0

Vertical alignement refuses

.txtSt { text-align: center; /* DOESN't WORK? vertical-align: middle; */ font-size: 10px; font-family: arial; } maybe it is something dumb..any help is appreciated. Thx *EDIT code added https://code.sololearn.com/WaMJ34I3p91i/?ref=app

26th Apr 2019, 10:19 AM
Robin R.
Robin R. - avatar
9 Answers
+ 2
Take a look at CSS flexbox! Finally we have a tool for properly doing stuff like this. It's kind of funny that it took us decades to figure out the simple task of centering things and we had to resort to putting in pixel values by hand or other odd things. But with flexbox it's easy, it's a great addition to CSS.
26th Apr 2019, 1:01 PM
Schindlabua
Schindlabua - avatar
+ 1
You got it to work now ?
26th Apr 2019, 10:31 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Line - height
26th Apr 2019, 10:44 AM
Gordon
Gordon - avatar
+ 1
Gordon didn't try that but, problem solved putting text in <span> and positioning that 😉
26th Apr 2019, 11:11 AM
Robin R.
Robin R. - avatar
+ 1
You can also add .txtSt { display: table-cell }
26th Apr 2019, 11:12 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Thx for the ideas everyone 🙏 *Edit for people interested in ways how to solve such problems, found this article; https://vanseodesign.com/css/vertical-centering/
26th Apr 2019, 11:14 AM
Robin R.
Robin R. - avatar
+ 1
Schindlabua flexbox Perfect Centering 😀 That sounds promesing, I will try that later!👌 SOLUTION: Set both the justify-content and align-itemsproperties to center, and the flex item will be perfectly centered: Example .flex-container {   display: flex;   height: 300px;   justify-content: center;   align-items: center; }
26th Apr 2019, 6:06 PM
Robin R.
Robin R. - avatar
0
You cannot apply a vertical-align to a block element. What type is .txtSt ?
26th Apr 2019, 10:22 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
its only working in table cell. i usually use, position as absolute then move the element 50% from top. then move it again in opposite direction by 50% of its own height by using translateY -50% (50%containter height - 50%element height) = center
26th Apr 2019, 10:30 AM
Taste
Taste - avatar