The global problem:
I want to set the width of an element depending on the parent's height, I know that you can use padding-top
to set the height depending on the parent's width, maybe someone knows a trick for my case.
A possible solution(trick) to The global problem would be setting height: 100%
to the element and then rotate(90deg)
that would simulate that it has the width equal to the parent's height but that don't fit my case.
The specific problem ( Maybe it's possible to do some workaround):
Simplified problem:
I want a dynamic square element that has width and height = x where x = parent's height.
Full problem:
I want something like this
where x = d / sqrt(2) (Pythagorean theorem)
so as you can see "d" is the parent's height, I try with
.blue{
background: #1AA9C8;
width: 200px;
height: 100px;
position: relative;
margin: 25px auto;
}
.blue:before{
content: '';
position: absolute;
right: calc(100% - 36px);
top: 15px;
background: firebrick;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
height: calc(100% / 1.41);/*this worked because height depends on the parent's height (div.blue)*/
width: 70.9px; /* calc(100% / 1.41) here is my problem because width depends on the parent's width and I don't know how to make it depends on the parent's height
}
<div class="blue"></div>
Note that I set a fixed width
because I don't know how to make it depends on the height
of div.blue
Here a jsfiddle example to do some workaround.
I would be grateful if someone could help me.
ONLY CSS