仅使用 html 设置 div 背景颜色
Set div background color with only html
是否可以在 css 上设置 div bg 颜色,只是纯粹的 html。
任何建议都会有所帮助...
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: white;
font-size: 14px;
font-weight: 100;
line-height: .2;
letter-spacing: 1px;
}
<div style="height:100px;" style="background-color:red;">text</div>
添加这个CSS
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: white;
font-size: 14px;
font-weight: 100;
line-height: .2;
letter-spacing: 1px;
}
.mydiv {
background:red;
padding:5px;
color:white;
}
在HTML
<div class="mydiv">text</div>
工作代码
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: white;
font-size: 14px;
font-weight: 100;
line-height: .2;
letter-spacing: 1px;
}
<div style="height:100px;background-color:red">text</div>
内联样式的语法错误。您指定了两次样式。
欢迎使用 Whosebug。我知道你是 SO 的新贡献者。
注意:
您正在使用两个样式属性到div标记它是无效..!!!
<div style="height:100px;" style="background-color:red;">text</div>
而不是使用(如果使用不同的 css 样式,由 ;
分隔,如下所示)
<div style="height:100px;background:red;">text</div>
在body
标签中使用bgColor="#6B6B6B"
来改变body 的背景颜色但是不能只用html 来改变Div 背景。
可以使用内联css,即
但是
The HTML bgcolor
attribute is used to set the background color of an HTML element. Bgcolor is one of those attributes that has become deprecated with the implementation of Cascading Style Sheets.
它支持像这样的标签
支持的标签:
支持的标签喜欢:
<body>
,<marquee>
, <table>
, <tbody>
,<td>
,<tfoot>
,<th>
,<thead>
,<tr>
使用 bgColor 的演示:
<body bgColor="#6B6B6B">
<div style="height:100px;background:red;">text</div>
</body>
不使用 bgColor 的演示:
<body style="background:#6B6B6B">
<div style="height:100px;background:red;">text</div>
</body>
注意:
您可以在 CSS
中使用 background
and background-color
属性 添加背景颜色
是否可以在 css 上设置 div bg 颜色,只是纯粹的 html。 任何建议都会有所帮助...
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: white;
font-size: 14px;
font-weight: 100;
line-height: .2;
letter-spacing: 1px;
}
<div style="height:100px;" style="background-color:red;">text</div>
添加这个CSS
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: white;
font-size: 14px;
font-weight: 100;
line-height: .2;
letter-spacing: 1px;
}
.mydiv {
background:red;
padding:5px;
color:white;
}
在HTML
<div class="mydiv">text</div>
工作代码
body {
background-color: #6B6B6B;
margin: 50px;
font-family: Arial;
color: white;
font-size: 14px;
font-weight: 100;
line-height: .2;
letter-spacing: 1px;
}
<div style="height:100px;background-color:red">text</div>
内联样式的语法错误。您指定了两次样式。
欢迎使用 Whosebug。我知道你是 SO 的新贡献者。
注意:
您正在使用两个样式属性到div标记它是无效..!!!
<div style="height:100px;" style="background-color:red;">text</div>
而不是使用(如果使用不同的 css 样式,由 ;
分隔,如下所示)
<div style="height:100px;background:red;">text</div>
在body
标签中使用bgColor="#6B6B6B"
来改变body 的背景颜色但是不能只用html 来改变Div 背景。
可以使用内联css,即
但是
The HTML
bgcolor
attribute is used to set the background color of an HTML element. Bgcolor is one of those attributes that has become deprecated with the implementation of Cascading Style Sheets.
它支持像这样的标签 支持的标签:
支持的标签喜欢:
<body>
,<marquee>
,<table>
,<tbody>
,<td>
,<tfoot>
,<th>
,<thead>
,<tr>
使用 bgColor 的演示:
<body bgColor="#6B6B6B">
<div style="height:100px;background:red;">text</div>
</body>
不使用 bgColor 的演示:
<body style="background:#6B6B6B">
<div style="height:100px;background:red;">text</div>
</body>
注意:
您可以在 CSS
中使用background
and background-color
属性 添加背景颜色