Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.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
Html 如何使div成为另一div的子div?_Html_Css - Fatal编程技术网

Html 如何使div成为另一div的子div?

Html 如何使div成为另一div的子div?,html,css,Html,Css,我想把三个div按如下顺序排列:输入,中断,输出。它们的父div是容器。我在为这些div应用框大小时面临问题,以下是我的css: html { border: groove 8px red; margin: 20px; } .container { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; width: 100%;

我想把三个div按如下顺序排列:
输入
中断
输出
。它们的父div是
容器
。我在为这些div应用框大小时面临问题,以下是我的css:

html {
    border: groove 8px red;
    margin: 20px;
}

.container {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    width: 100%;
    height:75%;
}

.container .input {
    width: 49%;
    height: 100%;
    border: solid 2px red;
    float: left;    
}

.container .break {
    width: 2%;
    height: 100%;
    background: blue;
    float: left;
}

.container .output {
    width: 49%;
    height: 100%;
    border: solid 2px green;
    float: right;
}

输出div是否低于输入和中断div?这是因为你的边界像素被添加到你的宽度上

49%+2%+49%+8px边界(输入每侧2个,输出每侧2个以上)>100%


你必须尝试不同的方法才能让它起作用,但是降低到48%甚至45%可能会起作用。因为你的区域已经向左和向右浮动,额外的空间就在中间了。

你的输出div是否低于你的输入和中断div?这是因为你的边界像素被添加到你的宽度上

49%+2%+49%+8px边界(输入每侧2个,输出每侧2个以上)>100%


你必须尝试不同的方法才能让它起作用,但是降低到48%甚至45%可能会起作用。因为你的区域已经向左和向右浮动,额外的空间就在中间。

< P>这个简单的三列布局

HTML

 <div class="header">header</div>
  <div class="layout">
   <div class="col1">column 1</div>
   <div class="col2">column 2</div>
   <div class="col3">clolumn 3</div>
  </div>
  <div class="footer">footer</div>
<div class="container">
    <div class="input">

    </div>
    <div class="break">

    </div>
    <div class="output">

    </div>
</div>

这是一个简单的三列布局

HTML

 <div class="header">header</div>
  <div class="layout">
   <div class="col1">column 1</div>
   <div class="col2">column 2</div>
   <div class="col3">clolumn 3</div>
  </div>
  <div class="footer">footer</div>
<div class="container">
    <div class="input">

    </div>
    <div class="break">

    </div>
    <div class="output">

    </div>
</div>

您还必须对子项应用
框大小调整

.container > * {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
     box-sizing: border-box;
}

您还必须对子项应用
框大小调整

.container > * {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
     box-sizing: border-box;
}
试试这个(对_s的赞美)。当你给它一个基于%的宽度,然后给它一个基于px的边框时,默认情况是把它们加在一起,这应该可以解决这个问题

*,
*:before,
*:after { /* apply a natural box layout model to all elements; see http://www.paulirish.com/2012/box-sizing-border-box-ftw/ */
-webkit-box-sizing: border-box; /* Not needed for modern webkit but still used by Blackberry Browser 7.0; see http://caniuse.com/#search=box-sizing */
-moz-box-sizing:    border-box; /* Still needed for Firefox 28; see http://caniuse.com/#search=box-sizing */
box-sizing:         border-box;
}
试试这个(对_s的赞美)。当你给它一个基于%的宽度,然后给它一个基于px的边框时,默认情况是把它们加在一起,这应该可以解决这个问题

*,
*:before,
*:after { /* apply a natural box layout model to all elements; see http://www.paulirish.com/2012/box-sizing-border-box-ftw/ */
-webkit-box-sizing: border-box; /* Not needed for modern webkit but still used by Blackberry Browser 7.0; see http://caniuse.com/#search=box-sizing */
-moz-box-sizing:    border-box; /* Still needed for Firefox 28; see http://caniuse.com/#search=box-sizing */
box-sizing:         border-box;
}

CSS的边框框属性不考虑边距。您需要将边距设置为0,并相应地调整填充,但如果使用边框,这可能是不需要的。您可以尝试使用百分比作为边距,使它们(宽度加边距)加起来等于100%。还要确保子div继承了长方体大小;您可能需要具体定义它。我通常在CSS中设置:

* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

最后,去掉它。break div。改用边距。

CSS的边框框属性不考虑边距。您需要将边距设置为0,并相应地调整填充,但如果使用边框,这可能是不需要的。您可以尝试使用百分比作为边距,使它们(宽度加边距)加起来等于100%。还要确保子div继承了长方体大小;您可能需要具体定义它。我通常在CSS中设置:

* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}
最后,去掉它。断开div。改用边距。

HTML

 <div class="header">header</div>
  <div class="layout">
   <div class="col1">column 1</div>
   <div class="col2">column 2</div>
   <div class="col3">clolumn 3</div>
  </div>
  <div class="footer">footer</div>
<div class="container">
    <div class="input">

    </div>
    <div class="break">

    </div>
    <div class="output">

    </div>
</div>

HTML

 <div class="header">header</div>
  <div class="layout">
   <div class="col1">column 1</div>
   <div class="col2">column 2</div>
   <div class="col3">clolumn 3</div>
  </div>
  <div class="footer">footer</div>
<div class="container">
    <div class="input">

    </div>
    <div class="break">

    </div>
    <div class="output">

    </div>
</div>

你需要一个三列布局?请创建一个fiddle你希望输出看起来像什么你需要一个三列布局?请创建一个fiddle你希望输出看起来像什么当然,但是这个问题可以通过应用框大小来解决,我应用了它,但问题仍然显示出来这就是他/她使用框大小的原因当然,但是这个问题可以通过应用盒子大小来解决,我应用了它,但问题仍然存在,这就是他/她使用盒子大小的原因