为什么这两个元素会重叠? CSS 问题
Why are these two elements overlapping? CSS issue
很难弄清楚为什么这两个 html 元素重叠。下面是各个元素的 HTML 和 CSS 文件。我在这里搜索了很多线程,但 none 的解决方案有效。谢谢!
main.css:
#titlesection {
height: auto;
width: 100%;
margin: auto;
padding: 0px;
margin-top: 25px;
margin-bottom: 25px;
position: absolute;
display: block;
}
#contentdiv {
top: 30%;
left: 2%;
width: 97%;
margin: auto;
height: 100%;
position: absolute;
display: block;
}
#title {
padding-top: 50px;
text-align: center;
font-size: 60px;
letter-spacing: 6px;
display: block;
margin-bottom: 1%;
height: auto;
}
#titlesubheading {
margin-top: 10px;
margin-bottom: 10px;
font-size: 30px;
text-align: center;
letter-spacing: 7px;
display: block;
height: auto;
}
#socialmedia {
width: 97%;
display: block;
}
#smtable {
width: 10%;
float: right;
}
#aboutheader {
width: 95%;
margin: auto;
margin-top: 5%;
padding: 10px;
font-size: 30px;
display: block;
position: static;
}
#about {
width: 95%;
margin: auto;
margin-top: 1%;
padding: 0px;
height: auto;
font-size: 20px;
display: block;
}
#abouttext {
width: 60%;
height: auto;
display: block;
margin-left: 10px;
min-height: 140px;
}
index.html :
<body>
<section id="titlesection">
<div id="title">
Abdullah Rehmat
</div>
<div id="titlesubheading">
Freelance Developer
</div>
<div id="socialmedia">
<table id="smtable">
<tbody>
<tr>
<td class="a">
<a href="mailto: rehmat.dev@gmail.com">
<img
src="{{url_for('static', filename='images/email.png')}}"
width="33"
height="33"
/>
</a>
</td>
<td class="a">
<a href="https://twitter.com/ARehmat20" target="_blank">
<img
src="{{url_for('static', filename='images/twitter0.svg')}}"
width="50"
height="50"
/>
</a>
</td>
<td class="a">
<a href="https://github.com/10CodeDev" target="_blank">
<img
src="{{url_for('static', filename='images/github.png')}}"
width="30"
height="30"
/>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<div id="contentdiv">
<div id="aboutheader">
About:
</div>
这是问题的图片。 aboutheader 与 titlesubheading 重叠:
这是因为您将这两个元素都设为 position: absolute;
。您可以通过删除来修复它。将您的 CSS 更新为:
编辑:同样供您参考,position 允许您在特定上下文中重新定位元素。 position: absolute;
从页面左上角定位一个元素,或者如果其父元素有 position: relative;
则从该元素定位。 position: relative;
将某物从其初始位置重新定位。
然后您可以使用 top
、left
、right
或 bottom
来选择如何重新定位项目。
#titlesection {
height: auto;
width: 100%;
margin: auto;
padding: 0px;
margin-top: 25px;
margin-bottom: 25px;
position: relative;
display: block;
}
#contentdiv {
top: 0;
left: 0;
width: 97%;
margin: auto;
height: 100%;
position: relative;
display: block;
}
#title {
padding-top: 50px;
text-align: center;
font-size: 60px;
letter-spacing: 6px;
display: block;
margin-bottom: 1%;
height: auto;
}
#titlesubheading {
margin-top: 10px;
margin-bottom: 10px;
font-size: 30px;
text-align: center;
letter-spacing: 7px;
display: block;
height: auto;
}
#socialmedia {
width: 97%;
display: block;
}
#smtable {
width: 10%;
float: right;
}
#aboutheader {
width: 95%;
margin: auto;
margin-top: 5%;
padding: 10px;
font-size: 30px;
display: block;
position: static;
}
#about {
width: 95%;
margin: auto;
margin-top: 1%;
padding: 0px;
height: auto;
font-size: 20px;
display: block;
}
#abouttext {
width: 60%;
height: auto;
display: block;
margin-left: 10px;
min-height: 140px;
}
ou can use the CSS position property in combination with the
z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for
positioned elements
很难弄清楚为什么这两个 html 元素重叠。下面是各个元素的 HTML 和 CSS 文件。我在这里搜索了很多线程,但 none 的解决方案有效。谢谢!
main.css:
#titlesection {
height: auto;
width: 100%;
margin: auto;
padding: 0px;
margin-top: 25px;
margin-bottom: 25px;
position: absolute;
display: block;
}
#contentdiv {
top: 30%;
left: 2%;
width: 97%;
margin: auto;
height: 100%;
position: absolute;
display: block;
}
#title {
padding-top: 50px;
text-align: center;
font-size: 60px;
letter-spacing: 6px;
display: block;
margin-bottom: 1%;
height: auto;
}
#titlesubheading {
margin-top: 10px;
margin-bottom: 10px;
font-size: 30px;
text-align: center;
letter-spacing: 7px;
display: block;
height: auto;
}
#socialmedia {
width: 97%;
display: block;
}
#smtable {
width: 10%;
float: right;
}
#aboutheader {
width: 95%;
margin: auto;
margin-top: 5%;
padding: 10px;
font-size: 30px;
display: block;
position: static;
}
#about {
width: 95%;
margin: auto;
margin-top: 1%;
padding: 0px;
height: auto;
font-size: 20px;
display: block;
}
#abouttext {
width: 60%;
height: auto;
display: block;
margin-left: 10px;
min-height: 140px;
}
index.html :
<body>
<section id="titlesection">
<div id="title">
Abdullah Rehmat
</div>
<div id="titlesubheading">
Freelance Developer
</div>
<div id="socialmedia">
<table id="smtable">
<tbody>
<tr>
<td class="a">
<a href="mailto: rehmat.dev@gmail.com">
<img
src="{{url_for('static', filename='images/email.png')}}"
width="33"
height="33"
/>
</a>
</td>
<td class="a">
<a href="https://twitter.com/ARehmat20" target="_blank">
<img
src="{{url_for('static', filename='images/twitter0.svg')}}"
width="50"
height="50"
/>
</a>
</td>
<td class="a">
<a href="https://github.com/10CodeDev" target="_blank">
<img
src="{{url_for('static', filename='images/github.png')}}"
width="30"
height="30"
/>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<div id="contentdiv">
<div id="aboutheader">
About:
</div>
这是问题的图片。 aboutheader 与 titlesubheading 重叠:
这是因为您将这两个元素都设为 position: absolute;
。您可以通过删除来修复它。将您的 CSS 更新为:
编辑:同样供您参考,position 允许您在特定上下文中重新定位元素。 position: absolute;
从页面左上角定位一个元素,或者如果其父元素有 position: relative;
则从该元素定位。 position: relative;
将某物从其初始位置重新定位。
然后您可以使用 top
、left
、right
或 bottom
来选择如何重新定位项目。
#titlesection {
height: auto;
width: 100%;
margin: auto;
padding: 0px;
margin-top: 25px;
margin-bottom: 25px;
position: relative;
display: block;
}
#contentdiv {
top: 0;
left: 0;
width: 97%;
margin: auto;
height: 100%;
position: relative;
display: block;
}
#title {
padding-top: 50px;
text-align: center;
font-size: 60px;
letter-spacing: 6px;
display: block;
margin-bottom: 1%;
height: auto;
}
#titlesubheading {
margin-top: 10px;
margin-bottom: 10px;
font-size: 30px;
text-align: center;
letter-spacing: 7px;
display: block;
height: auto;
}
#socialmedia {
width: 97%;
display: block;
}
#smtable {
width: 10%;
float: right;
}
#aboutheader {
width: 95%;
margin: auto;
margin-top: 5%;
padding: 10px;
font-size: 30px;
display: block;
position: static;
}
#about {
width: 95%;
margin: auto;
margin-top: 1%;
padding: 0px;
height: auto;
font-size: 20px;
display: block;
}
#abouttext {
width: 60%;
height: auto;
display: block;
margin-left: 10px;
min-height: 140px;
}
ou can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements