Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.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 CSS布局:一项与另一项重叠并到达容器的边界_Html_Css - Fatal编程技术网

Html CSS布局:一项与另一项重叠并到达容器的边界

Html CSS布局:一项与另一项重叠并到达容器的边界,html,css,Html,Css,我自己发现了我不明白这个: CSS .container { width: 50%; border: 1px solid #000; position: relative; } .container .small { width: 40%; background-color: tomato; position: absolute; left: 30px; height: 250px; top: 0; bottom: 0; margin: auto;

我自己发现了我不明白这个:

CSS

.container {
  width: 50%;
  border: 1px solid #000;
  position: relative;
}
.container .small {
  width: 40%;
  background-color: tomato;
  position: absolute;
  left: 30px;
  height: 250px;
  top: 0;
  bottom: 0;
  margin: auto;
}
.container .big {
  width: 60%;
  background-color: aquamarine;
  margin-left: auto;
}
.container > div {
  height: 300px;
}
HTML

<div class="container">
  <div class="small"></div>
  <div class="big"></div>
</div>

问题: 如何修改布局,使红色框到达容器的黑色边框,并且仍然与蓝色框重叠。

请注意:


蓝色框的内容可以在高度上有所不同,蓝色框的高度需要根据红色框的高度而有所不同(我可以使用JS处理这个问题)。但是如果有另外一种使用flexbox的方法,我会很高兴听到


浏览器支持是IE11+、FF36+、Chrome 36+、Android 4.2+、iOS 8+,因此您几乎可以使用任何您喜欢的CSS功能。

您是否尝试过将左侧属性设置为零并增加小div的宽度

.container .small {
    width: 45%;
    background-color: tomato;
    position: absolute;
    left: 0px;
    height: 250px;
    top: 0;
    bottom: 0;
    margin: auto;
}


根据您的描述和提供的代码,这具有所需的效果

是否尝试为left属性设置零并增加小div的宽度

.container .small {
    width: 45%;
    background-color: tomato;
    position: absolute;
    left: 0px;
    height: 250px;
    top: 0;
    bottom: 0;
    margin: auto;
}


根据您的描述和提供的代码,这具有所需的效果

除非我误解了,正如Opaw Nako在下面提到的,左值应该是0:

.container {
  width: 50%;
  border: 1px solid #000;
  position: relative;
  overflow:hidden; 

  .small {
    width: 45%;
    background-color: tomato;
    position: relative;
    left: 0px;
    height: 350px;
    top: 0;
    bottom: 0;
    margin: none;
  }

  .big { 
    width: 60%; 
    background-color: aquamarine; 
    margin-left: auto;
    position: absolute;
    top: 0px;
    right:0px;
    bottom:0px;
  }

  > div {

  }
}
将小框的位置设置为相对,将大框的位置设置为绝对(包含在相对框中),这也意味着.small box将设置.big将跟随的高度


以下是

,除非我误解了,正如Opaw Nako在下面提到的,左边的值应该是0:

.container {
  width: 50%;
  border: 1px solid #000;
  position: relative;
  overflow:hidden; 

  .small {
    width: 45%;
    background-color: tomato;
    position: relative;
    left: 0px;
    height: 350px;
    top: 0;
    bottom: 0;
    margin: none;
  }

  .big { 
    width: 60%; 
    background-color: aquamarine; 
    margin-left: auto;
    position: absolute;
    top: 0px;
    right:0px;
    bottom:0px;
  }

  > div {

  }
}
将小框的位置设置为相对,将大框的位置设置为绝对(包含在相对框中),这也意味着.small box将设置.big将跟随的高度


下面是CSS应该是这样的

.container {
width: 50%;
border: 1px solid #000;
position: relative;

.small {
width: 45%;
background-color: tomato;
position: absolute;
left: 0px;
height: 250px;
top: 0;
bottom: 0;
margin: auto;
}

.big {
width: 60%;
background-color: aquamarine;
margin-left: auto;
}

> div {
height: 300px;
}
}


    Edit: You are changing the left attribute for .small from 30px to 0px. 
    And increasing the small containers width from 40% to 45% to account 
    for proper overlap.

CSS应该是这样的

.container {
width: 50%;
border: 1px solid #000;
position: relative;

.small {
width: 45%;
background-color: tomato;
position: absolute;
left: 0px;
height: 250px;
top: 0;
bottom: 0;
margin: auto;
}

.big {
width: 60%;
background-color: aquamarine;
margin-left: auto;
}

> div {
height: 300px;
}
}


    Edit: You are changing the left attribute for .small from 30px to 0px. 
    And increasing the small containers width from 40% to 45% to account 
    for proper overlap.


我不确定我是否完全理解这个问题。我真的不明白,不是吗
。小的{left:0;}
?@sdcr红色框需要覆盖(重叠)蓝色框。@tribe84到底什么不清楚?它应该是什么样子,你的意思是到达左边界吗?我不确定我完全理解这个问题。我真的不明白,不是吗
。小的{left:0;}
?@sdcr红色框需要覆盖(重叠)蓝色框。@tribe84到底什么不清楚?它应该是什么样子,你的意思是到达左边框?这并不能解决可变高度问题,是吗?高度问题是什么?高度不应影响宽度。它仍将重叠。您是否试图在较小的视口中实现不同于此的效果?“蓝色框的内容可能会有不同的高度,蓝色框的高度需要根据红色框的高度而变化(我可以使用JS处理)。但是如果有其他方法使用flexbox,我会很高兴听到”我认为这个问题只是宽度的问题,因为有人说高度的问题是可以处理的。也许重新表述这个问题会澄清这一部分。正如上面所描述的,不同高度的行为对我来说也不是很清楚。当其中一个div的高度发生变化时,是否需要保持两个div之间的高度比?这并不能解决可变高度问题,是吗?高度问题是什么?高度不应影响宽度。它仍将重叠。您是否试图在较小的视口中实现不同于此的效果?“蓝色框的内容可能会有不同的高度,蓝色框的高度需要根据红色框的高度而变化(我可以使用JS处理)。但是如果有其他方法使用flexbox,我会很高兴听到”我认为这个问题只是宽度的问题,因为有人说高度的问题是可以处理的。也许重新表述这个问题会澄清这一部分。正如上面所描述的,不同高度的行为对我来说也不是很清楚。当其中一个div的高度发生变化时,两个div之间的高度比率是否需要保持?您能解释一下代码的作用吗?所以,它的存在不仅仅是为了回答问题,而是为了教育人们。你能解释一下你的代码是做什么的吗?所以,存在不仅仅是为了回答问题,而是为了教育人们。