【发布时间】:2018-01-02 23:50:45
【问题描述】:
我在其父级中绝对有一个块位置。父母有一个左右边框。这会导致绝对定位的块(也有边框)太小了2px。
解决此问题的最佳方法是什么?
目标:
我基本上希望这两个块对齐。它们的边界基本上应该看起来像 1 个边界。问题是即使使用border-box,子 div 也更小,因此无法对齐。
html
<div class="container">
<div class="diagonal"></div>
</div>
css
* {
box-sizing: border-box;
}
body {
background-color:red;
}
.container {
width:1170px;
margin:0 auto;
margin-top:200px;
height:700px;
position:relative;
z-index:3;
background-color:white;
border-style:solid;
border-color:transparent #D2D8DE #D2D8DE #D2D8DE;
border-width:0 1px 1px 1px;
}
.diagonal {
width:100%;
height:400px;
transform:skewY(-10deg);
position:absolute;
top:-200px;
left:0;
background-color:white;
border-style:solid;
border-color:transparent #D2D8DE;
border-width:0 1px;
z-index:-1;
}
【问题讨论】:
标签: html css width css-position