简体   繁体   English

居中 <li> 沿左侧浮动元素和右侧浮动元素的元素

[英]Centering a <li> element along side float left and float right elements

I'm currently making a header for my webpage and well, the problem is that I can't seem to get my (what will be title image) to center inside the the image below shows my problem, Where the text: "Inlustra" is written, I would like that in the center of the Header. 我目前正在为网页制作标题,问题是,我似乎无法使我的标题图像居中,下面的图像显示了我的问题,其中文本:“ Inlustra”是这样写的,我希望在标题的中心。

Do you think I would be better off just using divs? 您认为仅使用div会更好吗? if so how is this done? 如果是这样,如何完成? I had trouble even getting floating left and right divs earlier and then switched to an unordered list. 我什至无法更早地左右浮动div,然后又切换到无序列表。

Here is my css: 这是我的CSS:

    #header {
    position:relative;
    -webkit-box-shadow: 0px 7px 30px rgba(50, 50, 50, 1);
    -moz-box-shadow:    0px 7px 30px rgba(50, 50, 50, 1);
    box-shadow:         0px 7px 30px rgba(50, 50, 50, 1);
    z-index:10;
    width:100%;
    height:40px;
    background-color: #FFFFFF;
    border-bottom:3px solid #1C6FFF;
}

.nav li {
    margin-left:-10px;
    display: inline-block;
    list-style: none;
    text-align: center;
    min-width:100px; width: auto !important; width: 100px;
}

.centerchild {
    width:150px;
    margin-left: auto;
    margin-right: auto;
    clear:both;
}

.firstchild {
    width:50px;
    float:left;
    text-align:left;
    margin-right:1.3em;
}

.lastchild {
    width:50px;
    float:right;
    margin-left:1.3em;
    text-align: right;
}

Here is my HTML: 这是我的HTML:

 <div id="header"> 
                <ul class="nav">
                    <li class="firstchild"> <i class="icon-home icon-2x"> </i> </li>
                    <li class="firstchild"> <i class="icon-inbox icon-2x"> </i> </li>
                    <li class="lastchild"> <i class="icon-twitter icon-2x"> </i> </li>
                    <li class="lastchild"> <i class="icon-facebook icon-2x"> </i> </li>
                    <li class="centerchild"> TITLE OF PAGE </li>
                </ul>
            </div>

And here is the result 这是结果 http://imgur.com/IarX4bX

I don't like this answer myself, but going all 1995 and using tables will at least get the job done. 我自己不喜欢这个答案,但是在1995年使用表并至少可以完成工作。 Since in your example the width of the elements floated left and right won't change, you could do something like this: 由于在您的示例中,左右浮动的元素的宽度不会改变,因此您可以执行以下操作:

(Using inline styles just for brevity) (为了简洁起见,使用内联样式)

<table style="width: 100%">
  <tr>
    <td style="width: 80px">Left</td>
    <td style="text-align: center">Center</td>
    <td style="width: 80px">Right</td>
  </tr>
</table>

I really want to believe that there's a more elegant way of doing this, and I'm using tables to bait somebody else into posting it :-) 我真的很想相信这样做还有一种更优雅的方式,而且我正在使用表格诱使其他人将其发布:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM