Как растянуть SideBar до конца?
Нужно сделать так, чтобы сайдбар растянулся до конца высоты контента
body {
margin: 0px;
padding: 0px;
height: 100%;
font-family: 'Titillium Web', sans-serif;
}
html {
height: 100%;
}
a {
text-decoration: none;
}
.graficlogo {
padding: 5px;
max-width: 100%;
box-sizing: border-box;
}
header {
width: 100%;
display: flex;
justify-content: center;
background: #F6C010;
margin: 0;
}
#sidebar {
border-right: 5px solid #F6C010;
float: left;
padding: 5px;
margin-top: 3px;
margin-bottom: 3px;
background: #151718;
width: 200px;
height: 100%;
position: relative;
}
#sidebar h3 {
position: relative;
color: white;
text-align: center;
}
#sidebar__icon {
display: none;
float: left;
position: relative;
width: 50px;
height: 50px;
line-height: 50px;
text-align: center;
background: #151718;
}
#sidebar__icon a {
display: block;
color: white;
}
.sidebar__active {
display: block !important;
}
.search {
outline: none;
border-radius: 3px;
display: flex;
margin: auto;
padding: 10px;
margin-top: 20px;
border: 2px solid #F6C010;
width: 30%;
height: 15px;
}
main {
flex-grow: 1;
display: flex;
justify-content: center;
padding: 5px;
flex-wrap: wrap;
position: relative;
}
ul {
margin: 0px;
padding: 0px;
}
ul li {
list-style: none;
margin: 0;
}
ul li a {
background: #1C1E1F;
color: white;
display: block;
border-bottom: 1px solid black;
width: 180px;
padding: 10px;
text-decoration: none;
margin: 0;
}
ul li a:hover {
background: #F6C010;
transition: 0.25s;
color: white;
}
footer {
box-sizing: border-box;
display: block;
bottom: 0;
background: #F6C010;
height: 30%;
width: 100%;
display: flex;
justify-content: center;
flex-shrink: 0;
}
.social p {
color: white;
font-size: 25px;
}
.footer_social_img {
display: flex;
justify-content: space-around;
}
.tovari_items {
position: relative;
display: flex;
margin-top: 40px;
margin-bottom: 40px;
margin-left: 50px;
margin-right: 50px;
padding: 25px;
box-shadow: 0 0 10px;
cursor: pointer;
}
.tovari_block {
margin-top: -10px;
display: flex;
flex-wrap: wrap;
}
.tovari_items:hover {
box-shadow: 0 0 20px;
transition: 0.25s;
}
.tovar_list h3 {
display: flex;
justify-content: center;
}
.tovar_list p {
text-align: center;
font-size: 14px;
color: #6B6B6B;
}
#price h5 {
border-bottom: 2px solid #F6C010;
font-size: 16px;
padding-bottom: 5px;
display: flex;
justify-content: center;
}
#quantity_true h5 {
margin-top: -17px;
display: flex;
color: #54C418;
justify-content: center;
font-size: 14px;
}
#quantity_false h5 {
margin-top: -17px;
display: flex;
color: #FF0800;
justify-content: center;
font-size: 14px;
}
.buy {
cursor: pointer;
outline: none;
display: flex;
width: 100%;
background: #68D81E;
padding: 5px;
justify-content: center;
color: white;
border: none;
font-weight: 800;
}
.buy:hover {
background: #82F238;
transition: 0.25s;
}
@media screen and (max-width: 1290px) {
.tovari_block {
display: flex;
flex-wrap: wrap;
width: 30%;
box-sizing: border-box;
justify-content: center;
}
footer {
box-sizing: border-box;
}
}
@media screen and (max-width: 1024px) {
.tovari_block {
display: flex;
flex-wrap: wrap;
width: 85%;
justify-content: center;
box-sizing: border-box;
}
footer {
box-sizing: border-box;
}
.search {
width: 50%;
}
}
@media screen and (max-width: 768px) {
.tovari_block {
display: flex;
flex-wrap: wrap;
width: 100%;
justify-content: center;
box-sizing: border-box;
}
.search {
width: 90%;
}
footer {
box-sizing: border-box;
}
#sidebar {
display: none;
}
#sidebar__icon {
display: block;
}
}
@media screen and (max-width: 590px) {
.tovari_block {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 100%;
box-sizing: border-box;
}
footer {
box-sizing: border-box;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> WayStore </title>
<link rel="stylesheet" href="css/style.css">
<link href="https://fonts.googleapis.com/css2?family=Titillium+Web&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width">
</head>
<body>
<header>
<div class="logo">
<a href="index.html"><img class="graficlogo" src="img/logo_2.png"></a>
</div>
</header>
<div id="sidebar">
<h3> Каталог товаров </h3>
<ul>
<li><a href="#"> Телефоны и асскесуары </a></li>
<li><a href="#"> Мужская одежда </a></li>
<li><a href="#"> Женская одежда </a></li>
<li><a href="#"> Детская одежда </a></li>
<li><a href="#"> Бытовые приборы </a></li>
<li><a href="#"> Уличные площадки </a></li>
<li><a href="#"> Компьютерные акссесуары </a></li>
</ul>
</div>
<div id="sidebar__icon"><a href="#"> ☰ </a></div>
<input type="text" name="search" class="search" placeholder="Поиск по сайту">
<main>
<div class="tovari_block"> <!-- Товар блоки -->
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/telefon.png">
<div class="tovar_list">
<h3> Huawei P30 Lite </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_true">
<h5> Есть в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/tovar_iphone11proMAX.png">
<div class="tovar_list">
<h3> Iphone 11 Pro Max </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_false">
<h5> Нет в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/telefon.png">
<div class="tovar_list">
<h3> Huawei P30 Lite </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_true">
<h5> Есть в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/tovar_iphone11proMAX.png">
<div class="tovar_list">
<h3> Iphone 11 Pro Max </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_false">
<h5> Нет в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
</div> <!-- Товар блоки -->
<div class="tovari_block"> <!-- Товар блоки -->
<div class="tovari_block"> <!-- Товар блоки -->
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/telefon.png">
<div class="tovar_list">
<h3> Huawei P30 Lite </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_true">
<h5> Есть в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/tovar_iphone11proMAX.png">
<div class="tovar_list">
<h3> Iphone 11 Pro Max </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_false">
<h5> Нет в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/telefon.png">
<div class="tovar_list">
<h3> Huawei P30 Lite </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_true">
<h5> Есть в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
<div class="tovari_items">
<div class="tovar_img"><img src="img\tovari_leaderpage/tovar_iphone11proMAX.png">
<div class="tovar_list">
<h3> Iphone 11 Pro Max </h3>
<div id="price">
<h5> 9999 грн. </h5>
</div>
<div id="quantity_false">
<h5> Нет в наличии. </h5>
</div>
<div class="button">
<a href="https://mail.google.com/mail/u/0/#inbox?compose=CllgCHrkVmDmsQtcjCmMSdfnSmKtdCgPkWZshzFSbSpBgWxqVJHWcxNKWJdPBVqVbrnFFKvThLV" target="_blank">
<button class="buy" > Купить </button></a>
<p> Код товара: 000000 </p>
</div>
</div>
</div>
</div>
</div> <!-- Товар блоки -->
</main>
<footer>
<div class="social">
<p> Мы в социальных сетях! </p>
<div class="footer_social_img">
<a href="#"><img src="img/social_footer/footer_icon_instagram.png"></a>
<a href="#"><img src="img/social_footer/footer_icon_facebook.png"></a>
<a href="#"><img src="img/social_footer/footer_icon_twitter.png"></a>
</div>
</div>
</footer>
<script type="text/javascript" src="js/script.js"></script>
</body>
</html>
var sidebar = document.getElementById('sidebar');
var button = document.getElementById('sidebar__icon');
button.onclick = function() {
sidebar.classList.toggle('sidebar__active');
}
Ответы (1 шт):
Автор решения: MaximLensky
→ Ссылка
Предлагаю воспользоваться flex который если не указывать высоту явно сделает её автоматически равную всем flex потомкам и выглядит это так
header {
height: 150px;
background: green;
}
.items {
display: flex;
}
.bar {
background: #ccc;
width: 250px;
}
.content {
width: 100%;
}
.cart {
width: 300px;
height: 400px;
background: red;
border-radius: 20px;
margin: 20px auto;
}
<header></header>
<div class="items">
<div class="bar"></div>
<div class="content">
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
<div class="cart"></div>
</div>
</div>
