我正在制作一个用flex类构建的网格系统。这是我第一次使用flex,所以我还不确定它是如何工作的。
我到目前为止制作的网格 is looking like this。
我希望flexbox项目6如下图所示:
目前第5项和第6项的宽度分别为50%
item5和item6的宽度为50%。我似乎无法改变这一点。我希望第5项占66%,第6项占33%,但元素周围仍有边距。
有人可以看到我在做什么吗?
<style>
.d-flex {
display: -ms-flexbox!important;
display: flex!important
}
.d-inline-flex {
display: -ms-inline-flexbox!important;
display: inline-flex!important
}
.flex-wrap {
-ms-flex-wrap: wrap!important;
flex-wrap: wrap!important
}
.bg-img {
background-position: center center;
background-size: cover;
background-repeat: no-repeat; }
/* CTA Buttons */
.btn-top-left {
position: absolute;
left: 10%;
top: 10%
}
.btn-top-right {
}
.btn-center {
position: absolute;
left: 50%;
top: 50%
}
.btn-bottom-left {
}
.btn-bottom-right {
}
/* :: Set overlay over image and placement of text */
.single-welcome-post {
position: relative;
z-index: 1; }
.single-welcome-post::after {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.4);
content: '';
z-index: 5; }
.single-welcome-post .welcome-post-content {
position: absolute;
z-index: 100;
left: 50px;
bottom: 50px;
right: 50px; }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.single-welcome-post .welcome-post-content {
left: 20px;
bottom: 20px;
right: 20px; } }
@media only screen and (max-width: 767px) {
.single-welcome-post .welcome-post-content {
left: 15px;
bottom: 15px;
right: 15px; } }
.single-welcome-post.style-2 {
height: 645px; }
.hero-area {
position: relative;
z-index: 0;
background-color: #ffffff;
padding: 5px; }
.hero-area .hero-single-section {
position: relative;
z-index: 0;
-webkit-box-flex: 0;
-ms-flex: 0 0 50%;
flex: 0 0 50%;
max-width: 50%;
width: 50%; }
@media only screen and (max-width: 767px) {
.hero-area .hero-single-section {
-webkit-box-flex: 0;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
max-width: 100%;
width: 100%; } }
.hero-area .item1 {
height: 700px;
margin: 5px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item1 {
height: 600px; } }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item1 {
height: 500px; } }
@media only screen and (max-width: 767px) {
.hero-area .item1 {
height: 350px; } }
.hero-area .item2 {
height: 340px;
margin: 5px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item2 {
height: 290px; } }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item2 {
height: 240px; } }
@media only screen and (max-width: 767px) {
.hero-area .item2 {
height: 200px; } }
.hero-area .item3 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(50% - 10px);
width: calc(50% - 10px);
margin: 5px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item3 {
height: 300px; } }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item3 {
height: 250px; } }
@media only screen and (max-width: 767px) {
.hero-area .item3 {
height: 200px; } }
.hero-area .item4 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(50% - 10px);
width: calc(50% - 10px);
margin: 5px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item4 {
height: 300px; } }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item4 {
height: 250px; } }
@media only screen and (max-width: 767px) {
.hero-area .item4 {
height: 200px; } }
.hero-area .item5 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(130% - 10px);
width: calc(130% - 10px);
margin: 5px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item5 {
height: 300px; } }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item5 {
height: 250px;
max-width: calc(100% - 10px); } }
@media only screen and (max-width: 767px) {
.hero-area .item5 {
height: 200px;
max-width: calc(100% - 10px); } }
.hero-area .item6 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(100% - 10px);
width: calc(100% - 10px);
margin: 5px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item6 {
height: 300px; } }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item6 {
height: 250px;
max-width: calc(100% - 10px); } }
@media only screen and (max-width: 767px) {
.hero-area .item6 {
height: 200px;
max-width: calc(100% - 10px); } }
.hero-area .item7 {
height: 350px;
-webkit-box-flex: 0;
-ms-flex: 0 0 calc(50% - 10px);
flex: 0 0 calc(50% - 10px);
max-width: calc(100% - 10px);
width: calc(100% - 10px);
margin: 5px; }
@media only screen and (min-width: 992px) and (max-width: 1199px) {
.hero-area .item7 {
height: 300px; } }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.hero-area .item7 {
height: 250px;
max-width: calc(100% - 10px); } }
@media only screen and (max-width: 767px) {
.hero-area .item7 {
height: 200px;
max-width: calc(100% - 10px); } }
.single-blog-post {
position: relative;
z-index: 1; }
.single-blog-post .blog-thumb {
position: relative;
z-index: 1; }
.single-blog-post .blog-thumb img {
width: 100%; }
.single-blog-post .blog-content .post-tag {
color: #a6a6a6;
text-transform: uppercase;
font-size: 12px;
display: block;
font-weight: 700;
margin-bottom: 5px; }
.single-blog-post .blog-content .post-tag:hover, .single-blog-post .blog-content .post-tag:focus {
color: #ff1662; }
/* Set font-size */
@media only screen and (max-width: 767px) {
.single-blog-post .blog-content .post-tag {
font-size: 10px; } }
.single-blog-post .blog-content .post-title {
font-weight: 600;
font-size: 30px;
display: block;
color: #282828;
margin-bottom: 10px; }
/* Align text */
@media only screen and (max-width: 767px) {
.single-blog-post .blog-content .post-title {
font-size: 16px; } }
.single-blog-post .blog-content .post-title:hover, .single-blog-post .blog-content .post-title:focus {
color: #ff1662; }
.single-blog-post .blog-content .post-meta {
display: -webkit-box;
display: -ms-flexbox;
display: flex; }
/* Set space between text elements*/
.single-blog-post .blog-content .post-meta a {
color: #ffffff;
margin-right: 15px;
font-size: 11px;
line-height: 1;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: end;
-ms-flex-align: end;
-ms-grid-row-align: flex-end;
align-items: flex-end; }
/* Set color and placement on text*/
@media only screen and (max-width: 767px) {
.single-blog-post .blog-content .post-meta a {
font-size: 8px;
margin-right: 5px; } }
.single-blog-post .blog-content .post-meta a img {
margin-right: 10px; }
.single-blog-post .blog-content .post-meta a:last-child {
margin-right: 0; }
.single-blog-post .blog-content .post-meta a:hover, .single-blog-post .blog-content .post-meta a:focus {
color: #ff1662; }
.single-blog-post.white .blog-content .post-title,
.single-blog-post.white .blog-content .post-tag,
.single-blog-post.white .blog-content .post-meta a {
color: #ffffff; }
.single-blog-post.white .blog-content .post-title:hover, .single-blog-post.white .blog-content .post-title:focus,
.single-blog-post.white .blog-content .post-tag:hover,
.single-blog-post.white .blog-content .post-tag:focus,
.single-blog-post.white .blog-content .post-meta a:hover,
.single-blog-post.white .blog-content .post-meta a:focus {
color: #008ebe; }
.single-blog-post.style2 .blog-content .post-title {
font-size: 24px; }
/* Sidebar Nyhedsbrev */
.sidebar-area {
position: relative;
z-index: 1; }
@media only screen and (min-width: 768px) and (max-width: 991px) {
.sidebar-area {
margin-top: 100px; } }
@media only screen and (max-width: 767px) {
.sidebar-area {
margin-top: 100px; } }
.single-widget-area {
position: relative;
z-index: 1; }
.single-widget-area.newsletter-widget {
background-color: #f0f4f8;
padding: 50px 20px;
text-align: center; }
.single-widget-area.newsletter-widget h4 {
margin-bottom: 25px; }
.single-widget-area.newsletter-widget form input {
text-align: center;
width: 100%;
background-color: #d4dfe3;
height: 54px;
font-size: 12px;
font-style: italic;
color: #4c4c4c;
border: none;
margin-bottom: 15px; }
.single-widget-area.newsletter-widget p {
font-size: 12px;
font-style: italic; }
.single-widget-area.news-widget h4 {
margin-bottom: 60px; }
</style>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<!-- ##### Hero Area Start ##### -->
<div class="hero-area d-flex flex-wrap">
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item1" style="background-image: url(http://vouzalis.dk/stack/1.jpg);">
<!-- Content -->
<a href="https://www.youtube.com/watch?v=0aNNYEUARAk" class="video-play-btn"><i class="fa fa-play"></i></a>
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
<a href="#" class="post-tag">Featured</a>
<a href="#" class="post-title">Watch a tiny cat taking a bath</a>
<div class="post-meta">
<a href="#">Here is a text about the picture</a>
</div>
<button href="#" class="btn btn-success btn-center">Read More</button>
</div>
</div>
</div>
</div>
</div>
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item2" style="background-image: url(http://vouzalis.dk/stack/2.jpg);">
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
<a href="#" class="post-tag">Featured</a>
<a href="#" class="post-title">Spain: Take a virtual tour</a>
<div class="post-meta">
<a href="#"> Her er en tekst</a>
</div>
</div>
</div>
</div>
</div>
<div class="hero-second-section d-flex flex-wrap">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item3" style="background-image: url(http://vouzalis.dk/stack/3.jpg);">
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post style2 white">
<div class="blog-content">
<a href="#" class="post-tag">Featured</a>
<a href="#" class="post-title">5 Tips to create your garden</a>
</div>
</div>
</div>
</div>
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item4" style="background-image: url(http://vouzalis.dk/stack/4.jpg);">
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post style2 white">
<div class="blog-content">
<a href="#" class="post-tag">Featured</a>
<a href="#" class="post-title">10 Movies you need to see</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item5" style="background-image: url(http://vouzalis.dk/stack/1.jpg);">
<!-- Content -->
<a href="https://www.youtube.com/watch?v=0aNNYEUARAk" class="video-play-btn"><i class="fa fa-play"></i></a>
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
<a href="#" class="post-tag">Featured</a>
<a href="#" class="post-title">Watch a tiny cat taking a bath</a>
<div class="post-meta">
<a href="#">Here is a text about the picture</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="hero-single-section">
<!-- Single Welcome Post -->
<div class="single-welcome-post bg-img item6" style="background-image: url(http://vouzalis.dk/stack/2.jpg);">
<!-- Content -->
<a href="https://www.youtube.com/watch?v=0aNNYEUARAk" class="video-play-btn"><i class="fa fa-play"></i></a>
<!-- Content -->
<div class="welcome-post-content">
<!-- Single Blog Post -->
<div class="single-blog-post white">
<div class="blog-content">
<a href="#" class="post-tag">Featured</a>
<a href="#" class="post-title">Watch a tiny cat taking a bath</a>
<div class="post-meta">
<a href="#">Here is a text about the picture</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- ##### Hero Area end ##### -->
答案 0 :(得分:2)
宽度百分比不是我要使用的东西。我将最后2个元素包装到另一个div中,使其弯曲,然后针对该特定屏幕宽度将flex:1;
添加到第一个元素,并将flex:2;
添加到第二个元素。
这也将使宽度响应。最重要的是,避免百分比,将flex:
属性与flexbox项一起使用。
.wrapper {
width: 100%;
min-height: 150px;
display: flex;
justify-content: center;
align-items: center;
}
.one {
min-height: 150px;
flex: 2;
background: red;
}
.two {
min-height: 150px;
flex: 1;
background: green;
}
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
</div>
答案 1 :(得分:0)
您可以像这样在引导程序中解决此问题
.vh-100 {
height:100vh
}
.vh-50 {
height:50vh
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-6 bg-dark vh-100">
</div>
<div class="col-6 vh-100 bg-danger">
<div class="row">
<div class="col-6 vh-50 bg-primary">
</div>
<div class="col-6 vh-50 bg-warning">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-8 bg-success vh-100">
</div>
<div class="col-4 vh-100 bg-info">
</div>
</div>