Is there any way to create a sharp flat corner with CSS and HTML?
Something like this:
____
/ \
| |
\____/
Is there any way to create a sharp flat corner with CSS and HTML?
Something like this:
____
/ \
| |
\____/
Look here. There you find all you need:
http://css-tricks.com/examples/ShapesOfCSS/
Edit In case the link goes lost:
CSS
#octagon {
width: 100px;
height: 100px;
background: red;
position: relative;
}
#octagon:before {
content: "";
position: absolute;
top: 0; left: 0;
border-bottom: 29px solid red;
border-left: 29px solid #eee;
border-right: 29px solid #eee;
width: 42px; height: 0;
}
#octagon:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
border-top: 29px solid red;
border-left: 29px solid #eee;
border-right: 29px solid #eee;
width: 42px;
height: 0;
}
Here is my solution, using the CSS shapes from Chris Coyier.
http://jsfiddle.net/dDejan/XSs9L/
4 extra divs are inserted via JavaScript (well, jQuery actually) for each of your containers that you want shaped this way. These divs are positioned absolutely in the corners of it's parent, and they are styled accordingly as described in the link posted by Sven Bieder
You can compose this using absolutely-positioned :before
and :after
elements using the CSS triangles technique.
<div class="box"></div>
css:
.box {
background-color:#2020ff;
height:50px;
width:50px;
position:relative
}
.box:after {
content:" ";
width: 0;
height: 0;
border-top: 10px solid #ffffff;
border-bottom: 10px solid transparent;
border-right:10px solid #ffffff;
position:absolute;
top:-9px;
right:0px;
}
box {
background-color: transparent;
position: fixed;
width: 300px;
height: 300px;
}
svg {
width: 300px;
height: 300px;
}
polygon {
visibility: visible;
background: black;
stroke: white;
}
<box>
<svg>
<polygon points="0 250, 50 300, 300 300, 300 50, 250 0, 0 0" />
</svg>
</box>
Here is a complete solution for the whole box. It scales based on the content size like you would expect from a regular div. And you can easily resize it with the height and width property without having to tinker with anything else. It is a modified version of this codepen.
div {
padding: 5px;
margin: 40px auto;
width: 230px;
background: rgba(47,51,54,1); /* fallback */
background:
-moz-linear-gradient(45deg, transparent 7px, rgba(47,51,54,1) 7px),
-moz-linear-gradient(135deg, transparent 7px, rgba(47,51,54,1) 7px),
-moz-linear-gradient(225deg, transparent 7px, rgba(47,51,54,1) 7px),
-moz-linear-gradient(315deg, transparent 7px, rgba(47,51,54,1) 7px);
background:
-o-linear-gradient(45deg, transparent 7px, rgba(47,51,54,1) 7px),
-o-linear-gradient(135deg, transparent 7px, rgba(47,51,54,1) 7px),
-o-linear-gradient(225deg, transparent 7px, rgba(47,51,54,1) 7px),
-o-linear-gradient(315deg, transparent 7px, rgba(47,51,54,1) 7px);
background:
-webkit-linear-gradient(45deg, transparent 7px, rgba(47,51,54,1) 7px),
-webkit-linear-gradient(135deg, transparent 7px, rgba(47,51,54,1) 7px),
-webkit-linear-gradient(225deg, transparent 7px, rgba(47,51,54,1) 7px),
-webkit-linear-gradient(315deg, transparent 7px, rgba(47,51,54,1) 7px);
xbackground:
linear-gradient(45deg, transparent 7px, rgba(47,51,54,1) 7px),
linear-gradient(135deg, transparent 7px, rgba(47,51,54,1) 7px),
linear-gradient(225deg, transparent 7px, rgba(47,51,54,1) 7px),
linear-gradient(315deg, transparent 7px, rgba(47,51,54,1) 7px);
}
div {
background-position: bottom left, bottom right, top right, top left;
-moz-background-size: 50% 50%;
-webkit-background-size: 50% 50%;
background-size: 50% 50%;
background-repeat: no-repeat;
}
p {
border-left: none;
border-right: none;
color: #ccc;
margin: 0;
min-height: 40px;
padding: 10px;
position: relative;
}
<div>
<p>Here is some content.</p>
</div>
.rotate {
margin: 100px;
background-color: olivedrab;
width: 100px;
height: 100px;
transform: rotate(45deg);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="rotate"></div>
</body>
</html>