首页 > 解决方案 > CSS 不工作任何人都可以调试我的代码吗?

问题描述

好的,这就是我的问题:我有一个父母 divh2一个,当我从我的 cssp中删除包装时,我的 css 工作正常,但是一旦我再次添加我的元素就停止工作divh2pdivTop:;p

这是我的代码:

#p3 {
  position: relative;
  top: 5%;
  left: 5%;
  font-weight: 500;
  font-size: 15px;
  max-width: 39%;
}
<div>
  <h2 id="identities">Identities</h2>
  <p id="p3">One may identify as non-binary on its own or they may identify as a gender that falls in the category of non-binary.<br><br> Any gender that is not strictly and completely male or strictly and completely female falls under the category of non-binary.<br><br>    Some common non-binary identities include:
  </p>
</div>

这是没有div父母的情况:

正常显示的东西

这就是我添加div父级时发生的情况:

换东西

标签: htmlcss

解决方案


我认为您需要p3更好地定位元素。试试这段代码

css

div > #p3 {
  position: relative;
  top: 5%;
  left: 5%;
  font-weight: 500;
  font-size: 15px;
  max-width: 39%;
}

html

<div>
  <h2 id="identities">Identities</h2>
  <p id="p3">One may identify as non-binary on its own or they may identify as a gender that falls in the category of non-binary.<br><br> Any gender that is not strictly and completely male or strictly and completely female falls under the category of non-binary.<br><br>    Some common non-binary identities include:
  </p>
</div>

推荐阅读