首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >父元素的CSS继承?

父元素的CSS继承?
EN

Stack Overflow用户
提问于 2017-05-23 15:43:17
回答 4查看 105关注 0票数 0

看起来div的text-indent是0px (这是默认的body text-ident大小),但是为什么它继承了body元素呢?为什么不继承作为div父元素的P元素,将text-indent设置为32px?

代码语言:javascript
复制
p {
  text-indent: 32px;
}

div {
  text-indent: inherit;
}
代码语言:javascript
复制
<p>In my younger, he told me, ,
  <div>'just remember that all the people in this world haven't had the advantages thatyou've had.'</div>
</p>

EN

回答 4

Stack Overflow用户

发布于 2017-05-23 15:45:25

文本缩进属性指定文本块中第一行的缩进,而不是所有行。

阅读更多信息:https://www.w3schools.com/cssref/pr_text_text-indent.asp

从语法上讲,p中的在所有HTML标准中都是无效的。

阅读更多信息:Nesting block level elements inside the tag... right or wrong?

您可以使用span而不是div

这样的 :

代码语言:javascript
复制
p {
  margin-left: 32px;
}
代码语言:javascript
复制
<p>In my younger, he told me,<br><br>
  <span>'just remember that all the people in this world haven't had the advantages thatyou've had.'</span>
</p>

如果您想使用缩进坚持,请使用margin-left表示div

代码语言:javascript
复制
p {
  text-indent: 32px;
}

div {
  margin-left: 32px;
}
代码语言:javascript
复制
<p>In my younger, he told me,
  <div>'just remember that all the people in this world haven't had the advantages thatyou've had.'</div>
</p>

票数 1
EN

Stack Overflow用户

发布于 2017-05-23 15:49:35

您不能将"div“标记插入到在html中无效的"p”标记内。但是你可以在"div“标签中插入"p”标签。如果希望子元素继承"p“元素属性,只需将"div”更改为"p“即可。

票数 1
EN

Stack Overflow用户

发布于 2017-05-23 15:54:24

使用<span>而不是<div>

不能在<p>中插入在html中无效的<div>标记。

代码语言:javascript
复制
<p>In my younger, he told me, ,
  <span>'just remember that all the people in this world haven't had the advantages that you've had.'</span>
</p>

希望这能对你有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44128700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档