如何为元素或 div 的内容设置样式?
我知道您可以使用 ELEMENT * {...} 为 ELEMENT 中的每个单独项目设置样式,但我想将内容作为一个整体进行样式设置。我还知道您可以使用 ELEMENT #DIVID {...} 但我不想在我的代码中包含另一个 DIV。
如果您在想为什么我不直接设置整个 ELEMENT {}
的样式,那是因为当我使用填充时,我不希望我的 ELEMENT
根据大小进行更改在填充物上。
这就是我现在所拥有的;
CSS 代码:
article {
background: #fff;
width: 900px;
margin: 0 auto;
border: 1px solid #e0e0dc;
-webkit-box-shadow: 0px 0px 10px #e0e0dc;
-moz-box-shadow: 0px 0px 10px #e0e0dc;
box-shadow: 0px 0px 10px #e0e0dc;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
overflow: auto;
}
article #content {
padding: 25px;
}
HTML 代码:
<article>
<div id="content">
<h2>Test Title</h2>
<p>Blah Blah Blah</p>
<p>Blah Blah Blah</p>
<p>Blah Blah Blah</p>
<a href="http://google.com">Google</a>
</div>
</article>
我不想有内容 DIV。
I know you can use ELEMENT * {...}
to set a style for each individual item in ELEMENT, but I want to style the contents as a whole. I also know that you can use ELEMENT #DIVID {...}
however I don't want to include another DIV in my code.
If you you are thinking why don't I just style the entire ELEMENT {}
, it is because when I use padding, I do not want my ELEMENT
to change size based on the padding.
This is what I have at the moment;
CSS Code:
article {
background: #fff;
width: 900px;
margin: 0 auto;
border: 1px solid #e0e0dc;
-webkit-box-shadow: 0px 0px 10px #e0e0dc;
-moz-box-shadow: 0px 0px 10px #e0e0dc;
box-shadow: 0px 0px 10px #e0e0dc;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
overflow: auto;
}
article #content {
padding: 25px;
}
HTML Code:
<article>
<div id="content">
<h2>Test Title</h2>
<p>Blah Blah Blah</p>
<p>Blah Blah Blah</p>
<p>Blah Blah Blah</p>
<a href="http://google.com">Google</a>
</div>
</article>
I do not want to have the content DIV.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以对 ELEMENT 内的每种类型的 ELEMENT 执行此操作:
You can do this for each type of ELEMENT within ELEMENT: