简体   繁体   中英

Irregular shape drawing with css (should be responsive)

Is there any way to draw a shape (image below) with 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. 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/

I go with an answer since it seems my comment brought you some ideas.

The idea is based on ( 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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