its posibily its posibily its posibily its posibily its posibily its posibily its posibily
Asked
Active
Viewed 7,872 times
-3
-
2Isn't the text itself a content? – Sleek Geek Mar 20 '15 at 15:36
-
use "display:table-cell" and vertical-align:middle for text middle – Sanjay Gohil Mar 20 '15 at 15:42
-
It;s not clear what you are asking. Are you trying to center this div vertically & horizontally on the page? – Paulie_D Mar 20 '15 at 15:45
-
1use the display properti :) http://jsfiddle.net/nju2ecby/1/ – G-Cyrillus Mar 20 '15 at 15:45
-
1Do not vandalize your posts. By posting on this site, you've irrevocably granted the Stack Exchange network the right to distribute that content under the CC BY-SA 4.0 license for as long as it sees fit to do so. For alternatives to deletion, see: [I've thought better of my question; can I delete it?](https://stackoverflow.com/help/what-to-do-instead-of-deleting-question) – Ollie Nov 19 '21 at 18:44
3 Answers
3
You can realize that by deleting the styles of the span (or the span completely) and display the .container
as a table-cell. Table-cells will allow you to vertical align the text in it.
Like this:
.container {
background:#010101;
width:150px;
height:40px;
font-size:11px;
color:#fff;
display: table-cell;
text-align: center;
vertical-align: middle;
}

GreyRoofPigeon
- 17,833
- 4
- 36
- 59
-
i see your fiddle, working perfectly, but on my localhost not working. – vaneayoung Mar 20 '15 at 15:59
1
try this
.text{
position:absolute;
left:25px;
top:13px;
width:120px;
font-size:11px;
color:#fff;
}
._text{
font-size:11px;
color:#fff;
}
.container {
position:relative;
background:#010101;
width:150px;
height:40px;
display:table-cell;
vertical-align:middle;
text-align:center;
}

Sanjay Gohil
- 144
- 10
1
See this solution: http://jsfiddle.net/nju2ecby/4/
I convert the span in div and for it I set the line-height the same of his container.
.text {
font-size:11px;
color:#fff;
margin: 0px auto;
text-align: center;
vertical-align: middle;
line-height: 150px;
}
._text {
font-size:11px;
color:#fff;
margin: 0px auto;
text-align: center;
vertical-align: middle;
line-height: 150px;
}
.container {
background:#010101;
width:450px;
height:150px;
}

Robertino
- 34
- 5