2017-05-23 113 views
0

我的柔性箱有問題,文字不符合移動視圖中的導航欄。我希望它用與菜單大小相同的文本填充屏幕。CSS柔性箱問題

問題:

enter image description here

我想看起來像我article-container使文本在整個手機屏幕填寫。在桌面視圖,他們三個在一起,並在移動視圖,它們堆疊像類似菜單漢堡包在那裏說LANK 1 2 3 4

enter image description here

body { 
 
\t margin: 0; 
 
} 
 
ul { 
 
\t list-style-type: none; 
 
\t margin: 0; 
 
\t padding: 0; 
 
\t width: 25%; 
 
\t background-color: #EBEBEB; 
 
\t position: fixed; 
 
\t height: 100%; 
 
\t overflow: auto; 
 
} 
 
li a { 
 
\t display: block; 
 
\t color: #000; 
 
\t padding: 8px 16px; 
 
\t text-decoration: none; 
 
} 
 
li a.active { 
 
\t background-color: #F16529; 
 
\t color: white; 
 
} 
 
li a:hover:not(.active) { 
 
\t background-color: #555; 
 
\t color: white; 
 
} 
 
.container { 
 
\t margin-left: 25%; 
 
\t padding: 1px 16px; 
 
\t height: auto; 
 
} 
 
@media screen and (max-width: 480px) { 
 
\t ul { 
 
\t \t position: relative; 
 
\t \t width: 100%; 
 
\t } 
 
\t .container { 
 
\t \t margin: 0 auto; 
 
\t \t padding: 1px 16px; 
 
\t } 
 
\t div.item { 
 
\t \t width: initial; 
 
\t \t max-width: 256px; 
 
\t } 
 
} 
 
div.item { 
 
\t vertical-align: top; 
 
\t display: inline-block; 
 
\t text-align: center; 
 
\t max-width: 256px; 
 
} 
 
.blog { 
 
\t max-width: 100%; 
 
\t height: auto; 
 
\t margin-left: auto; 
 
\t margin-right: auto; 
 
\t display: block; 
 
} 
 
.caption { 
 
\t display: block; 
 
} 
 
img { 
 
\t display: block; 
 
} 
 
img.wrap { 
 
\t max-width: 70%; 
 
\t margin: 30px 0px; 
 
} 
 
img.align-right { 
 
\t float: right; 
 
\t margin-left: 30px; 
 
} 
 
div.article-container { 
 
\t padding: 5px; 
 
} 
 
.clearfix:after { 
 
\t content: ""; 
 
\t display: table; 
 
\t clear: both; 
 
} 
 
footer { 
 
\t right: 0; 
 
\t bottom: 0; 
 
\t left: 0; 
 
\t padding: 1rem; 
 
\t background-color: #EBEBEB; 
 
\t text-align: center; 
 
} 
 
@media(max-width:767px) { 
 
\t img.align-right { 
 
\t \t float: none; 
 
\t \t margin: auto; 
 
\t } 
 
\t div.article-container { 
 
\t \t padding: 5px; 
 
\t \t text-align: center; 
 
\t \t max-width: 256px; 
 
\t } 
 
} 
 
.flex-grid { 
 
    display: flex; 
 
} 
 
.flex-grid .col { 
 
    flex: 1; 
 
} 
 
.flex-grid-thirds { 
 
    display: flex; 
 
    justify-content: space-between; 
 
} 
 
.flex-grid-thirds .col { 
 
    width: 32%; 
 
} 
 

 
@media (max-width: 400px) { 
 
    .flex-grid, 
 
    .flex-grid-thirds { 
 
    display: block; 
 
    .col { 
 
     width: 100%; 
 
     margin: 0 0 10px 0; 
 
    } 
 
    } 
 
} 
 

 

 

 

 
* { 
 
    box-sizing: border-box; 
 
} 
 
body { 
 
    padding: 20px; 
 
} 
 
