【问题标题】:Centering subnav along with top main nav与顶部主导航一起居中子导航
【发布时间】:2014-04-08 04:01:25
【问题描述】:

我在这里获得了一些帮助,让我的主导航中的多行文本垂直居中,但我无法让子导航中的文本做同样的事情。我弄得有点乱。

http://codepen.io/Compton/pen/icBDw/

#nav-wrap {
    width:100%;
    height:100px;
    font-weight:500;padding: 0;
    left:0;
    font-family: 'Raleway', Arial, sans-serif;
}

#nav-wrap ul {
    list-style-type: none;
    margin: 0;
    padding:0;
    text-transform: uppercase;
}   

#nav-wrap ul li {
    width:14.275%; /*  ~(100/7)  */
    display:block;
    float:left;
    text-align:center;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

#nav-wrap ul li a {
    width:100%;
    display: block;
    height: 100%;
    position: relative;
    color:#FFFFFF !important;
    text-decoration:none;
}

#nav-wrap ul li + li {
  border-left: 1px #fff solid;
}

#nav-wrap ul li span {
    display: inline-block;
    vertical-align: middle;
    height: 100px;
    font-size:1.45em;
    text-align: center;
    padding: 0 5% 0 5%; /* was 0 20px */ 
    line-height: 100px;
}

#nav-wrap ul li.yellow-facebook {
    width:14.275%;
}   

#nav-wrap ul li.yellow-facebook a {
    background-size:130px 26px; /* > 25px */
}

#nav-wrap .doubleLine {
  display: table-cell;
  line-height: 1.2em;
    width:65.275%;
}   


li .subnav {
  display: none;
  position: absolute;  
  clear: both;
  margin-left: 0;
  /*font-size:0.9em;*/
}

.subnav ul {
  margin-left: 0;
  float:left;
  padding:0;
  width:100%;
}

.subnav ul li { 
    margin: 0 0 0 0;
    height:42px;
}

.subnav ul li a {
    padding: 5px 0 5px 0;/*
    background-image: url(../images/submenu-background-divider.png);
    background-repeat:no-repeat;
    background-position:left;*/
}

.subnav ul li span {
    display: inline-block !important;
    vertical-align: middle !important;
    height: 40px !important;
    text-align: center !important;
    padding: 0 0 0 0 !important; /* was 0 20px */ 
    line-height: 1.1em !important;
    font-size:0.9em !important;
}

.subnavul li span .doubleLine {
  display: table-cell !important;
    width:65.275% !important;
}   

.subnav {
    width:100%;
    padding: 0;
    margin: 0.05% 0 0 0;
}

#nav-wrap ul li.orange a {
    background-color:#f37028;
}
#nav-wrap ul li.orange a:hover {
    color: #231f20 !important;
}
#nav-wrap ul li.red a {
    background-color:#ed1b24;
}
#nav-wrap ul li.red a:hover {
    color: #231f20 !important;
}
#nav-wrap ul li.pink a {
    background-color:#e54198;
}
#nav-wrap ul li.pink a:hover {
    color: #231f20 !important;
}
#nav-wrap ul li.purple a {
    background-color:#6b439c;
}
#nav-wrap ul li.purple a:hover {
    color: #231f20 !important;
}
#nav-wrap ul li.blue a {
    background-color:#0193cf;
}
#nav-wrap ul li.blue a:hover {
    color: #231f20 !important;
}
#nav-wrap ul li.green a {
    background-color:#80c02c;
}
#nav-wrap ul li.green a:hover {
    color: #231f20 !important;
}
#nav-wrap ul li.yellow-facebook a {
    background-color:#fff300;
    background-image:url(../images/social-media/facebook-text.png);
    background-repeat:no-repeat;
    background-position:center;
}
#nav-wrap ul li.yellow-facebook a:hover {
    color: #231f20;
    background-image:url(../images/social-media/facebook-text_over.png);
}

.subnav ul li a:link, a:active, a:visited {
  text-decoration:none;
}
.subnav ul li a:hover { 
  color:#000;
  text-decoration:none;
}

li:hover > .subnav {display:inline-block; left:0;}

【问题讨论】:

    标签: html css centering


    【解决方案1】:

    为以下内容添加display:table-cell;

    .subnav ul li span {
     display: table-cell !important;
    vertical-align: middle !important;
    height: 40px !important;
    text-align: center !important;
    padding: 0 0 0 0 !important; /* was 0 20px */ 
    line-height: 1.1em !important;
    font-size:0.9em !important;
    

    }

    解决问题

    【讨论】:

    • 谢谢,这可行,但它会将所有单行文本向右对齐。你能解决这个问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 2013-05-27
    • 1970-01-01
    • 2019-06-21
    • 1970-01-01
    相关资源
    最近更新 更多