想要将水平导航居中

发布于 2024-12-10 11:21:24 字数 3012 浏览 0 评论 0原文

我有一个带有弯曲选项卡的水平导航。我想将水平导航相对于屏幕分辨率居中。目前,我的水平导航距左侧边距 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮光沉寂 2024-12-17 11:21:24

更改 css 中 ul 的边距规则,如下所示:

ul#toc{
     margin: 0 auto;}

这使浏览器自动等于 ul 元素两侧的边距。

此外,您还需要为 ul#toc 提供固定宽度,因为宽度为 100% 时,它不能将任何内容居中,因为它适合屏幕的整个宽度。

Change the margin rule for your ul in your css like so:

ul#toc{
     margin: 0 auto;}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文