Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何在同一行中获得输入-strong和p元素?_Css_Css Float - Fatal编程技术网

Css 如何在同一行中获得输入-strong和p元素?

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向左浮

我有以下html内容

      <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;
}