Подскажите как рассположить елементы в ряд, в мобильной версии?
Мне нужно чтобы навигация занимала всю страницу при ширине екрана 600px, сейчас мой код выглядит вот так
*{
box-sizing: border-box;
}
html,
body {
font-size: 16px;
font-family: Verdana, sans-serif;
color: #555;
display: flex;
flex-direction: column;
min-height: 100vh;
flex-shrink: 1;
flex-wrap: wrap;
}
.header {
color: white;
background: linear-gradient(60deg, red, orange);
text-align: center;
flex-shrink: 1;
}
.main {
display: flex;
flex-grow: 1;
}
.footer {
background-color: #e5e5e5;
text-align: center;
padding: 0.5em;
}
.section {
width: 60%;
font-size: 1.25em;
padding: 0.5em;
margin: 0;
}
.section__header {
text-align: center;
font-size: 5vw;
}
.navigation {
width: 20%;
padding: 0.5em;
}
.nav-list-item {
list-style-type: none;
background-color: #808080;
height: 2em;
line-height: 2em;
margin-bottom: 0.5em;
color: white;
}
.nav-list-link {
width: 100%;
text-decoration: none;
color: white;
display: inline-block;
padding: 0 0.5em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.nav-list {
padding: 0;
}
.css-units {
color: #8b0000;
background-color: #e5e5e5;
font-weight: 700;
font-size: 1.125em;
}
.units-list {
height: 1.75em;
line-height: 1.75em;
}
.news {
width: 20%;
padding: 0.5em;
}
picture{
width: 60%;
}
img{
width: 100%;
box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.2);
}
@media screen and (min-width: 600px){
.navigation {
display: flex;
flex-direction: column;
}
.section {
flex: 1;
flex-direction: column;
}
.news {
flex: 1;
flex-direction: column;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css"
integrity="sha256-WAgYcAck1C1/zEl5sBl5cfyhxtLgKGdpI3oKyJffVRI="
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<header class="header">
<h1>Responsive website</h1>
</header>
<main class="main">
<nav class="navigation">
<ul class="nav-list">
<li class="nav-list-item"><a class="nav-list-link" href="#">Responsive images</a></li>
<li class="nav-list-item"><a class="nav-list-link" href="#">Mediaqueries</a></li>
<li class="nav-list-item"><a class="nav-list-link" href="#">Flexbox</a></li>
</ul>
</nav>
<section class="section">
<h2 class="section__header">True story</h2>
<picture>
<source class="big-picture" srcset="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/big.png"
media="(min-width: 1200px)">
<img class="smal-picture" src="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/small.png"
alt="smal picture">
<!-- <img class="big-picture" srcset="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/big.png"
alt="picture"> -->
</picture>
<p>There are few ways to define <code>font-size</code>:</p>
<ul class="units-list">
<li>
<span class="css-units">px</span> are good if you need strict definition for a size of
text. In other cases it is better to use relative units listed below.
</li>
<li><span class="css-units">em</span> based on current font size</li>
<li><span class="css-units">rem</span> based on <code><html></code> font-size</li>
<li><span class="css-units">%</span> based on parent font size</li>
<li><span class="css-units">vh</span> (viewport height) based on screen height</li>
<li><span class="css-units">vw</span> (viewport width) based on screen width</li>
</ul>
</section>
<aside class="news">
<h2>Not a news</h2>
<p>A web page should look good on any device!</p>
</aside>
</main>
<footer class="footer">Welcome to the responsive world!</footer>
</body>
</html>
Ответы (2 шт):
Автор решения: Яна Коваль
→ Ссылка
*{
box-sizing: border-box;
}
html,
body {
font-size: 16px;
font-family: Verdana, sans-serif;
color: #555;
display: flex;
flex-direction: column;
min-height: 100vh;
flex-shrink: 1;
flex-wrap: wrap;
}
.header {
color: white;
background: linear-gradient(60deg, red, orange);
text-align: center;
flex-shrink: 1;
}
.main {
display: flex;
flex-grow: 1;
flex-direction: column;
}
.footer {
background-color: #e5e5e5;
text-align: center;
padding: 0.5em;
}
.section {
flex-direction: column;
/* width: 60%; */
width: 100%;
font-size: 1.25em;
padding: 0.5em;
margin: 0;
}
.section__header {
text-align: center;
font-size: 5vw;
}
.navigation {
width: 100%;
/* width: 20%; */
padding: 0.5em;
}
.nav-list-item {
list-style-type: none;
background-color: #808080;
height: 2em;
line-height: 2em;
margin-bottom: 0.5em;
color: white;
}
.nav-list-link {
/* width: 100%; */
text-decoration: none;
color: white;
display: inline-block;
padding: 0 0.5em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.nav-list {
padding: 0;
}
.css-units {
color: #8b0000;
background-color: #e5e5e5;
font-weight: 700;
font-size: 1.125em;
}
.units-list {
height: 1.75em;
line-height: 1.75em;
}
.news {
width: 20%;
/* width: 20%; */
padding: 0.5em;
width: 100%;
}
picture{
width: 60%;
}
img{
width: 100%;
box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.2);
}
@media screen and (min-width: 600px){
.navigation{
display: flex;
flex-direction: column;
}
.section{
flex: 1;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css"
integrity="sha256-WAgYcAck1C1/zEl5sBl5cfyhxtLgKGdpI3oKyJffVRI="
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<header class="header">
<h1>Responsive website</h1>
</header>
<main class="main">
<nav class="navigation">
<ul class="nav-list">
<li class="nav-list-item"><a class="nav-list-link" href="#">Responsive images</a></li>
<li class="nav-list-item"><a class="nav-list-link" href="#">Mediaqueries</a></li>
<li class="nav-list-item"><a class="nav-list-link" href="#">Flexbox</a></li>
</ul>
</nav>
<section class="section">
<h2 class="section__header">True story</h2>
<picture>
<source class="big-picture" srcset="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/big.png"
media="(min-width: 1200px)">
<img class="smal-picture" src="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/small.png"
alt="smal picture">
<!-- <img class="big-picture" srcset="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/big.png"
alt="picture"> -->
</picture>
<p>There are few ways to define <code>font-size</code>:</p>
<ul class="units-list">
<li>
<span class="css-units">px</span> are good if you need strict definition for a size of
text. In other cases it is better to use relative units listed below.
</li>
<li><span class="css-units">em</span> based on current font size</li>
<li><span class="css-units">rem</span> based on <code><html></code> font-size</li>
<li><span class="css-units">%</span> based on parent font size</li>
<li><span class="css-units">vh</span> (viewport height) based on screen height</li>
<li><span class="css-units">vw</span> (viewport width) based on screen width</li>
</ul>
</section>
<aside class="news">
<h2>Not a news</h2>
<p>A web page should look good on any device!</p>
</aside>
</main>
<footer class="footer">Welcome to the responsive world!</footer>
</body>
</html>
текст, выделенный жирным шрифтом
Автор решения: Anton Essential
→ Ссылка
Ставим .main {flex-direction: column;} это правило выстроит блоки в колонки, далее растягиваем naw, section, news {width: 100%;} и убираем у .units-list высоту
*{
box-sizing: border-box;
}
html,
body {
font-size: 16px;
font-family: Verdana, sans-serif;
color: #555;
display: flex;
flex-direction: column;
min-height: 100vh;
flex-shrink: 1;
flex-wrap: wrap;
}
.header {
color: white;
background: linear-gradient(60deg, red, orange);
text-align: center;
flex-shrink: 1;
}
.main {
display: flex;
flex-grow: 1;
flex-direction: column;
}
.footer {
background-color: #e5e5e5;
text-align: center;
padding: 0.5em;
}
.section {
flex-direction: column;
width: 100%;
font-size: 1.25em;
padding: 0.5em;
margin: 0;
}
.section__header {
text-align: center;
font-size: 5vw;
}
.navigation {
width: 100%;
padding: 0.5em;
}
.nav-list-item {
list-style-type: none;
background-color: #808080;
height: 2em;
line-height: 2em;
margin-bottom: 0.5em;
color: white;
}
.nav-list-link {
text-decoration: none;
color: white;
display: inline-block;
padding: 0 0.5em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.nav-list {
padding: 0;
}
.css-units {
color: #8b0000;
background-color: #e5e5e5;
font-weight: 700;
font-size: 1.125em;
}
.units-list {
/* height: 1.75em; */
line-height: 1.75em;
}
.news {
width: 20%;
padding: 0.5em;
width: 100%;
}
picture{
width: 60%;
}
img{
width: 100%;
box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.2);
}
@media screen and (min-width: 600px){
.navigation{
display: flex;
flex-direction: column;
}
.section{
flex: 1;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css"
integrity="sha256-WAgYcAck1C1/zEl5sBl5cfyhxtLgKGdpI3oKyJffVRI="
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<header class="header">
<h1>Responsive website</h1>
</header>
<main class="main">
<nav class="navigation">
<ul class="nav-list">
<li class="nav-list-item"><a class="nav-list-link" href="#">Responsive images</a></li>
<li class="nav-list-item"><a class="nav-list-link" href="#">Mediaqueries</a></li>
<li class="nav-list-item"><a class="nav-list-link" href="#">Flexbox</a></li>
</ul>
</nav>
<section class="section">
<h2 class="section__header">True story</h2>
<picture>
<source class="big-picture" srcset="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/big.png"
media="(min-width: 1200px)">
<img class="smal-picture" src="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/small.png"
alt="smal picture">
<!-- <img class="big-picture" srcset="https://gromcode.s3.eu-central-1.amazonaws.com/front-end/html-css/lesson22/hw2/big.png"
alt="picture"> -->
</picture>
<p>There are few ways to define <code>font-size</code>:</p>
<ul class="units-list">
<li>
<span class="css-units">px</span> are good if you need strict definition for a size of
text. In other cases it is better to use relative units listed below.
</li>
<li><span class="css-units">em</span> based on current font size</li>
<li><span class="css-units">rem</span> based on <code><html></code> font-size</li>
<li><span class="css-units">%</span> based on parent font size</li>
<li><span class="css-units">vh</span> (viewport height) based on screen height</li>
<li><span class="css-units">vw</span> (viewport width) based on screen width</li>
</ul>
</section>
<aside class="news">
<h2>Not a news</h2>
<p>A web page should look good on any device!</p>
</aside>
</main>
<footer class="footer">Welcome to the responsive world!</footer>
</body>
</html>