我有一个fiddle,其中有一些文字和矩形有一些垂直放置的文字。
I am wondering how I can put a text and a rectangle (having some text) align in the same line and also at the center of a page,
类似this的内容,其中文本和框(包含一些文本)在页面中心的同一行中对齐。
我尝试在某些课程中使用float: left, float: right, display: inline-block and display: block
但不幸的是它没有用。
每个职位空缺课程的HTML代码是:
<div class="job-opening1">
<p class="section1">Development & Design</p>
<div class="rectangle">
<p class="job-title">Web Designer</p>
<p class="job-description">Qualifications Go here</p>
</div>
</div>
答案 0 :(得分:0)
我会使用Flexbox,就像这样:
<div class="job-opening1" style="display:flex;">
<p class="section1">Development & Design</p>
<div class="rectangle">
<p class="job-title">Web Designer</p>
<p class="job-description">Qualifications Go here</p>
</div>
</div>
它需要一些造型,但我认为它符合您的要求。 Flexbox非常易于使用,如果您需要,可以查看本教程https://medium.freecodecamp.org/flexbox-in-10-minutes-7295497804ed
编辑: 我认为这更准确,我从小提琴中复制了样式设置并放置了一些间距:
<div class="job-opening1" style="display:flex;">
<p class="section1" style="flex-grow:1">Development & Design</p>
<div class="rectangle" style="flex-grow:1;
border-radius: 10px;
display: inline-block;
margin-bottom: 30px;
margin-right: 5px;
width: 350px;
height: 100px;
border: 1px solid #000;
background-color: white;
padding: 10px 10px 10px 100px;
position: relative;">
<p class="job-title">Web Designer</p>
<p class="job-description">Qualifications Go here</p>
</div>
答案 1 :(得分:0)
一种选择是对所有float:right
使用.rectangle
,为clear:both
使用.openings div
,如下所示:
/**** Openings Start *****/
.openings .headline-text:before {
border-top: 1px solid #1072B8;
display: block;
position: relative;
top: -25px;
margin: 0 auto;
width: 50%;
content: "";
}
.openings .headline-text {
text-align: center;
font-size: 24px;
color: #1072B8;
padding-top: 60px;
font-weight: bold;
}
.openings .rectangle {
border-radius: 10px;
display: inline-block;
margin-bottom: 30px;
margin-right: 5px;
width: 250px;
height: 100px;
border: 1px solid #000;
background-color: white;
padding: 10px 10px 10px 100px;
position: relative;
float: right;
}
.section{
float:left;
}
.openings .job-opening{
clear:both;
}
/**** Openings Finish *****/
&#13;
<div class="openings">
<p class="headline-text">Departments</p>
<div class="job-opening">
<p class="section">Development & Design</p>
<div class="rectangle">
<p class="job-title">Web Designer</p>
<p class="job-description">Qualifications Go here</p>
</div>
</div>
<div class="job-opening">
<p class="section">Full Stack Developer</p>
<div class="rectangle">
<p class="job-title">Full Stack Developer</p>
<p class="job-description">Qualifications Go here</p>
</div>
</div>
<div class="job-opening">
<p class="section">Marketing Director</p>
<div class="rectangle">
<p class="job-title">Marketing Director</p>
<p class="job-description">Qualifications Go here</p>
</div>
</div>
<div class="job-opening">
<p class="section">Marketing Analyst</p>
<div class="rectangle">
<p class="job-title">Marketing Analyst</p>
<p class="job-description">Qualifications Go here</p>
</div>
</div>
</div>
&#13;
答案 2 :(得分:0)
在包含文本的元素上,只需添加float css规则,以便下面的元素将浮动在使用浮动规则的元素集的一侧
.section1{
float:left;
}