[英]Alignment of paragraphs and headings in CSS
I have a design below which I am trying to replicate in HTML and CSS: 我有一个设计,下面尝试在HTML和CSS中进行复制:
Note: I have written text Margin
and Padding
to make things easy to understand. 注意:我已经写了
Margin
和Padding
文字,以使事情容易理解。 It will not come in the actual design 不会出现在实际设计中
At this moment, I am able to get this in my fiddle . 此时此刻,我能够把它弄成小提琴了 。
The only thing which is not matching the above design in the fiddle are the paragraphs (eg: Our main goal, Among our biggest, etc) in every box which don't have line break
. 在小提琴
are the paragraphs (eg: Our main goal, Among our biggest, etc) in every box which don't have line break
唯一与上述设计不匹配的are the paragraphs (eg: Our main goal, Among our biggest, etc) in every box which don't have line break
。 I am considering boxes as every job-opening with titles (Back-end .., Front-end .., etc) and paragraphs (eg: Our main goal, Among our biggest, etc). 我正在考虑在每个职位空缺中加上标题(后端..,前端..等)和段落(例如:我们的主要目标,最大的目标等)中的框。
The CSS for every box is: 每个框的CSS是:
.firstrow {
display: inline-block;
width: 100%;
}
.firstrow #front-end {
text-align: center;
width: 50%;
height: 250px;
float: left;
background-repeat: no-repeat;
display: flex;
align-items: center;
background-size: 100% 100%;
justify-content: center;
}
Here is a improved version of your code, just using flexbox, without using float
s or anything else. 这是代码的改进版本,仅使用flexbox,而不使用
float
或其他任何东西。
h2 { text-align: center; font-size: 2.8rem; color: #444444; } .row { display: flex; flex-wrap: wrap; padding: 5%; } .row>div { padding: 5%; background: gray; margin: 15px; display: flex; flex-flow: column wrap; align-items: center; justify-content: center; text-align: center; flex: 1; box-sizing:border-box }
<div class="job-openings"> <h2>Seems Interesting? Apply Now</h2> <div class="row"> <div id="back-end"> <h3>Back-end Developer</h3> <p> Our main goal is to build and maintain the online platform and...</p> </div> <div id="front-end"> <h3>Front-end Web Developer</h3> <p>Among our biggest priorities are interface design and user experience...</p> </div> <div id="graphics"> <h3>Graphics Designer</h3> <p> We believe in the power of design. Our designers are motivated, creative and...</p> </div> <div id="sales"> <h3>Sales & Marketing</h3> <p>Our Marketing team is focussed on driving growth and building a brand that customers love...</p> </div> </div> </div>
Op's Comment to answer: Op的评论回答:
Back-end and front-end will come in one row with graphics designer and sales and marketing in another row.
后端和前端将排成一排,图形设计师以及销售和市场营销将排在另一排。
Assuming you want to have always 2 rows, then you can use flex:0 50%
instead of flex:1
, in this case flex: 0 calc(50% - 30px)
to take in count the margin 假设您总是要有2行,则可以使用
flex:0 50%
代替flex:1
,在这种情况下, flex: 0 calc(50% - 30px)
来计算边距
h2 { text-align: center; font-size: 2.8rem; color: #444444; } .row { display: flex; flex-wrap: wrap; padding: 5%; } .row>div { padding: 5%; background: gray; margin: 15px; display: flex; flex-flow: column wrap; align-items: center; justify-content: center; text-align: center; flex: 0 calc(50% - 30px); box-sizing:border-box }
<div class="job-openings"> <h2>Seems Interesting? Apply Now</h2> <div class="row"> <div id="back-end"> <h3>Back-end Developer</h3> <p> Our main goal is to build and maintain the online platform and...</p> </div> <div id="front-end"> <h3>Front-end Web Developer</h3> <p>Among our biggest priorities are interface design and user experience...</p> </div> <div id="graphics"> <h3>Graphics Designer</h3> <p> We believe in the power of design. Our designers are motivated, creative and...</p> </div> <div id="sales"> <h3>Sales & Marketing</h3> <p>Our Marketing team is focussed on driving growth and building a brand that customers love...</p> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.