Keeping middle item centered horizontally

77 views Asked by At

I'm trying to make my first custom header.

I want the middle item (eg. the logo) to stay centered regardless of how much content is on either side.

I tried using z-index but I believe that was wrong.

HTML:

.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
}

.flex-item {
  text-align: center;
}

.image {
  z-index: -1;
}
<div id="header_container">
  <div id="header">

    <ul class="flex-container">
      <li class="flex-item">Menu items 1 BHello | seven | eight | nineteen | Fitiyytwooooo
      </li>
      <li class="image">
        <img src="http://www.plankdesign.com/wp-content/uploads/2011/01/html4.jpg" style="width:204px;height:128px;">
      </li>
      <li class="flex-item">Menu items 2 Blah | Blah | Blah</li>
    </ul>
  </div>
</div>

Here's my jsfiddle demo.

2

There are 2 answers

6
G.L.P On BEST ANSWER

Try like this: Demo

.image img {
    z-index: 1000;
    width:18%;
    height:128px;
    position:absolute;
    left:50%;
    margin-left:-9%; /* half of the width */
}

HTML:

 <li class="image">
   <img src="http://www.plankdesign.com/wp-content/uploads/2011/01/html4.jpg" />
 </li>
0
Greenhorn On

Check this out, you may want to modify the code(col-md-x) as per your requirement.