Html 希望宽度为padding+;仅文本本身
Html 希望宽度为padding+;仅文本本身,html,css,Html,Css,.start的宽度应该是=文本大小+填充,所以我使用了display inline block,但是我得到了类似这样的结果 问题演示 我想要实现的目标: 如果将元素的显示属性设置为内联块,则是: .start { display: inline-block; padding: 20px; color: white; background: blue; font-family: Arial; font-size: 16px; font-w
.start
的宽度应该是=文本大小+填充,所以我使用了display inline block,但是我得到了类似这样的结果
问题演示
我想要实现的目标:
如果将元素的
显示
属性设置为内联块
,则是:
.start {
display: inline-block;
padding: 20px;
color: white;
background: blue;
font-family: Arial;
font-size: 16px;
font-weight: 900;
}
根据编辑后的问题进行更新 考虑到新添加的HTML和视觉参考,我建议添加以下内容:
.racingbox,
.start {
/* forces the elements to a new line */
clear: both;
/* floats the elements, removing them from the 'normal'
document-flow, allowing the previous rule to apply */
float: left;
}
.非常欢迎您;如果你觉得答案是满意的,请考虑接受答案;你没有义务接受答案(当然也要给它一些时间等待可能更好的答案)。我很抱歉,我在代码中尝试了你的建议,但我遇到了一个错误。你能再核对一下这个问题吗?我做了一个编辑,把问题放到一边。解释一下“错误”是什么。如果我们不知道为什么错的话,告诉我们你得到了什么是没有用的。非常感谢你,先生。正是我想要的。我选择了这个答案。
.racingbox,
.start {
/* forces the elements to a new line */
clear: both;
/* floats the elements, removing them from the 'normal'
document-flow, allowing the previous rule to apply */
float: left;
}