我正在练习响应式网页设计,使用flex布局。
问题是,当屏幕小于768像素时,我想让.menu li的宽度为100%,所以我尝试给.menu ul和.menu li设置width:100%。但是它不起作用。我还尝试了flex:0 0 100%,但什么也没有发生。
如何使.menu li达到100%宽度?
* {
box-sizing: border-box;
}
nav ul,
.outline ul {
list-style-type: none;
margin: 0;
padding: 0;
}
/*common*/
/*layout*/
.container {
max-width: 900px;
margin: 0;
}
.outline {
flex: 2;
}
section {
flex: 7;
}
/*header*/
header {
display: flex;
}
.login ul,
.menu ul {
display: flex;
}
.login ul {
justify-content: flex-end;
}
.toparea {
margin-left: auto;
}
/*section*/
.contents {
display: flex;
}
/*media query*/
@media only screen and (max-width: 768px) {
body {
background-color: #EAC0F0;
}
header {
flex-direction: column;
}
.logo {
justify-content: center;
}
.login {
display: none;
}
.menu ul {
flex-direction: column;
}
.contents {
flex-direction: column;
}
.outline ul {
display: flex;
}
.outline li {
flex: 1;
}
}
/*footer*/
/*temp*/
img,
.login ul,
.menu ul,
.outline li {
border: 1px solid black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>RWD</title>
<link rel="stylesheet" href="./rwd.css">
</head>
<body>
<div class="container">
<header>
<img src="" alt="logo">
<div class="toparea">
<nav class="login">
<ul>
<li>Login</li>
<li>Help</li>
</ul>
</nav>
<nav class="menu">
<ul>
<li>Menu1</li>
<li>Menu2</li>
<li>Menu3</li>
<li>Menu4</li>
</ul>
</nav>
</div>
</header>
<div class="contents">
<div class="outline">
<ul>
<li>Outline1-1</li>
<li>Outline1-2</li>
</ul>
</div>
<section>
<h1>heading</h1>
<p>paragraph</p>
</section>
</div>
<footer>
<address>Contact : email@email.com</address>
</footer>
</div>
</body>
</html>