html - 给div添加css背景

标签 html css

我有以下文档结构,

<div style="background:#000000;">
    <input type="button" style="float:right" value="click here"/>
    <input type="button" style="float:right" value="click here"/>
</div>

但不要给我我想要的结果。我希望背景在 div 主体上重复,如图所示

enter image description here

非常感谢任何帮助

最佳答案

首先,您缺少一个 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/

相关文章:

html - 如何使用 HTML 或 jQuery 代码禁用 INPUT 上的 Chrome 拼写检查?

php - 将数据从sql加载到html中的列表

jquery - 实现e.pageX和e.pageY时html属性 "id"和 "class"有什么区别

html - CSS删除线与文本不同的颜色?

javascript - 如何使用 jquery 1.11 及更高版本制作 “See all category” 链接按钮以显示其余文本

html - 如何首先放置 ionic 标签?

css - 如何将我的文本和按钮对齐到 CSS 中的中心?

jQuery 菜单中的 jQuery 问题绑定(bind)函数

css - css 下拉菜单的 z-index 问题

javascript - 在 JavaScript 中使用 RegEx 解析 CSS 字符串