2016-11-09 42 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>