css - 添加边框后如何在 Twenty Twelve 中重新居中导航栏?

标签 css wordpress navbar

我正在使用一个二十十二个 wordpress 子主题,当我向导航栏添加边框时,边框的左边缘与标题图像对齐,将右侧推到上方。我如何将其居中,在两侧扩展边框 2px?

这可以在 www.valuetactics.com 上实时看到

我尝试将标题图片增加到 1004 像素,但没有效果。

这是我的子主题.css

    @import url("../twentytwelve.1.6/twentytwelve/style.css");

body.custom-font-enabled {
    font-family: Helvetica, Arial, sans-serif;
}


/* Increase theme width to 1000px */
@media screen and (min-width: 960px) {
    .site {
        max-width: 1000px;
        max-width: 71.4285rem;
    }
}
.ie .site { max-width: 1000px; }

footer[role="contentinfo"] {
    max-width: 1000px;
    max-width: 71.4285rem;
}

/* Left & Right Sidebars */
@media screen and (min-width: 600px) {
    .custom-layout .site-content {
        width: 50%;
        margin-left: 25%;
    }
    .custom-layout .widget-area {
        position: relative;
        width: 20%;
    }
    .custom-layout #extra-sidebar {
        float: left;
        margin-left: -75%;
        width: 20%;
    }

}

/* IE8 and IE7 - Left and Right Sidebars */
.ie  .custom-layout .site-content {
    width: 50%;
    margin-left: 25%;
}
.ie .custom-layout .widget-area {
    float: right;
    width: 20%;
    position: relative;
}
.ie .custom-layout #extra-sidebar {
    float: left;
    margin-left: -75%;
    width: 20%;
}

/*Ross customizations: */

body .site {
    box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
    margin-bottom: 3.42857rem;
    margin-top: 3.42857rem;
    padding: 0 2.85714rem;
}

.main-navigation {
    margin-top: -65px;
    text-align: center;
}

    .main-navigation ul.nav-menu,
    .main-navigation div.nav-menu > ul {
        background: rgba(0,0,0,0.7);
        border: 2px solid #C4F4FF;
        border-radius: 4px;
        display: inline-block !important;
        text-align: left;
        width: 100%;
    }

        .main-navigation li a {
        border-bottom: 0;
        margin-left: 20px;
        color: #C4F4FF;
        font-weight:bold; 
        line-height: 3.692307692;
        text-transform: uppercase;
        white-space: nowrap;
    }
    .main-navigation li a:hover,
    .main-navigation li a:focus {
        color: #C4F4FF;
    }

    @import url('../twentytwelve/style.css');

body .headerContent {
margin-top:0px;
margin-bottom:0px;
overflow:visible;
}
body .site {
box-shadow:none;
}

#page {
margin-top:0px;
}

.headerContent, .headerWrapper {
background:#E6E6E6;
}

    .main-navigation ul {
        margin: 0;
    }


    .site-header {
    padding: 0;
    margin-bottom: 5px;
}


/* Sidebar */
.widget-area .widget {
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    hyphens: auto;
    padding: 10px;
    border: 1px solid;
    border-color: blue;
    border-radius: 3px;
    margin-top: 12px;
    margin-top: 1.7rem;
    margin-bottom: 24px;
    margin-bottom: 1.7rem;
    word-wrap: break-word;
    background: lightblue;
    }

.header-image {
    margin-top: -3px;
}

这是 border: 20px 的样子,可以更清楚地说明问题: http://s22.postimg.org/st72q5fy9/menubarfail.jpg

.main-navigation ul.nav-menu,
    .main-navigation div.nav-menu > ul {
        background: rgba(0,0,0,0.7);
        border: 20px solid #C4F4FF;
        border-radius: 4px;
        display: inline-block !important;
        text-align: left;
        width: 100%;
    }

最佳答案

一旦我想通了,这是一个非常简单的修复。将边框宽度更改为 -2 而不是 2。这将边框置于容器内部,使其适合并居中放置在父级中。

关于css - 添加边框后如何在 Twenty Twelve 中重新居中导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27757927/

相关文章:

html - 按钮在小屏幕上变得笨拙

html - 我怎样才能让我的导航栏与顶部居中的 Logo /图像完美居中

html - z-index 和伪类之后

滚动更改导航栏不透明度的 Javascript 使我的导航内容消失

html - 用绝对头寸管理 margin

jquery - 如果没有 div 高度,Fuel UX 的无限滚动将无法工作

html - 使用 SVG 和 HTML/CSS 创建列表

php - 空白的 WordPress 登录页面

linux - .htaccess 是否会干扰嵌套的 .htaccess/.htpasswd?

php - 在购物车 View 中获取送货国家 - WooCommerce