.flex-grid { 
 
    margin: 0 0 20px 0; 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <meta charset="utf-8"> 
 
\t <title>Inlämningsuppgift 6</title> 
 
\t <meta content="width=device-width, initial-scale=1" name="viewport"> 
 
\t <link href="style.css" rel="stylesheet"> 
 
</head> 
 
<body> 
 
\t <!--nav bar--> 
 
\t <nav> 
 
\t \t <ul> 
 
\t \t \t <li style="list-style: none"><br></li> 
 
\t \t \t <li><img alt="htmll logo" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"></li> 
 
\t \t \t <li> 
 
\t \t \t \t <h2>Menu</h2> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a class="active" href="#lank">Länk 1</a> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a href="#lank2">Länk 2</a> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a href="#lank3">Länk 3</a> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a href="#lank4">Länk 4</a> 
 
\t \t \t </li> 
 
\t \t </ul> 
 
\t </nav><!--navbar end--> 
 
\t <!--container for blog posts 3 images--> 
 

 
\t </div> 
 
\t <div class="container"> 
 

 
\t \t <h1>Innehåll</h1> 
 
\t \t <div class="flex-grid-thirds"> 
 
\t \t \t <div class="col"> 
 
\t \t \t \t \t \t \t <img alt="htmll logo" class="blog" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png" alligment > 
 
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t </div> 
 
\t \t \t <div class="col"> 
 
\t \t \t \t \t \t \t <img alt="htmll logo" class="blog" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"> 
 
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t </div> 
 
\t \t \t <div class="col"> 
 
\t \t \t \t \t \t \t <img alt="htmll logo" class="blog" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"> 
 
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t </div> 
 
\t \t </div> 
 

 
\t </div><!--end--> 
 
\t <hr> 
 
\t <!--container for article --> 
 
\t <div class="container"> 
 
\t \t <div class="article-container clearfix"> 
 
\t \t \t <img alt="html logo" class="wrap align-right" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"> 
 
\t \t \t <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t </div> 
 
\t </div><!--end--> 
 
\t <footer class="container"> 
 
\t \t Skriven i HTML 5. 
 
\t </footer> 
 

 

 
</html>

回答

1

你使用.col更新媒體查詢中.col部分的寬度,但您使用.flex-grid-thirds .col定義了初始寬度。所以這只是媒體查詢中的特定問題。在媒體查詢選擇器中使用.flex-grid-thirds .col

body { 
 
    margin: 0; 
 
} 
 

 
ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    width: 25%; 
 
    background-color: #EBEBEB; 
 
    position: fixed; 
 
    height: 100%; 
 
    overflow: auto; 
 
} 
 

 
li a { 
 
    display: block; 
 
    color: #000; 
 
    padding: 8px 16px; 
 
    text-decoration: none; 
 
} 
 

 
li a.active { 
 
    background-color: #F16529; 
 
    color: white; 
 
} 
 

 
li a:hover:not(.active) { 
 
    background-color: #555; 
 
    color: white; 
 
} 
 

 
.container { 
 
    margin-left: 25%; 
 
    padding: 1px 16px; 
 
    height: auto; 
 
} 
 

 
@media screen and (max-width: 480px) { 
 
    ul { 
 
    position: relative; 
 
    width: 100%; 
 
    } 
 
    .container { 
 
    margin: 0 auto; 
 
    padding: 1px 16px; 
 
    } 
 
    div.item { 
 
    width: initial; 
 
    max-width: 256px; 
 
    } 
 
} 
 

 
div.item { 
 
    vertical-align: top; 
 
    display: inline-block; 
 
    text-align: center; 
 
    max-width: 256px; 
 
} 
 

 
.blog { 
 
    max-width: 100%; 
 
    height: auto; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    display: block; 
 
} 
 

 
.caption { 
 
    display: block; 
 
} 
 

 
img { 
 
    display: block; 
 
} 
 

 
img.wrap { 
 
    max-width: 70%; 
 
    margin: 30px 0px; 
 
} 
 

 
img.align-right { 
 
    float: right; 
 
    margin-left: 30px; 
 
} 
 

 
div.article-container { 
 
    padding: 5px; 
 
} 
 

 
.clearfix:after { 
 
    content: ""; 
 
    display: table; 
 
    clear: both; 
 
} 
 

 
footer { 
 
    right: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    padding: 1rem; 
 
    background-color: #EBEBEB; 
 
    text-align: center; 
 
} 
 

 
@media(max-width:767px) { 
 
    img.align-right { 
 
    float: none; 
 
    margin: auto; 
 
    } 
 
    div.article-container { 
 
    padding: 5px; 
 
    text-align: center; 
 
    max-width: 256px; 
 
    } 
 
} 
 

 
.flex-grid { 
 
    display: flex; 
 
} 
 

 
.flex-grid .col { 
 
    flex: 1; 
 
} 
 

 
.flex-grid-thirds { 
 
    display: flex; 
 
    justify-content: space-between; 
 
} 
 

 
.flex-grid-thirds .col { 
 
    width: 32%; 
 
} 
 

 
@media (max-width: 400px) { 
 
    .flex-grid, 
 
    .flex-grid-thirds { 
 
    display: block; 
 
    } 
 
    .flex-grid-thirds .col { 
 
    width: 100%; 
 
    margin: 0 0 10px 0; 
 
    } 
 
} 
 

 

 
} 
 
