I haven't been able to get some text to align horizontally and vertically within a div
.
I have the following css :
html, body {
position: relative;
margin:0;
padding: 0;
width: 100%;
height: 100%;
}
body {
color: #333;
margin: 0;
padding: 8px;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
div{
display: grid;
background-color: blue;
max-height: 200px;
min-height: 200px;
min-width: 100%;
max-width: 100%;
}
div p{
color:white ;
justify-content: center;
align-items: center;
text-align: center;
}
<div>
<p>{tkn}</p>
</div>
In theory, the paragraph inside div
should be centered both horizontally and vertically according to the css code , but the text is painting it for me at the top.
That is to say that you are not centering it vertically , only horizontally .
To fix it, just change the styles you have in
p
the parentOnly by changing those two attributes of p to div, the content of the div will be centered vertically.
You have to remember that who sets the style of how the content will look is the container, not the content.
In the styles of the div, you must replace "display: grid;" by "display: flex;" and in the styles of the p element, you should add these two lines: margin: 0 auto; align-self: center;