Css 如何在同一行中获得输入-strong和p元素?
我有以下html内容Css 如何在同一行中获得输入-strong和p元素?,css,css-float,Css,Css Float,我有以下html内容 <div><input type="checkbox"><strong></strong><p></p></div> 关于这个css设置,我不理解的是p元素占据了div元素的整个宽度。例如,div宽度是1360,p元素也是1360,但强宽度是184,输入宽度是16,它们都适合在同一行上,p元素在水平线上溢出。float:overflow;不存在,它只能是左或右。您需要将p向左浮
<div><input type="checkbox"><strong></strong><p></p></div>
关于这个css设置,我不理解的是p元素占据了div元素的整个宽度。例如,div宽度是1360,p元素也是1360,但强宽度是184,输入宽度是16,它们都适合在同一行上,p元素在水平线上溢出。float:overflow;不存在,它只能是左或右。您需要将p向左浮动。浮动所有剩余的内容将使它们全部捕捉到同一条线上(只要定位是相对的,您也应该这样做)
在你给
一个浮点:左
,您必须给
一个溢出:隐藏代码>
如果你想把
降低一点,那就给它一个页边距顶部
看看这个
CSS
div
{
overflow:hidden;
}
input
{
float: left;
margin: 0;
padding: 0;
}
strong
{
float: left;
margin: 0;
padding: 0;
}
p
{
margin: 0;
padding: 0;
float:left;
white-space: nowrap;
}
之所以
采用全宽,是因为的display
属性是block
,就像
一样,除非浮动它,否则它将采用全宽。始终使用display:inline将元素放在一行上:
HTML:
<div>
<input type="checkbox" />
<strong>Hello</strong>
<p>World</p>
</div>
input{
float: overflow;
margin: 0;
padding: 0;
}
strong
{
float: overflow;
margin: 0;
padding: 0;
}
p
{
display:inline;
margin: 0;
padding: 0;
white-space: nowrap;
}
您忘记将html内容添加到问题中。在将溢出值固定为左值并将html内容向右推4个空格后,问题仍然存在。
<div>
<input type="checkbox" />
<strong>Hello</strong>
<p>World</p>
</div>
input{
float: overflow;
margin: 0;
padding: 0;
}
strong
{
float: overflow;
margin: 0;
padding: 0;
}
p
{
display:inline;
margin: 0;
padding: 0;
white-space: nowrap;
}