2016-11-09 35 views
0

问题:我下面的代码是在台式机或景观设备工作正常。但是当我切换到移动/响应式视图div边框没有显示。我不知道我在下面的代码中做错了什么。请有人把我从这个小问题中解救出来。在响应视图边界上没有显示的div

开头代码:

<meta name="viewport" content="width=device-width, initial-scale=1"> 

HTML代码:

<div class="ah-header"> 
    <div class="ah-logo"></div> 
    <div class="ah-navbar-searchbar"></div> 
    <div class="ah-nav"></div> 
</div> 

CSS代码:

.ah-header { 
padding: 9px; 
background-color: rgb(25, 118, 210); 
display: table; 
width: 100%; 
min-height: 50px; 
max-height: 150px; 
.ah-logo { 
    display: table-cell; 
    width: 250px; 
    border: 1px solid yellow; 
} 
.ah-navbar-searchbar { 
    display: table-cell; 
    position: relative; 
    /* Firefox */ 
    width: -moz-calc(100% - 500px); 
    /* WebKit */ 
    width: -webkit-calc(100% - 500px); 
    /* Opera */ 
    width: -o-calc(100% - 500px); 
    /* Standard */ 
    width: calc(100% - 500px); 
    border: 1px solid yellow; 
} 
.ah-nav { 
    display: table-cell; 
    position: relative; 
    /* Firefox */ 
    width: 250px; 
    border: 1px solid yellow; 
} 
@media only screen and (max-width : 320px) { 
     .ah-header { 
      padding: 0px !important; 
      display: block !important; 
      max-height: 150px !important; 
     } 
     .ah-logo, .ah-navbar-searchbar, .ah-nav { 
      display: table-row !important; 
      border: 1px solid yellow; 
      height: 50px !important; 
     } 
} 
+1

看起来你错过了''''之前的'.ah-logo {' – Banzay

回答

1

设置你@media查询的.ah-logo, .ah-navbar-searchbar, .ah-nav规则的display: block;代替display: table-row

侧面说明,我删除了所有的!important,因为他们在这里没有必要和你错过了一个支架}.ah-header规则

.ah-header { 
 
    padding: 9px; 
 
    background-color: rgb(25, 118, 210); 
 
    display: table; 
 
    width: 100%; 
 
    min-height: 50px; 
 
    max-height: 150px; 
 
} 
 
    .ah-logo { 
 
    display: table-cell; 
 
    width: 250px; 
 
    border: 1px solid yellow; 
 
    } 
 

 
.ah-navbar-searchbar { 
 
    display: table-cell; 
 
    position: relative; 
 
    /* Firefox */ 
 
    width: -moz-calc(100% - 500px); 
 
    /* WebKit */ 
 
    width: -webkit-calc(100% - 500px); 
 
    /* Opera */ 
 
    width: -o-calc(100% - 500px); 
 
    /* Standard */ 
 
    width: calc(100% - 500px); 
 
    border: 1px solid yellow; 
 
    } 
 
    .ah-nav { 
 
    display: table-cell; 
 
    position: relative; 
 
    /* Firefox */ 
 
    width: 250px; 
 
    border: 1px solid yellow; 
 
    } 
 
    @media only screen and (max-width: 320px) { 
 
    .ah-header { 
 
     padding: 0px; 
 
     display: block; 
 
     max-height: 150px; 
 
    } 
 
    .ah-logo, 
 
    .ah-navbar-searchbar, 
 
    .ah-nav { 
 
     display: block; 
 
     border: 1px solid yellow; 
 
     height: 50px; 
 
    } 
 
    }
<div class="ah-header"> 
 
    <div class="ah-logo"></div> 
 
    <div class="ah-navbar-searchbar"></div> 
 
    <div class="ah-nav"></div> 
 
</div>