【发布时间】:2018-09-21 00:39:52
【问题描述】:
我正在尝试使用 FlexBox 创建一个页面,这样我就可以使主图像始终以顶部徽标和页面居中。并在左侧添加“偏离中心”文本。
我现在的问题是我无法让每个框(图像+文本)保持垂直位置,框浮动,并且根据我用来查看的内容(大屏幕、笔记本电脑),它们之间的空间不同。
我不是 FlexBox 专家,我可以这样做吗?
另外,我想在第三个框之后添加一个栏,100% 宽度...但它位于页面中间,框之间。
欢迎任何帮助,我会继续学习:)
body {
margin: 0;
}
.container {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
height: 100vh;
}
.top {
border: 1px solid white;
width: 50%;
height: 10%;
align-self: flex-start;
text-align: center;
}
.inner-container {
border: 1px solid white;
width: 50%;
height: 60%;
display: flex;
}
.center {
position: absolute;
width: 50%;
text-align: left;
align-self: flex-end;
}
.off-center {
position: absolute;
vertical-align: bottom;
text-transform: uppercase;
padding-left: 10px;
min-width: 200px;
align-self: flex-end;
}
.center, .off-center {
position: absolute;
}
.center img {width: 100%;}
.off-center h2 {font-size:12px; font-family: 'Open Sans', sans-serif; font-weight: 400;text-transform: uppercase; color:black; display: block!important;margin: 0px;}
.off-center p {font-size: 20px; font-family:'aileronbold', sans-serif; display: block!important;margin: 0px;text-transform: none;}
.row.subscriptionBar {display:flex; background-color: black; display: block; padding:20px;}
.subscriptionBar h2 {color:white;}
.firstPart {display: }
@media screen and (min-width: 769px) {
.off-center {
margin-left: 50%;
}
@media screen and (max-width: 768px) {
.off-center {
margin-top: 105px;
}
}
<div class="container">
<div class="top"><img src="https://www.oilandgasreinvented.com/img/logo-placeholder.svg" width="80px"></div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 1</h2>
<p>509476ZclHtqXy</p></div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 2</h2>
<p>Title lala 1</p></div>
</div>
<div class="inner-container">
<div class="center">
<img src="http://hdimages.org/wp-content/uploads/2017/03/placeholder-image1.gif" alt=""></div>
<div class="off-center">
<h2 class="">ArtistName 3 444</h2>
<p>Title 093830</p></div>
</div>
</div>
【问题讨论】:
-
您的代码看起来非常接近您想要实现的目标。你能解释一下实际问题是什么吗?
-
好的,谢谢。问题: 1) 图像/框垂直移动,有时会越过顶部的徽标。我习惯于使用 Bootstrap 和 CSS,但使用 flexbox 我不知道如何设置边界。 2)我认为与上一个项目相同的问题,但我如何设置水平图像和垂直图像以保持相同的比例。检查附加在我的帖子上的示例/线框。目前,垂直图像与其他框重叠。 3)单杠:在页面中间,我要在第三个框之后。
-
我在您的布局中看不到任何水平条。此外,您可能希望通过进一步分解问题来简化问题。也许将这个问题集中在一个问题上。一旦解决了这个问题,请关注新问题中的下一个问题。这将使问题更容易理解,对贡献者更有吸引力。
-
我认为如果您将
flex-direction: column;添加到您的容器中,您的布局会容易得多。