2016-02-26 183 views
0

當我調整瀏覽響應式代碼的工作時,但當我在我的手機或切換設備模式響應不工作時打開。我使用媒體查詢,但它不適用於移動設備。我在移動設備中發現了滾動。但在調整瀏覽器工作正常。響應式代碼無法在桌面上工作

\t \t body { 
 
    background-color: #91ced4; 
 
} 
 
body * { 
 
    box-sizing: border-box; 
 
} 
 

 
.header { 
 
    background-color: #327a81; 
 
    color: white; 
 
    font-size: 1.5em; 
 
    padding: 1rem; 
 
    text-align: center; 
 
    text-transform: uppercase; 
 
} 
 

 
img { 
 
    border-radius: 50%; 
 
    height: 60px; 
 
    width: 60px; 
 
} 
 

 
.table-users { 
 
    border: 1px solid #327a81; 
 
    border-radius: 10px; 
 
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.1); 
 
    max-width: calc(100% - 2em); 
 
    margin: 1em auto; 
 
    overflow: hidden; 
 
    width: 800px; 
 
} 
 

 
table { 
 
    width: 100%; 
 
} 
 
table td, table th { 
 
    color: #2b686e; 
 
    padding: 10px; 
 
} 
 
table td { 
 
    text-align: center; 
 
    vertical-align: middle; 
 
} 
 
table td:last-child { 
 
    font-size: 0.95em; 
 
    line-height: 1.4; 
 
    text-align: left; 
 
} 
 
table th { 
 
    background-color: #daeff1; 
 
    font-weight: 300; 
 
} 
 
table tr:nth-child(2n) { 
 
    background-color: white; 
 
} 
 
table tr:nth-child(2n+1) { 
 
    background-color: #edf7f8; 
 
} 
 

 
@media screen and (max-width: 700px) { 
 
    table, tr, td { 
 
    display: block; 
 
    } 
 

 
    td:first-child { 
 
    position: absolute; 
 
    top: 50%; 
 
    -webkit-transform: translateY(-50%); 
 
      transform: translateY(-50%); 
 
    width: 100px; 
 
    } 
 
    td:not(:first-child) { 
 
    clear: both; 
 
    margin-left: 100px; 
 
    padding: 4px 20px 4px 90px; 
 
    position: relative; 
 
    text-align: left; 
 
    } 
 
    td:not(:first-child):before { 
 
    color: #91ced4; 
 
    content: ''; 
 
    display: block; 
 
    left: 0; 
 
    position: absolute; 
 
    } 
 
    td:nth-child(2):before { 
 
    content: 'Name:'; 
 
    } 
 
    td:nth-child(3):before { 
 
    content: 'Email:'; 
 
    } 
 
    td:nth-child(4):before { 
 
    content: 'Phone:'; 
 
    } 
 
    td:nth-child(5):before { 
 
    content: 'Comments:'; 
 
    } 
 

 
    tr { 
 
    padding: 10px 0; 
 
    position: relative; 
 
    } 
 
    tr:first-child { 
 
    display: none; 
 
    } 
 
} 
 
@media screen and (max-width: 500px) { 
 
    .header { 
 
    background-color: transparent; 
 
    color: white; 
 
    font-size: 2em; 
 
    font-weight: 700; 
 
    padding: 0; 
 
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.1); 
 
    } 
 

 
    img { 
 
    border: 3px solid; 
 
    border-color: #daeff1; 
 
    height: 100px; 
 
    margin: 0.5rem 0; 
 
    width: 100px; 
 
    } 
 

 
    td:first-child { 
 
    background-color: #c8e7ea; 
 
    border-bottom: 1px solid #91ced4; 
 
    border-radius: 10px 10px 0 0; 
 
    position: relative; 
 
    top: 0; 
 
    -webkit-transform: translateY(0); 
 
      transform: translateY(0); 
 
    width: 100%; 
 
    } 
 
    td:not(:first-child) { 
 
    margin: 0; 
 
    padding: 5px 1em; 
 
    width: 100%; 
 
    } 
 
    td:not(:first-child):before { 
 
    font-size: .8em; 
 
    padding-top: 0.3em; 
 
    position: relative; 
 
    } 
 
    td:last-child { 
 
    padding-bottom: 1rem !important; 
 
    } 
 

 
    tr { 
 
    background-color: white !important; 
 
    border: 1px solid #6cbec6; 
 
    border-radius: 10px; 
 
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.1); 
 
    margin: 0.5rem 0; 
 
    padding: 0; 
 
    } 
 

 
    .table-users { 
 
    border: none; 
 
    box-shadow: none; 
 
    overflow: visible; 
 
    } 
 
} 
 

 
\t 
 
\t
<div class="table-users"> 
 
    <div class="header">Users</div> 
 
    
 
    <table> 
 
     <tr> 
 
     <th>Picture</th> 
 
     <th>Name</th> 
 
     <th>Email</th> 
 
     <th>Phone</th> 
 
     <th width="230">Comments</th> 
 
     </tr> 
 

 
     <tr> 
 
     <td><img src="http://lorempixel.com/100/100/people/1" alt="" /></td> 
 
     <td>Jane Doe</td> 
 
     <td>[email protected]</td> 
 
     <td>01 800 2000</td> 
 
     <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </td> 
 
     </tr> 
 

 
     <tr> 
 
     <td><img src="http://lorempixel.com/100/100/sports/2" alt="" /></td> 
 
     <td>John Doe</td> 
 
     <td>[email protected]</td> 
 
     <td>01 800 2000</td> 
 
     <td>Blanditiis, aliquid numquam iure voluptatibus ut maiores explicabo ducimus neque, nesciunt rerum perferendis, inventore.</td> 
 
     </tr> 
 

 
     <tr> 
 
     <td><img src="http://lorempixel.com/100/100/people/9" alt="" /></td> 
 
     <td>Jane Smith</td> 
 
     <td>[email protected]</td> 
 
     <td>01 800 2000</td> 
 
     <td> Culpa praesentium unde pariatur fugit eos recusandae voluptas.</td> 
 
     </tr> 
 
     
 
     <tr> 
 
     <td><img src="http://lorempixel.com/100/100/people/3" alt="" /></td> 
 
     <td>John Smith</td> 
 
     <td>[email protected]</td> 
 
     <td>01 800 2000</td> 
 
     <td>Aut voluptatum accusantium, eveniet, sapiente quaerat adipisci consequatur maxime temporibus quas, dolorem impedit.</td> 
 
     </tr> 
 
    </table> 
 
</div>

回答

3

視標籤添加到您的<head>

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

+0

than than now now now –

+0

您可以在這裏閱讀關於此元標記的更多信息(https://developer.mozilla.org/en/docs/Mozilla/Mobile/Viewport_meta_tag)。如果你能在我的答案標記爲正確的,如果它有幫助,當你有機會,那麼請。 – Aaron

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

寬度=設備寬度部分設置頁面遵循的寬度設備的屏幕寬度(這會改變d依靠設備)。

initial-scale = 1.0部分設置瀏覽器首次加載頁面時的初始縮放級別。

相關問題