html - 我怎样才能改变一个位置
元素?
问题描述
我刚开始从事网络开发,我的第一个项目是一个简历网站。我试图用 hr 元素将教育和体验部分分开。它工作正常,然后我使用 CSS 中的 float 属性将教育描述对齐到左侧,将相应的日期对齐到右侧。现在,在教育部分之后的那条线是在错误的区域。这是一些代码:
<section>
<h2>EDUCATION</h2>
<p id='e1'><strong>M.A. in Teaching</strong>, University of North Carolina</p>
<p id='e2'><strong>June 2021 - May 2022</strong></p>
<p id='e1'><strong>B.A., Human Development & Family Studies major & Education minor</strong>, University of North Carolina</p>
</section>
<hr>
<section>
<h2>EXPERIENCE</h2>
id e1 只是向左浮动,而 id e2 向右浮动。如何让 hr 元素实际出现在两个部分之间,而不是教育部分的中间?
解决方案
id
应该是唯一的,因此#e1
从第三个p
元素更改为您的选择,但不同。- 用于清除
clear:left
左侧的浮动属性hr
- 您还可以使用 cleafix hack 来
<hr>
添加clearfix
类<hr>
并添加此 CSS
.clearfix::after {
content: "";
clear: both;
display: table;
}
- 您还可以使用
border-right
我在代码中指定的添加垂直规则
* {
box-sizing: border-box/*So that padding used below don't effect width*/
}
hr {
clear: left
}
#e1 {
float: left;
width: 33%; /*Width so that content is divided in 3colums*/
height: 100px;
/*Height specified so that border become equal for all others and act as a vertical rule*/
border-right: 2px solid red;
padding: 5px;
}
#e2 {
float: right;
width: 33%;
height: 100px;
padding: 5px;
}
#e3 {
float: left;
width: 33%;
height: 100px;
border-right: 2px solid red;
padding: 5px;
}
<section>
<h2>EDUCATION</h2>
<p id='e1'><strong>M.A. in Teaching</strong>, University of North Carolina</p>
<p id='e2'><strong>June 2021 - May 2022</strong></p>
<p id='e3'><strong>B.A., Human Development & Family Studies major & Education minor</strong>, University of North Carolina</p>
</section>
<hr>
<section class="hed2">
<h2>EXPERIENCE</h2>
推荐阅读
- python - 如何在不重新训练的情况下简单地加载 ML 模型?
- api - 如何在没有状态管理的情况下访问 Flutter 应用中的 50 多个 api?
- android - 滚动期间调用 MPAndroidChart 图表值选定的侦听器
- java - Android UDP 打孔
- javascript - DiscordJS 获取角色的 ID
- javascript - 无法呈现身份验证页面
- javascript - 第二个for循环条件语句不起作用
- javascript - 使用原生 javascript 连接到 MongoDB 数据库
- r - R: Vars - 用于循环/函数/应用的列列表
- perl - Perl Time::Piece 如果不是格式,则使用当前日期