I'm trying to use CSS to place a right triangle within a containing div so that the triangle takes up the full height and width of the containing div.
The height is set to 100px
, so that's easy enough to handle, but the width is variable (essentially 100%) of the screen width, and I can't figure out how to get the triangle to stretch properly for a variable width.
The following is basically what I would like to get on the screen:
The following markup and CSS is as close as I've been able to get, but the problems I'm running into is that you can't do a percentage for a border width, and setting 100vw
for the border width doesn't account for the vertical scrollbar, which causes the red triangle width to be too wide and thus add horizontal scrollbars to the site.
HTML:
<div class="container">
<div class="triangle">
</div>
</div>
CSS:
.container {
background: blue;
height: 100px;
}
.triangle {
border-color: transparent transparent transparent red;
border-style: solid;
border-width: 100px 0 0 100vw;
}
Does anyone know how to solve this problem? Thank you.