How can I make a diagonal line fill in and fit into a box (just pure css - without any use of background image)?
div.diagonal-container {
border: 1px solid #000;
width:400px;
height:400px;
margin: 0 auto;
}
.to-right,
.to-left {
border-top:1px solid #ff00ff;
width:100%;
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.to-right {
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
<div class="diagonal-container" style="">
<div class="to-right"></div>
</div>
<div class="diagonal-container" style="">
<div class="to-right"></div>
</div>
<div class="diagonal-container" style="">
<div class="to-left"></div>
</div>
Result:
Also, is it possible to have an element only without wrapping it? For instance:
<div class="to-right"></div>
<div class="to-right"></div>
<div class="to-left"></div>
Is it possible?
You can add a
linear-gradient
background
and ditch the inner element, add that class to the other divMy approach:
position: relative
to the container andposition: absolute
for the lines.transform-origin: left
andleft: 0
for the left line,transform-origin: right
andright: 0
for the right line.width
andheight
of the container are equal, then the width of the line'll be ~141.5%
.If you used a CSS preprocessor (LESS for example), you'd do something like this:
CodePen
You can draw the lines with pseudo elements.
Try this as your css: