2016-12-26 88 views
0

我有三个子div,并希望中间div忽略父div的宽度,并采取全屏宽度(但它需要保持其位置低于第一格)我怎么能有第二个div行忽略父div的宽度

+0

如果你有一些代码,这是比较容易帮助。 –

+0

得到它解决看到[jsfiddle](https://jsfiddle.net/sachingpta/3qu3m466/),谢谢。 – SACn

+0

@SachinGupta你最好删除那个问题。山姆是对的,你的问题太模糊了:有很多方法可以解决问题,但其中大多数不符合你的真实(不成文)要求 –

回答

0

使用position: absolute标签解决了这个问题。见JSfiddle:https://jsfiddle.net/sachingpta/3qu3m466/。示例代码

`

html,body{ 
    height: 100%; 
    padding: 0px; 
    margin: 0px; 
} 
.parent{ 
    width: 300px; 
    height: 100%; 
    background-color: grey;  
    margin: 0 auto; 
} 
.child1{ 
    background-color: red; 
} 
.child2{ 
    background-color: green; 
    position: absolute; 
    left: 0px; 
    right: 0px; 
} 
.child3{ 
    background-color: blue; 
} 

`

0

您可以定义中间的孩子宽度在vw定义的宽度:

.parent { 
 
    width: 100px; 
 
    height: 40px; 
 
    background: blue; 
 
} 
 
.child { 
 
    width: 100%; 
 
    background: yellow; 
 
} 
 
.overflower { 
 
    width: 100vw; 
 
    background: red; 
 
}
<div class=parent> 
 
    <div class=child>child</div> 
 
    <div class=overflower>overflows</div> 
 
    <div class=child>child</div> 
 
</div>

相关问题