Tuesday, December 12, 2017

How can I create this irregularly-shaped border with pure CSS (no images)?


I am trying to avoid using a background image (or any image-based solution) to effectively create this:


irregular border


Note: the red arrow is just pointing at the border in question. The arrow should not be included in your answer.


How can I create this irregularly-shaped border with pure CSS (no images)? If images are unavoidable, the most concise and readable answer will get upvoted and accepted.



Answer



You could use CSS (keeping in mind this won't work with older versions of IE).


For example, you could combine some shapes like a rectangle and two triangles. See this jsfiddle.



enter image description here


HTML:








And the CSS:


#triangle-topright {

width: 0;
height: 0;
border-top: 40px solid red;
border-left: 100px solid transparent;
}

#triangle-topleft {
width: 0;
height: 0;
border-top: 40px solid red;

border-right: 100px solid transparent;
}

#square {
background-color:red;
clear:both;
height:60px;
width:200px;
}


.align div {
float: left;
}

You can see a variety of CSS shapes here. Most if not all require more than one div, so the challenge would be applying a darker border.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...