2016-04-05 29 views
0

我想玩「流體層」和調整窗口大小(手動調整其寬度)時,我想使:顯示:無其中一個DIV,但它失敗這樣做(根本不起作用)。液體層 - 顯示:沒有不工作

你能告訴我爲什麼顯示:沒有在線18不工作?另外,當我想將3個塊集中在一個容器內時,我應該使用DIVS嗎?或者你對我有更好的主意?

如果您知道任何有關實施Liquid Layers的更好/不同想法,我們將很樂意。感謝您的幫助。

這裏是我的代碼:

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<style> 
body 
{ 
    background-color: #FFFFFF; 
} 

/* Extra small devices (phones, up to 480px) */ 
@media (max-width: 480px) 
{ 
    body 
    { 
    background-color: #FFFFFF; 
    } 
    .col3 { display: none; } 
} 

/* Extra small devices (usually phones from 480px to 768px) */ 
@media (min-width: 481px) and (max-width: 767px) 
{ 
    body 
    { 
    background-color: yellow; 
    } 
} 

/* Small devices (tablets, 768px and up) */ 
@media (min-width: 768px) and (max-width: 991px) 
{ 
    body 
    { 
    background-color: #444; 
    } 
} 

/* Small devices (tablets/desktop, 768px and up) */ 
@media (min-width: 992px) and (max-width: 1199px) 
{ 
    body 
    { 
    background-color: green; 
    } 
} 

/* large desktops and up ----------- */ 
@media (min-width: 1200px) 
{ 
    body 
    { 
    background-color: lightblue; 
    } 
} 
</style> 
</head> 
<body> 

<div style="width:100%; margin-left: 0 auto; background-color:#422220; text-align:center; overflow: hidden; padding:10px 0px;"> 
<div id="col1" style="width:29%; padding: 0; margin-left: 3%; margin-right:3%; background-color:#FFF333; display: inline- block">Text</div> 
<div id="col2" style="width:29%; padding: 0; margin-right:3%; background-color:#FFF333; display: inline-block">Text</div> 
<div id="col3" style="width:29%; padding: 0; margin-right:3%; background-color:#FFF333; display: inline-block">Text</div> 
</div> 

</body> 
</html> 
+2

第18行,您使用的是 'COL3' 作爲類,而不是ID,嘗試'#{col3的顯示:無; } - https://jsfiddle.net/4uknmLe2/1/ – ASR

回答

0

您用來代替id作爲選擇的一類。

此外,我將所有列的常用樣式移動到樣式表中,而不像您所做的那樣將內聯樣式移至樣式表。

body { 
 
    background-color: #FFFFFF; 
 
} 
 
#col1, 
 
#col2, 
 
#col3 { 
 
    width: 29%; 
 
    padding: 0; 
 
    margin-left: 3%; 
 
    margin-right: 3%; 
 
    background-color: #FFF333; 
 
    display: inline-block; 
 
} 
 
/* Extra small devices (phones, up to 480px) */ 
 

 
@media (max-width: 480px) { 
 
    body { 
 
    background-color: #FFFFFF; 
 
    } 
 
    #col3 { 
 
    display: none; 
 
    } 
 
} 
 
/* Extra small devices (usually phones from 480px to 768px) */ 
 

 
@media (min-width: 481px) and (max-width: 767px) { 
 
    body { 
 
    background-color: yellow; 
 
    } 
 
} 
 
/* Small devices (tablets, 768px and up) */ 
 

 
@media (min-width: 768px) and (max-width: 991px) { 
 
    body { 
 
    background-color: #444; 
 
    } 
 
} 
 
/* Small devices (tablets/desktop, 768px and up) */ 
 

 
@media (min-width: 992px) and (max-width: 1199px) { 
 
    body { 
 
    background-color: green; 
 
    } 
 
} 
 
/* large desktops and up ----------- */ 
 

 
@media (min-width: 1200px) { 
 
    body { 
 
    background-color: lightblue; 
 
    } 
 
}
<div style="width:100%; margin-left: 0 auto; background-color:#422220; text-align:center; overflow: hidden; padding:10px 0px;"> 
 
    <div id="col1">Text</div> 
 
    <div id="col2">Text</div> 
 
    <div id="col3">Text</div> 
 
</div>