我正在尝试格式化DIV中的文本,但是,我也希望为DIV设置样式。
在PHP页面中,我有DIV和文本:
<div id="main-content">
<h1>Welcome to the Drug Debate!</h1>
<p>Home of facts and deabtes of legal and illegal drugs!The Drug debate offers a safe and relaxed enviroment where you will be able to find information and facts about different types of drug </p>
</div>
然后在我的CSS中,我试图使用以下方式设置DIV的样式:
#main-content{
background-color: #FFFFFF;
width:600px;
height: 350px;
margin: 0 auto;
border:solid;
}
以及<h1>
和<p>
使用:
h1 {
font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-size:24px;
padding-left:200px;
}
(和<p>
类似)
这会产生问题,例如DIV的背景颜色不适用于文本背后?
(请记住,我对编码和这个网站很新!)
答案 0 :(得分:0)
default background color property is transparent,这就是您看到通用选择器背景颜色的原因。只需将background-color:inherit;
添加到CSS中即可。
h1, p {
font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-size:24px;
padding-left:200px;
background-color:inherit;
}
<强> jsFiddle example 强>