有没有办法用css绘制形状(下图)?灰色边框样式应为虚线。 最重要的是响应(应该调整不同尺寸的半径的屏幕)。
错误的例子(没有回复):
#box {
position: relative;
margin: 30px;
width: 200px;
height: 100px;
background: #fff;
border: 1px dashed #333;
}
.corner {
position: absolute;
height: 10px;
width: 10px;
border: 1px dashed #333;
background-color: #fff;
}
.top-left {
top: -1px;
left: -1px;
border-radius: 0 0 100% 0;
border-width: 0 1px 1px 0;
}

<div id="box">
<div class="corner top-left"></div>
</div>
&#13;
答案 0 :(得分:1)
我的建议是与SVG一起使用。这是它的用途。这是一个例子......
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100%" viewBox="0 0 256 128" enable-background="new 0 0 256 128" xml:space="preserve">
<path fill="#FFFFFF" stroke="#828282" stroke-dasharray="10" stroke-width="5" d="M249.75,121h-242V64c0,0,56.5,4.75,56.5-56.5h185.5V121z" />
</svg>
答案 1 :(得分:0)
我回答一下,因为我的评论似乎给你带来了一些想法。
这个想法基于(codepen)
使用宽度作为参考的垂直边距和填充百分比。
用于绘制虚线弯曲的背景渐变(firefox在那里有虚线/虚线圆形边框)
mix-blend-mode将伪父级和白色背景与页面混合。
https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
calc()混合百分比和像素,以15-20px宽度绘制弯曲边框。
p {
margin: 0;
text-shadow: 0 0 1px;
text-align:justify;
}
div {
font-size:2em;
width: 80%;
background: white;
margin: 10% 2em 2em 10%;
padding: 15px;
border: 15px dashed gray;
position: relative;
mix-blend-mode: multiply;
}
div:before {
padding: calc(3% + 10px);
float: left;
content: '';
}
div:after {
position: absolute;
content: '';
padding: 7%;
border: inherit;
border-radius: 50%;
top: 0;
left: 0;
margin: calc(-10% - 7px);
box-shadow: 0 0 0 15px white, inset 0 0 0 150px white;
}
div + div:after {
background: url(http://lorempixel.com/250/250/people/6) center ;
box-shadow: 0 0 0 15px white;
}
p:before {
content: '';
border-radius: 50%;
padding: calc(7% + 35px);
position: absolute;
background: repeating-linear-gradient(45deg, transparent 0, transparent 20px, gray 20px, gray 45px) bottom right no-repeat ;
background-size: 35% 39.5%;
top: -20px;;
left: -20px;
margin: -10%
}
body {
background: url(http://lorempixel.com/640/480/nature/6) yellow;
background-size: cover
}
<div>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus
lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor,
facilisis luctus, metus</p>
</div>
<div>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus
lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor,
facilisis luctus, metus</p>
</div>