For you to use Calc(), you should always know the size of the things you insert, not only put height inside calc(), that it will not return the value for the calculation.
He must also be with position in absolute, Otherwise, the element will be out of alignment. In this example, when determining values for width and height, I worked with half the values for alignment:
.container {
background-color: lime;
height: 100px;
width: 100px;
position: absolute;
left: calc(50% - 50px);
top: calc(50% - 50px);
}
<div class="container">teste</div>
Another option, in my view easier, is to use the translate(-50%,-50%), in which you can freely determine the size of the element you want, which it will do the alignment automatically:
.container {
position:absolute;
top:50%;
left:50%;
width:100px;
height:100px;
transform: translate(-50%,-50%);
background:tomato;
}
<div class="container">teste</div>
Your lime has a pair of () more... It should be appended Calc((100% - height) / 2). Anyway I don’t know if this will solve. I actually believe that this is not the best way to align an element vertically....
– hugocsl
Sorry, but I couldn’t quite understand what you intend to do. You want a size of height variable so that the content inside it does not come out is this ? Just delete the height. There’s no need for it. But now if you need a specific value, you can go put the amount of pixels until you have the result you want. If you want to have a top space, inside your container, you can use only one Padding-top: Number of pixels;
– Köinzell
Here is more than 20 answers of how to do this alignment, some of them should serve you https://answall.com/questions/2817/qual-best-forma-de-centralizar-um-elemento-vertical-horizontally
– hugocsl
The
transform: translateY(-50%)withtop: 50%maybe I can solve.– Sam
https://stackoverflow.com/questions/39190922/how-to-calculate-with-scss-variables-from-function
– hugocsl