I need to center some text inside a <div> or <span> tag.
I’ve set the display:table-cell. That worked.
But I want to animate it (using jQuery). But this doesn’t work because the display is set back to display:block. I don’t want that, because that’s not displaying properly.
Does anyone know a way to do it?
(Tell me if you need the code I used.)
<div id="container">
<ul>
<li id="1">
<span id="spanimg1">Lorem Ipsum</span>
<img id="img1" src="1.jpg" />
</li>
<li id="2">
<span id="spanimg2">Lorem Ipsum</span>
<img id="img2" src="2.jpg"/>
</li>
<li id="3">
<span id="spanimg3">Lorem Ipsum</span>
<img id="img3" src="3.jpg"/>
</li>
</ul>
</div>
<style>
#container {
width: 400px;
height: 400px;
position:relative;
margin: auto;
vertical-align:middle;
}
li {
margin: 0;
padding: 0;
}
ul {
margin: 0;
padding: 0;
list-style-type:none;
}
li span {
position:relative;
background:black;
width:400px;
height:80px;
text-align:center;
color:white;
display:none;
z-index:1000;
vertical-align:middle;
}
img {
position:absolute;
display:none;
}
.showimg {
display:block;
}
.show {
display:table-cell;
vertical-align:middle;
position:absolute;
}
</style>
Upgrade to jQuery 1.4.3 or later got get support for
table-celldisplay in animations.