Consider the following HTML and CSS code:
<div class="preview-content"> PREVIEW </div>
.preview-content { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAGklEQVQIW2NkYGD4D8SMQAwGcAY2AbBKDBUAVuYCBQPd34sAAAAASUVORK5CYII=) repeat; width: 100%; min-height: 300px; max-height: 300px; line-height: 300px; text-align: center; vertical-align: middle; font-size: 2em; }
The objective is to add diagonal lines to the background of the preview-content div, as seen in the following image:
[Image of a DIV with diagonal lines]
A scalable solution that dynamically adjusts to the element's dimensions can be achieved using CSS3 linear-gradients and the calc() function.
.crossed { background: linear-gradient(to top left, rgba(0,0,0,0) 0%, rgba(0,0,0,0) calc(50% - 0.8px), rgba(0,0,0,1) 50%, rgba(0,0,0,0) calc(50% + 0.8px), rgba(0,0,0,0) 100%), linear-gradient(to top right, rgba(0,0,0,0) 0%, rgba(0,0,0,0) calc(50% - 0.8px), rgba(0,0,0,1) 50%, rgba(0,0,0,0) calc(50% + 0.8px), rgba(0,0,0,0) 100%); }
<textarea class="crossed"></textarea>
The above is the detailed content of How Can I Create Diagonal Lines in a DIV Background Using CSS?. For more information, please follow other related articles on the PHP Chinese website!