简体   繁体   English

使用CSS绘制不规则形状的图形(应该响应)

[英]Irregular shape drawing with css (should be responsive)

Is there any way to draw a shape (image below) with css? 有没有办法用CSS绘制形状(下图)? The grey border style should be dashed . 灰色边框样式应为虚线 And the most important is it should be responsive ( should adapt different size of screen with different radius ). 最重要的是它应该具有响应性应使用不同的半径适应不同尺寸的屏幕 )。

Bad example (not responsive): 错误的例子(不响应):

 #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> 

在此处输入图片说明

My advice is to go with SVG. 我的建议是选择SVG。 It's what it's for. 这就是它的目的。 Here's an example... 这是一个例子

<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>

Fiddle: https://jsfiddle.net/6r0hhfsh/ 小提琴: https : //jsfiddle.net/6r0hhfsh/

I go with an answer since it seems my comment brought you some ideas. 我的回答是正确的,因为似乎我的评论为您带来了一些想法。

The idea is based on ( codepen ) 这个想法是基于( codepen

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM