Tuesday, 1 August 2017

html - How to vertically align text within element css?




I am making a chrome extension for the first time and am trying to centre text. And the moment I am using text-align: centre; to horizontally align it but can't figure out how to vertically align so at the moment my text looks like this:



screenshot of extension



If anyone could help that would be great.


Answer



ex) display: table






div{
display: table;
width: 100px;
height: 50px;
background-color: #000;
}

div p{
display: table-cell;

text-align: center;
vertical-align: middle;
color: #fff;
}


chatter








ex) flex





div{
display: flex;
align-items: center;
justify-content: center;
width: 100px;

height: 50px;
background-color: #000;
}

div p{
color: #fff;
}


chatter








ex) position





div{
position: relative;

width: 100px;
height: 50px;
background-color: #000;
text-align: center;
}
div p{
position: absolute;
top: 0;
right: 0;
bottom: 0;

left: 0;
color: #fff;
}


chatter






No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...