Answer
Since you’re talking about styling a DIV and tried a CSS solution (and there is actually a good and working one), this question would be better asked on StackOverflow.
But since I know how to use CSS I’ll answer here now anyway.
Create two DIVs. One for the red box, one for the white line like so
<div class="container">
<div class="line"></div>
</div>
Then add the CSS
.container {
width: 300px;
height: 300px;
background-color: red;
}
.line {
position: relative;
z-index: 1;
left: -50%;
width: 300%;
height: 1px;
background-color: white;
-webkit-transform: rotate(-45deg); /* Safari and Chrome */
-ms-transform: rotate(-45deg); /* IE 9 */
transform: rotate(-45deg);
}
The result will look like this working demo.
Attribution
Source : Link , Question Author : robotsatan , Answer Author : Jascha Goltermann