想要将水平导航居中
我有一个带有弯曲选项卡的水平导航。我想将水平导航相对于屏幕分辨率居中。目前,我的水平导航距左侧边距 260 像素。因此,不要采用这种方式,只想使其以屏幕为中心,而不管屏幕分辨率如何。
base_menu.html
<ul id="toc">
<li><a href="{% url mmc.views.return_clients %}"><span>Home</span></a></li>
<li><a href="{% url mmc.views.quote_step1 %}"><span>Create quote/order</span></a></li>
<li><a href="{% url mmc.views.search_item %}"><span> Item Search</span></a></li>
<li><a><span>Service orders</span></a><br/>
<ul class="subnav">
<li><a href="{% url mmc.views.order_list %}"><span>Storage orders</span></a></li>
<li><a href="{% url mmc.views.order_list_service 1 %}"><span>Delivery orders</span></a></li>
<li><a href="{% url mmc.views.order_list_service 2 %}"><span>Collection orders</span></a></li>
</ul>
</li>
<li><a><span>Collection/Delivery</span></a><br/>
<ul class="subnav">
<li><a href="{% url mmc.views.service_list 1 %}"><span>Delivery list</span></a></li>
<li><a href="{% url mmc.views.service_list 2 %}"><span>Collection list</span></a></li>
</ul>
</li>
<li><a><span>Admin Tools</span></a><br/>
<ul class="subnav">
<li><a href="{% url mmc.views.invoice_list %}"><span>Export for invoicing</span></a></li>
<li><a href="{% url mmc.views.dbbackup %}"><span>Backup data</span></a></li>
</ul>
</li>
<li><a href="{% url mmc.views.help_login %}" target="_blank" onclick="return showAddAnotherPopup(this);"><span>Help</span></a></li>
</ul>
base.css
ul#toc {
height: 2em;
list-style: none;
margin-left: 260px;
padding: 0;
position: relative;
width: 100%;
}
ul#toc li{
background:#ffffff url(../images/tab.png);
float: left;
margin: 0 1px 0 0;
}
ul#toc li#drop{
background-color:#bce6c3;
float: left;
margin: 0 1px 0 0;
}
ul#toc span {
background: url(../images/tab.png) 100% 0;
display: block;
line-height: 2em;
padding-right: 10px;
}
ul#toc a {
color: #000000;
height: 2em;
float: left;
text-decoration: none;
padding-left: 10px;
}
ul#toc a:hover {
background: url(../images/tab2.png);
text-decoration: underline;
}
ul#toc a:hover span{
background: url(../images/tab2.png) 100% 0;
}
I have a horizontal navigation with curved tabs. I want to center my horizontal navigation relative to whatever the screen resolution is. Currently, my horizontal nav is 260px away from the left hand margin. So instead of this way, just want to make it centered to the screen regardless of screen resolution.
base_menu.html
<ul id="toc">
<li><a href="{% url mmc.views.return_clients %}"><span>Home</span></a></li>
<li><a href="{% url mmc.views.quote_step1 %}"><span>Create quote/order</span></a></li>
<li><a href="{% url mmc.views.search_item %}"><span> Item Search</span></a></li>
<li><a><span>Service orders</span></a><br/>
<ul class="subnav">
<li><a href="{% url mmc.views.order_list %}"><span>Storage orders</span></a></li>
<li><a href="{% url mmc.views.order_list_service 1 %}"><span>Delivery orders</span></a></li>
<li><a href="{% url mmc.views.order_list_service 2 %}"><span>Collection orders</span></a></li>
</ul>
</li>
<li><a><span>Collection/Delivery</span></a><br/>
<ul class="subnav">
<li><a href="{% url mmc.views.service_list 1 %}"><span>Delivery list</span></a></li>
<li><a href="{% url mmc.views.service_list 2 %}"><span>Collection list</span></a></li>
</ul>
</li>
<li><a><span>Admin Tools</span></a><br/>
<ul class="subnav">
<li><a href="{% url mmc.views.invoice_list %}"><span>Export for invoicing</span></a></li>
<li><a href="{% url mmc.views.dbbackup %}"><span>Backup data</span></a></li>
</ul>
</li>
<li><a href="{% url mmc.views.help_login %}" target="_blank" onclick="return showAddAnotherPopup(this);"><span>Help</span></a></li>
</ul>
base.css
ul#toc {
height: 2em;
list-style: none;
margin-left: 260px;
padding: 0;
position: relative;
width: 100%;
}
ul#toc li{
background:#ffffff url(../images/tab.png);
float: left;
margin: 0 1px 0 0;
}
ul#toc li#drop{
background-color:#bce6c3;
float: left;
margin: 0 1px 0 0;
}
ul#toc span {
background: url(../images/tab.png) 100% 0;
display: block;
line-height: 2em;
padding-right: 10px;
}
ul#toc a {
color: #000000;
height: 2em;
float: left;
text-decoration: none;
padding-left: 10px;
}
ul#toc a:hover {
background: url(../images/tab2.png);
text-decoration: underline;
}
ul#toc a:hover span{
background: url(../images/tab2.png) 100% 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改 css 中 ul 的边距规则,如下所示:
这使浏览器自动等于 ul 元素两侧的边距。
此外,您还需要为 ul#toc 提供固定宽度,因为宽度为 100% 时,它不能将任何内容居中,因为它适合屏幕的整个宽度。
Change the margin rule for your ul in your css like so:
This makes the browser automatically equal the margin either side of your ul element.
Also you need to give your ul#toc a fixed width as with a width of 100% it cannot center anything as it fits the whole width of the screen.