html - 背景 div 不显示
问题描述
<!doctype html>
<html>
<style type="text/css">
body {
background-color: #444669;
}
#1 {
background-color: #DD2124;
height: 337px;
width: 388px;
}
</style>
<body>
<div id="1"></div>
</body>
</html>
我正在尝试制作具有不同背景颜色的 div 部分,但它甚至根本不显示。
解决方案
CSS 中的 ID 不能以数字开头。#1
例如,只需将 更改为 ,就可以了#first
。
预习:
https://jsfiddle.net/uLwn05q2/
<!doctype html>
<html>
<style type="text/css">
body {
background-color: #444669;
}
#first {
background-color: #DD2124;
height: 337px;
width: 388px;
}
</style>
<body>
<div id="first"></div>
</body>
</html>
更新:
您可以使用一个技巧将 id 实际保留为数字:
<style type="text/css">
body {
background-color: #444669;
}
[id='1'] {
background-color: #DD2124;
height: 337px;
width: 388px;
}
</style>
推荐阅读
- ios - 使用 ThemeData 作为 CupertinoApp 的主题
- c# - C# 中的委托是后期绑定机制吗?
- rest - URL 参数与发布表单数据
- javascript - 导航链接上的 Onclick 事件以触发汉堡包图标上的 css 动画
- mysql - 特拉维斯没有说明理由就失败了
- python - 禁用 PDF 查看器的代码不再起作用
- mysql - 在mysql中插入重复条目
- wxpython - 如何将样式线的背景颜色扩展到 wxWidget TextCtrl 或 StyledTextCtrl 中的整行?
- html - 将 div 向上翻译时,如何去除 div 下方的空格?
- java - 如何在 Youtube Player 中使用自定义字体?