实际上,我一直在尝试自己解决这些问题,但似乎无法弄清楚,我已经使用flexbox创建了一个布局,但我正在尝试实现一些目标。让我说: 我有一个标题,导航和一个三列部分,其中包括主要部分和左右两个侧边栏,我想在以下位置添加更多侧边栏 右侧边栏,但我似乎无法弄清楚,因为您知道我已经声明了三列flex ...
您可以在此处查看图片以了解要实现的目标
此处为源代码www.codepen.io/enipx/details/dQmXKP
答案 0 :(得分:0)
您可以在右侧div中包装两个侧边栏。
/* ===== Framework ===== */
html{
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
}
*, *::before, *::after{
box-sizing: inherit;
}
body{
background-color: #fdfafb;
height: 100vh;
/* border: 1px solid green; */
margin: 0 auto;
width: 100%;
}
.col-1{
width: 8.33%;
}
.col-2{
width: 16.66%;
}
.col-3{
width: 25%;
}
.col-4{
width: 33.33%;
}
.col-5{
width: 41.66%;
}
.col-6{
width: 50%;
}
.col-7{
width: 58.33%;
}
.col-8{
width: 66.66%;
}
.col-9{
width: 75%;
}
.col-10{
width: 83.33%;
}
.col-11{
width: 91.66%;
}
.col-12{
width: 100% ;
}
/* ===== Layout ===== */
#header{
margin: 10px;
height: 90px;
border-radius: 5px 5px 0 0;
background-color: rgba(160,194,227,0.8);
text-align: center;
color: white;
font-size: medium;
}
#nav{
margin: 10px;
margin-top: 0;
height: 40px;
border-radius: 0;
background-color: rgba(160,194,227,0.3);
text-align: center;
color: white;
font-size: medium;
}
.mainparent{
display: flex;
}
.sidebarright{
flex-basis: 16%;
order: 1;
}
.sidebarrightfirst{
margin: 10px;
margin-top: 0;
border-radius: 0;
background-color: rgba(160,194,227,0.5);
text-align: center;
color: white;
font-size: medium;
height: 195px;
}
.sidebarrightsecond{
margin: 10px;
margin-top: 0;
border-radius: 0;
background-color: rgba(160,194,227,0.5);
text-align: center;
color: white;
font-size: medium;
height: 195px;
}
.sidebarleft{
margin: 10px;
margin-top: 0;
border-radius: 0;
background-color: rgba(160,194,227,0.5);
text-align: center;
color: white;
font-size: medium;
flex-basis: 16%;
order: -1;
height: 400px;
}
.main{
margin-bottom: 10px;
margin-top: 0;
margin-right: 0;
margin-left: 0;
border-radius: 0;
background-color: rgba(160,194,227,0.5);
text-align: center;
color: white;
font-size: medium;
flex-basis: 68%;
height: 400px;
}
.imgport{
display: flex;
flex-wrap: wrap;
}
.imgport img {
width: calc(25% - 20px);
height: 200px;
margin: 10px;
margin-top: 0;
opacity: 0.8;
transition: 0.5s ease-in-out;
}
.imgport img:hover {
opacity: 1.0;
}
#footer{
margin: 10px;
margin-top: 0;
height: 200px;
border-radius: 0 0 5px 5px;
background-color: rgba(160,194,227,0.8);
text-align: center;
color: white;
font-size: medium;
}
<header id="header">
header
</header>
<nav id="nav">
nav
</nav>
<div class="mainparent">
<div class="sidebarright">
<aside class="sidebarrightfirst">
sidebarright
</aside>
<aside class="sidebarrightsecond">
sidebarright
</aside>
</div>
<aside class="sidebarleft">
sidebarleft
</aside>
<section class="main">
main
</section>
</div>
<div class="imgport">
<img src="https://images.unsplash.com/photo-1536276502222-b10f42bcf71e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=6266a66ab254251150d738aad585fd36" alt="boxes">
<img src="https://images.unsplash.com/photo-1538592716926-9a321f0614ea?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=488b23073a233d23083f36b67c3bd769" alt="boxes">
<img src="https://images.unsplash.com/photo-1506798161991-ff979d14a391?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=7378c40e370c1207c6bca0d269c81818" alt="boxes">
<img src="https://images.unsplash.com/photo-1537203626302-cb08b9deb186?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=224379104368ef8280a06dfedda5c01b" alt="boxes">
<img src="https://images.unsplash.com/photo-1534256007535-8692ac6876cf?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=4c0f4f5d14175406c0ab97a8a0700950" alt="boxes">
<img src="https://images.unsplash.com/photo-1521405785232-7a56b029191e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c15f44bf62d0a5307c50150953fea8deg" alt="boxes">
<img src="https://images.unsplash.com/photo-1521405785232-7a56b029191e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c15f44bf62d0a5307c50150953fea8de" alt="boxes">
<img src="https://images.unsplash.com/photo-1534256007535-8692ac6876cf?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=4c0f4f5d14175406c0ab97a8a0700950" alt="boxes">
</div>
<footer id="footer">
footer
</footer>
答案 1 :(得分:0)
Updated Codepen here 这个想法是在右侧栏中包装一列flexbox布局。
/* ===== Framework ===== */
html{
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
}
*, *::before, *::after{
box-sizing: inherit;
}
body{
background-color: #fdfafb;
height: 100vh;
/* border: 1px solid green; */
margin: 0 auto;
width: 100%;
}
.col-1{
width: 8.33%;
}
.col-2{
width: 16.66%;
}
.col-3{
width: 25%;
}
.col-4{
width: 33.33%;
}
.col-5{
width: 41.66%;
}
.col-6{
width: 50%;
}
.col-7{
width: 58.33%;
}
.col-8{
width: 66.66%;
}
.col-9{
width: 75%;
}
.col-10{
width: 83.33%;
}
.col-11{
width: 91.66%;
}
.col-12{
width: 100% ;
}
/* ===== Layout ===== */
#header{
margin: 10px;
height: 90px;
border-radius: 5px 5px 0 0;
background-color: rgba(160,194,227,0.8);
text-align: center;
color: white;
font-size: medium;
}
#nav{
margin: 10px;
margin-top: 0;
height: 40px;
border-radius: 0;
background-color: rgba(160,194,227,0.3);
text-align: center;
color: white;
font-size: medium;
}
.mainparent{
display: flex;
}
.sidebarright{
border-radius: 0;
text-align: center;
color: white;
font-size: medium;
flex-basis: 16%;
order: 1;
}
.column {
display: flex;
flex-direction: column;
}
.column .top,
.column .bottom {
margin: 10px;
margin-top: 0;
flex-basis: 100%;
max-width: 100%;
height: 195px;
background-color: rgba(160,194,227,0.8);
}
.sidebarleft{
margin: 10px;
margin-top: 0;
border-radius: 0;
background-color: rgba(160,194,227,0.5);
text-align: center;
color: white;
font-size: medium;
flex-basis: 16%;
order: -1;
height: 400px;
}
.main{
margin-bottom: 10px;
margin-top: 0;
margin-right: 0;
margin-left: 0;
border-radius: 0;
background-color: rgba(160,194,227,0.5);
text-align: center;
color: white;
font-size: medium;
flex-basis: 68%;
height: 400px;
}
.imgport{
display: flex;
flex-wrap: wrap;
}
.imgport img {
width: calc(25% - 20px);
height: 200px;
margin: 10px;
margin-top: 0;
opacity: 0.8;
transition: 0.5s ease-in-out;
}
.imgport img:hover {
opacity: 1.0;
}
#footer{
margin: 10px;
margin-top: 0;
height: 200px;
border-radius: 0 0 5px 5px;
background-color: rgba(160,194,227,0.8);
text-align: center;
color: white;
font-size: medium;
}
<!DOCTYPE html>
<html>
<head>
<title>Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" initial-scale="1.0">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<header id="header">
header
</header>
<nav id="nav">
nav
</nav>
<div class="mainparent">
<aside class="sidebarright">
<div class="column">
<div class="top">sidebarright top</div>
<div class="bottom">sidebarright bottom</div>
</div>
</aside>
<aside class="sidebarleft">
sidebarleft
</aside>
<section class="main">
main
</section>
</div>
<div class="imgport">
<img src="https://images.unsplash.com/photo-1536276502222-b10f42bcf71e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=6266a66ab254251150d738aad585fd36" alt="boxes">
<img src="https://images.unsplash.com/photo-1538592716926-9a321f0614ea?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=488b23073a233d23083f36b67c3bd769" alt="boxes">
<img src="https://images.unsplash.com/photo-1506798161991-ff979d14a391?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=7378c40e370c1207c6bca0d269c81818" alt="boxes">
<img src="https://images.unsplash.com/photo-1537203626302-cb08b9deb186?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=224379104368ef8280a06dfedda5c01b" alt="boxes">
<img src="https://images.unsplash.com/photo-1534256007535-8692ac6876cf?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=4c0f4f5d14175406c0ab97a8a0700950" alt="boxes">
<img src="https://images.unsplash.com/photo-1521405785232-7a56b029191e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c15f44bf62d0a5307c50150953fea8deg" alt="boxes">
<img src="https://images.unsplash.com/photo-1521405785232-7a56b029191e?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c15f44bf62d0a5307c50150953fea8de" alt="boxes">
<img src="https://images.unsplash.com/photo-1534256007535-8692ac6876cf?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=4c0f4f5d14175406c0ab97a8a0700950" alt="boxes">
</div>
<footer id="footer">
footer
</footer>
</body>
</html>
答案 2 :(得分:0)
对于那些正在寻找这个问题的答案的人,这是我的解决方案。
/* all */
a {
text-decoration: none;
}
h1 {
font-size: 20px;
}
.body {
display: flex;
align-items: center;
flex-direction: column;
}
.wrapper {
box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.75);
border-radius: 0 0 10px 10px;
}
/* Header */
/*header {*/
/* display: flex;*/
/* justify-content: center;*/
/* padding: 10px 10px;*/
/*}*/
.page-info {
display: flex;
justify-content: center;
border: 3px solid black;
}
.page-menu {
display: flex;
justify-content: center;
border: 3px solid black;
}
nav li {
display: inline-block;
list-style: none;
}
nav a {
display: block;
padding: 20px;
color: royalblue;
text-decoration: none;
}
/* main */
.main-content{
display: flex;
flex-direction: row;
}
.main-content .vmist{
/** Задаём ширину 60% **/
flex: 6;
order: 0;
align-items: center;
display: flex;
justify-content: center;
border: 3px solid black;
}
/*.main-content .left-side{*/
/* flex: 4;*/
/* order: 1;*/
/* border: 3px solid black;*/
/*}*/
.sidebarright{
display: grid;
flex: 4;
order: 1;
}
.dodatok {
background-color: orange;
display: flex;
align-items: center;
justify-content: center;
border: 3px solid black;
}
.footer {
background-color: gray;
display: flex;
align-items: center;
justify-content: center;
border: 3px solid black;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<div class="wrapper">
<header>
<div class="page-info">
<h1>Test</h1>
</div>
<div class="page-menu">
<nav>
<ul id="menu-active">
<li class="menu-item"><a href="#info">1</a></li>
<li class="menu-item"><a href="#news">2</a></li>
<li class="menu-item"><a href="#place">3</a></li>
<li class="menu-item"><a href="#worker">4</a></li>
</ul>
</nav>
</div>
</header>
<div class="main-content">
<div class="vmist">
<p>Test</p>
</div>
<div class="sidebarright">
<div class="dodatok">
<aside class="sidebarrightfirst">
right1
</aside>
</div>
<div class="footer">
<aside class="sidebarrightfirst">
right2
</aside>
</div>
</div>
</div>
</div>
</body>
</html>