使用 CSS 显示 DIV:
div.divBg {
background-color : red;
width : 200px;
height : 300px;
}
这显示了 CSS 中设置的内容:
<div class = "divBg">
</div>
在 DIV 本身中写入相同的设置是行不通的:
<div background-color ="red" width = "200px" height = "300px">
</div>
请告诉我我错过了什么
最佳答案
您应该在 style
属性中包含您的 CSS 规则:
<div style="background-color: red; width: 200px; height: 200px;"></div>
关于html - 在 CSS 中或直接编写元素属性有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39631225/