How to vertically align text within element css? [duplicate]

How to vertically align text within <div> element css? [duplicate]



This question already has an answer here:



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:


text-align: centre;



screenshot of extension



If anyone could help that would be great.



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




2 Answers
2



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;


<div>
<p>chatter</p>
</div>



ex) flex




div
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 50px;
background-color: #000;


div p
color: #fff;


<div>
<p>chatter</p>
</div>



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;


<div>
<p>chatter</p>
</div>






It works well for me! good solution.

– Canet Robern
Oct 12 '18 at 9:08



A really simple class I use for this is


.is-vertical-center
display: flex;
align-items: center;



Hope this helps!

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế