试着让它看起来像“有角度的剪裁”。如果可能的话,我不喜欢使用任何带有伪元素的hack。

HTML应该是一些简单的东西,比如:
<span>Hello World</span>CSS:
span {
// some crazy new css-3 rule?
}我不关心较旧的浏览器,并且解决方案必须具有响应性。
发布于 2017-04-15 18:47:17
不,在CSS3中没有这样疯狂的规则(在css4*中也没有),所以你可以创建一个SVG,或者使用不需要的伪(或者2个额外的内部元素,后者更糟糕)。
下面是最简单、最不麻烦的解决方案,其中使用了伪
span {
position: relative;
display: inline-block;
padding: 10px 20px 10px 25px;
margin: 10px;
}
span::before, span::after {
content: '';
position: absolute;
left: 0; top: 0;
width: 100%; height: 50%;
border: 2px solid #ddd;
background: #eee;
z-index: -1;
}
span::before {
border-bottom: none;
transform: skewX(40deg);
}
span::after {
top: 50%;
border-top: none;
transform: skewX(-40deg);
}
/* second span */
span ~ span {
font-size: 32px;
}<span>Hello World</span>
<br>
<span>Hello World</span>
选项
发布于 2017-04-15 18:46:27
我用CSS3做了一个裁剪角落的例子。
.quote {
background: #000;
color: #fff;
position: relative;
z-index: 1;
}
.q{
background: #000;
color: #fff;
position: relative;
z-index: 1;
padding:10px;
margin:100px;
width:100px;
border-right: 10px solid black;
}
.quote:after {
background: inherit;
bottom: -11px;
content: '';
display: block;
height: 200%;
left: -50px;
position: absolute;
right: -10px;
transform: skewX(-35deg);
transform-origin: 100%;
z-index: -1;
}
.quote:before {
background: inherit;
top: -11px;
content: '';
display: block;
height: 200%;
left: -50px;
position: absolute;
right: -10px;
transform: skewX(35deg);
transform-origin: 100%;
z-index: -1;
}
.q:after{
background: inherit;
bottom: 0;
content: '';
display: block;
height: 50%;
left: 10px;
top:20px;
position: absolute;
right: -50px;
transform: skewX(-35deg);
transform-origin: 100%;
z-index: -1;
}
.q:before{
background: inherit;
bottom: 0;
content: '';
display: block;
height: 50%;
left: 10px;
top:-00px;
position: absolute;
right: -50px;
transform: skewX(35deg);
transform-origin: 100%;
z-index: -1;
}<div class="q">
<span class="quote">Hello World!!</span>
</div>
https://stackoverflow.com/questions/43424638
复制相似问题