* { 
 
    box-sizing: border-box; 
 
} 
 
body { 
 
    padding: 20px; 
 
} 
 
.flex-grid { 
 
    margin: 0 0 20px 0; 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <meta charset="utf-8"> 
 
\t <title>Inlämningsuppgift 6</title> 
 
\t <meta content="width=device-width, initial-scale=1" name="viewport"> 
 
\t <link href="style.css" rel="stylesheet"> 
 
</head> 
 
<body> 
 
\t <!--nav bar--> 
 
\t <nav> 
 
\t \t <ul> 
 
\t \t \t <li style="list-style: none"><br></li> 
 
\t \t \t <li><img alt="htmll logo" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"></li> 
 
\t \t \t <li> 
 
\t \t \t \t <h2>Menu</h2> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a class="active" href="#lank">Länk 1</a> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a href="#lank2">Länk 2</a> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a href="#lank3">Länk 3</a> 
 
\t \t \t </li> 
 
\t \t \t <li> 
 
\t \t \t \t <a href="#lank4">Länk 4</a> 
 
\t \t \t </li> 
 
\t \t </ul> 
 
\t </nav><!--navbar end--> 
 
\t <!--container for blog posts 3 images--> 
 

 
\t </div> 
 
\t <div class="container"> 
 

 
\t \t <h1>Innehåll</h1> 
 
\t \t <div class="flex-grid-thirds"> 
 
\t \t \t <div class="col"> 
 
\t \t \t \t \t \t \t <img alt="htmll logo" class="blog" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png" alligment > 
 
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t </div> 
 
\t \t \t <div class="col"> 
 
\t \t \t \t \t \t \t <img alt="htmll logo" class="blog" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"> 
 
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t </div> 
 
\t \t \t <div class="col"> 
 
\t \t \t \t \t \t \t <img alt="htmll logo" class="blog" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"> 
 
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t </div> 
 
\t \t </div> 
 

 
\t </div><!--end--> 
 
\t <hr> 
 
\t <!--container for article --> 
 
\t <div class="container"> 
 
\t \t <div class="article-container clearfix"> 
 
\t \t \t <img alt="html logo" class="wrap align-right" src="https://www.w3.org/html/logo/downloads/HTML5_Logo_256.png"> 
 
\t \t \t <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t \t <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p> 
 
\t \t </div> 
 
\t </div><!--end--> 
 
\t <footer class="container"> 
 
\t \t Skriven i HTML 5. 
 
\t </footer> 
 

 

 
</html>

0

的問題是,類.COL仍然被設置爲寬32%。當瀏覽器小於480px時,正文文本仍然只有32%,應該是100%。

最簡單的解決是添加

@media screen and (max-width: 480px) { 

    .col { 
     width: 100% !important; 

    } 

} 

如果你想刪除!重要的是你可以移動類.flex電網三分之二.COL當瀏覽器比481px更大隻被調用。

@media screen and (min-width: 481px) { 

    { 
     width: 32%; 
    } 

}