我有以下文档结构,
<div style="background:#000000;">
<input type="button" style="float:right" value="click here"/>
<input type="button" style="float:right" value="click here"/>
</div>
但不要给我我想要的结果。我希望背景在 div 主体上重复,如图所示
非常感谢任何帮助
最佳答案
首先,您缺少一个 0。#00000
不是有效的十六进制颜色代码。十六进制颜色代码必须包含 3 个或 6 个十六进制数字。要解决此问题,只需添加一个 0(或删除两个 0):
<div style="background:#000000;">
...
</div>
来自CSS Color Module specification :
The format of an RGB value in hexadecimal notation is a ‘#’ immediately followed by either three or six hexadecimal characters. The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00. This ensures that white (#ffffff) can be specified with the short notation (#fff) and removes any dependencies on the color depth of the display.
其次,当 float 元素之后您需要清除它们,因为 float 会将它们带出页面的上下文。这个可以引用What methods of ‘clearfix’ can I use? .
关于html - 给div添加css背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19220935/