How can I align this text vertically in the middle of the divs?
I've already tried to change the position using relative
/absolute
, and changing the top
and left
of the paragraph, but it doesn't work at all.
div.roxo{
background-color: purple;
padding: 40px;
}
div.amarelo{
background-color: yellow;
height: 300px;
width: 25%;
float: left;
}
div.vermelho{
background-color: red;
height: 300px;
width: 50%;
float: left;
}
div.verde{
background-color: green;
height: 300px;
width: 25%;
float: left;
}
div.azul{
background-color: blue;
padding: 40px;
}
p{
margin: 0;
text-align: center;
vertical-align: middle;
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div class="roxo">
<p>roxo</p>
</div>
<div class="amarelo">
<p>amarelo</p>
</div>
<div class="vermelho">
<p>vermelho</p>
</div>
<div class="verde">
<p>verde</p>
</div>
<div class="azul">
<p>azul</p>
</div>
</body>
</html>