Is there a way to create a diagonal line that fills in and fits perfectly into a box using just CSS, without the need for any background images?
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>
Outcome:
https://i.sstatic.net/DDUjt.png
View the working example on jsfiddle.
Addtionally, is it feasible to have an element exist on its own without wrapping it in a container? For example:
<div class="to-right"></div>
<div class="to-right"></div>
<div class="to-left"></div>
Would this be achievable?