我正在尝试使用此示例:http://dabblet.com/gist/3401493表示将其用于边框:
.tophalf:after {
content: " ";
display:block;
position: relative;
width: 240px;
bottom:-30px;
height:30px;
outline:1px solid red;
background: linear-gradient(-45deg, transparent 75%, white 75%) 0 50%,
linear-gradient( 45deg, transparent 75%, white 75%) 0 50%;
background-repeat: repeat-x;
background-size:30px 30px, 30px 30px;
}
但是,我的上半部分的百分比高度为50%,因此边框不会转到div的底部。我该如何解决这个问题?
三江源
答案 0 :(得分:2)
你想要做的是以绝对方式应用之字形边框,以便它会粘在底部。
我设置了一个示例:http://jsfiddle.net/rym6p/2/
html:
<div class="container">
<div class="tophalf">
</div>
</div>
css:
body{background:green;}
.container{height:480px;}
.tophalf{background:blue; height:50%; width:240px; position:relative;}
.tophalf:after {
content: " ";
display: block;
position: absolute;
width: 240px;
bottom: 0;
height: 30px;
outline: 1px solid red;
background: -webkit-linear-gradient(135deg, transparent 75%, white 75%) 0 50%, -webkit-linear-gradient(45deg, transparent 75%, white 75%) 0 50%;
background-repeat: repeat-x;
background-size: 30px 30px, 30px 30px;
}
答案 1 :(得分:0)
非常喜欢这个问题和答案。
然而,它只处理面向下的曲折。
我在这里添加SCSS解决方案,用于上/右/左/右方向。
希望这对其他人有用。
@mixin zigzag_downward( $color ){
background: linear-gradient( 45deg, transparent 75%, $color 75%) 0 50%,
linear-gradient(-45deg, transparent 75%, $color 75%) 0 50%;
background-repeat: repeat-x;
background-size:30px 30px, 30px 30px;
}
@mixin zigzag_upward( $color ){
background: linear-gradient( 45deg, $color 25%, transparent 25%) 0 50%,
linear-gradient(-45deg, $color 25%, transparent 25%) 0 50%;
background-repeat: repeat-x;
background-size:30px 30px, 30px 30px;
}
@mixin zigzag_left( $color ){
background: linear-gradient( 45deg, transparent 75%, $color 75%) 0% 0,
linear-gradient(135deg, transparent 75%, $color 75%) 0% 0%;
background-repeat: repeat-y;
background-size:30px 30px, 30px 30px;
}
@mixin zigzag_right( $color ){
background: linear-gradient( 45deg, $color 25%, transparent 25%) 0% 0,
linear-gradient(135deg, $color 25%, transparent 25%) 0% 0%;
background-repeat: repeat-y;
background-size:30px 30px, 30px 30px;
}
这是一个codepen示例:http://codepen.io/anon/pen/HjJBF