我有一个用作表的标题,并且我试图将最后一个li浮动到右侧。
我试过将第5 li的padding-right%设置为显示在末尾,但显然这并不理想,因为在其他屏幕上会引起问题。我也尝试过将其向右浮动,但它弄乱了垂直对齐方式。有什么建议?
#header ul {
width: 100%;
float: left;
margin: 0;
margin-top: 2px;
padding: 0;
list-style-type: none;
list-style-image: none;
}
#header ul li {
height: 100%;
display: table-cell;
vertical-align: middle;
}
/* Logo */
#header li:nth-child(1) {
font-size: 40px;
font-family: serif;
font-weight: bold;
padding-right: 4%;
}
/* Back & Forward buttons */
#header li:nth-child(2) {
padding-right: 8.2%;
}
/* Search box */
#header li:nth-child(3) {
padding-right: 4.5%;
}
/* Break line */
#header li:nth-child(4) {
padding-right: 2%;
}
/* Icons */
#header li:nth-child(5) {}
/* Icons */
#header li:nth-child(6) {
border: 1px dotted red;
}
<div id="header">
<ul>
<!-- Logo -->
<li width="10%"><div>B</div></li>
<!-- Back / forward buttons -->
<li>
<i class="material-icons md-38 back-forward icn-hvr">chevron_left</i>
<i class="material-icons md-38 back-forward icn-hvr">chevron_right</i>
</li>
<!-- Search box -->
<li>
<input type="search" id="search" size="30" placeholder="What are you looking for?" />
</li>
<!-- Break line -->
<li>
<span class="hdr-break"></span>
</li>
<!-- Icons -->
<li>
<i class="material-icons md-26 icn-lft icn-stamp">add_location</i>
<i class="material-icons md-26 icn-lft icn-map">map</i>
<i class="material-icons md-26 icn-lft icn-hvr">business_center</i>
<i class="material-icons md-26 icn-lft icn-hvr">notifications</i>
</li>
<!-- This should float right -->
<li>
<p>x</p>
</li>
</ul>
</div>
使用现有代码,只需删除float:left;
并添加display: table
。
#header ul {
width: 100%;
display: table;
....
这是显示它的代码段。
#header ul {
width: 100%;
display: table;
margin-top: 2px;
padding: 0;
list-style-type: none;
list-style-image: none;
}
#header ul li {
height: 100%;
display: table-cell;
vertical-align: middle;
}
/* Logo */
#header li:nth-child(1) {
font-size: 40px;
font-family: serif;
font-weight: bold;
padding-right: 4%;
}
/* Back & Forward buttons */
#header li:nth-child(2) {
padding-right: 8.2%;
}
/* Search box */
#header li:nth-child(3) {
padding-right: 4.5%;
}
/* Break line */
#header li:nth-child(4) {
padding-right: 2%;
}
/* Icons */
#header li:nth-child(5) {}
/* Icons */
#header li:nth-child(6) {
border: 1px dotted red;
}
<div id="header">
<ul>
<!-- Logo -->
<li width="10%"><div>B</div></li>
<!-- Back / forward buttons -->
<li>
<i class="material-icons md-38 back-forward icn-hvr">chevron_left</i>
<i class="material-icons md-38 back-forward icn-hvr">chevron_right</i>
</li>
<!-- Search box -->
<li>
<input type="search" id="search" size="30" placeholder="What are you looking for?" />
</li>
<!-- Break line -->
<li>
<span class="hdr-break"></span>
</li>
<!-- Icons -->
<li>
<i class="material-icons md-26 icn-lft icn-stamp">add_location</i>
<i class="material-icons md-26 icn-lft icn-map">map</i>
<i class="material-icons md-26 icn-lft icn-hvr">business_center</i>
<i class="material-icons md-26 icn-lft icn-hvr">notifications</i>
</li>
<!-- This should float right -->
<li>
<p>x</p>
</li>
</ul>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句