I am trying to draw following "L" shaped div using CSS.
How can I draw this shape so contained text flows in this L shaped container?
Like so:
HTML:
<div class="container">
<div class="mask"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
CSS:
.container
{
border: 3px solid black;
}
.mask
{
border-style: solid;
border-width: 0 0 3px 3px;
position: relative;
float: right;
clear: none;
right: -3px;
top: -3px;
background-color: white;
width: 50%;
height: 4em;
}
Demo
Here is another version which caters for transparent and non-solid backgrounds also. In essence this is an enhancement on the currently accepted answer.
In this method the shape is created as follows:
linear-gradients
for half the width and half the height of the container. The backgrounds have size equal to the width the border and are positioned as required on top left and bottom right..container {
box-sizing: border-box;
position: relative;
margin: 10px;
border-left: 3px solid;
border-bottom: 3px solid;
height: 250px;
/*height: auto;*/
width: 400px;
line-height: 20px;
background: -webkit-linear-gradient(0deg, black 50%, transparent 50%), -webkit-linear-gradient(90deg, black 50%, transparent 50%);
background: -moz-linear-gradient(90deg, black 50%, transparent 50%), -moz-linear-gradient(0deg, black 50%, transparent 50%);
background: linear-gradient(90deg, black 50%, transparent 50%), linear-gradient(0deg, black 50%, transparent 50%);
background-size: 100% 3px, 3px 100%;
/*background-size: 100% 3px, 3px 122%;*/
background-position: 0px 0px, 100% 100%;
background-repeat: no-repeat;
}
.container:before {
position: relative;
float: right;
right: 0px;
top: 0px;
content: '';
background: transparent;
height: 50%;
/*height: 80px;*/
width: 50%;
border-left: 3px solid;
border-bottom: 3px solid;
}
p {
display: block;
padding: 8px 8px;
}
/* Just for demo */
body {
background: -webkit-linear-gradient(0deg, crimson, indianred, purple);
background: -moz-linear-gradient(90deg, crimson, indianred, purple);
background: linear-gradient(90deg, crimson, indianred, purple);
}
<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
Points to note:
clip-path
(can be employed using SVG or CSS). The support however is very minimal. SVG Sample | CSS Sample
height
on both parent and pseudo element. For gradients to look like perfect borders, the size would need to be modified dynamically as parent's height increases.You can use Use Google web designer tool for creating complex shapes using HTML5-canvas and CSS
.
As the file contains much code, providing a fiddle of the demo created using Google Web Designer tool
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With