Możesz np. bez podawania width i height
<p>Lorem</p>
p {
position: absolute; /* lub position: fixed; */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
możesz też, za pomocą "kontenera" i flex
<div class="container">
<div>Lorem</div>
</div>
html, body {
margin: 0;
}
.container {
width: 100vw;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
/* Dla demonstracji */
background-image: linear-gradient(transparent 10%, grey);
}
.container div {
/* Dla demonstracji */
background-image: linear-gradient(transparent 10%, orange);
}
możesz też spróbować z: display: grid; , czy display: table ( zapytaj wujka google )
[ CENTERING THINGS by css ] [ Centering in CSS: A Complete Guide ]
[ Quick CSS Trick: How To Center an Object Exactly In The Center ]
[ How to Center Anything with CSS - Align a Div, Text, and More ]