因此,一旦网站点击某个媒体查询,我就会尝试保持无序列表居中。如果页面四处移动,我无法让它留在容器的中心。这是相应的代码。
HTML
<div id="centerNav">
<ul id="home-nav">
<li><a href="/practice-areas/dui-defense/">DUI/DWI Defense</a></li>
<li><a href="/practice-areas/criminal-defense/">Criminal Defense</a></li>
<li><a href="/practice-areas/estate-planning/">Estate Planning</a></li>
<li style="border: none;"><a href="/practice-areas/agricultural-law/"> Agricultural Law</a></li>
</ul>
</div>
CSS
@media only screen and (max-width: 839px)
{
#centerNav {
margin: 0 auto;
max-width: 840px;
padding: 0;
height:60px;
}
#home-nav li {
float: left;
position: relative;
display: block;
text-align: center;
background: none;
font-size: 20px;
width: 158px;
border-right: 1px solid #fff;
margin-top: 8px;
line-height: 1em;
padding-left: 10px;
}
#home-nav {
list-style:none;
position:relative;
height: 60px;
vertical-align: middle;
z-index: 5;
border-top: 4px double #fff;
border-bottom: 4px double #fff;
border: none;
margin: 0;
background: #7a0426;
}
}