tags:

views:

72

answers:

3

Here's what I got:

<div class="slideshow">
    <span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet. Lorum ipsum delore sit amet.</span>
    <span style="font-size:12px; color:#333333; font-family:Lucida Grande,Lucida Sans Unicode,Calibri,Arial,sans-serif;">Goodbye</span>
</div><br />

And the CSS:

/* slideshow */
.slideshow {
width:940px;
height:64px;
text-align:center;
background-image:url(../images/quotes.png);
position:relative;
}
.slideshow span {
display:block;
width:940px;
height:64px;
}

The <span>s are currently centered horizontally, but they should also be centered vertically. Is this possible?

The whole idea is to have testimonials on top the background image (quotes on the left and right side), but it doesn't quite look right without being centered both horizontally and vertically.

I'm sure I could somewhat get the desired effect using padding, but since each testimonial will be a different length I don't think that'd be a good approach.

A: 

yes it is possible.

Use the CSS attribute vertical-align:middle.

If you want to align verticaly below or above the horizontal center position then Use like this :

vertical-align:5;

or

vertical-align:-5;
GitsD
I tried using `vertical-align:middle;` with no success. Could you show me how I would do it in the code I provided?
Matt Untsaiyi
you can use padding to div.
GitsD
I already mentioned padding wouldn't make sense.
Matt Untsaiyi
A: 

Hi Matt, if you know that the content of your span will never exceed one line of text, just set

.slideshow span {
    line-height: 64px /* = the height of the containing div */
}

Or, if you know the height of the span:

.slideshow span {
    display: block;
    position: absolute;
    height: 64px;
    top: 50%;
    margin-top: -32px; /* = height/2 */
}

Last option would be to use a table formed by a single cell in place of the div, and use the vertical-align property.

mjsarfatti
Good idea. I might just do that, but I'm expecting it will probably exceed one line (one line isn't really that much space.)
Matt Untsaiyi
I jsut wrote a couple more options, please see the edited answer...
mjsarfatti
I tried the `position:absolute;` option just now, it works (with the exception it should be `margin-top:32px`, not -32) but has the same problem as using `line-height:64px` - anything over one line and it's no longer centered. Could I do the last option without replacing the `div`? My jQuery plugin Cycle needs it.
Matt Untsaiyi
replace the span instead :)
mjsarfatti
Is a table cell `<td>` - sorry I'm new to HTML/CSS, learning as I go.
Matt Untsaiyi
htmldog.com is a great resource for learning...
mjsarfatti
+1  A: 

CSS:

<style>
    div {
        width:300px; height:300px;
        text-align:center;
        display:table-cell; vertical-align:middle;
    }
</style>

HTML:

<div>
    <span>The Span</span>
</div>
Jeaffrey Gilbert
You beat me by milliseconds with the table-cell display property.
Stan Rogers
IE doesn't support display: table-cell unfortunately...
mjsarfatti
And it doesn't work anyway :(. I added `display:table-cell; vertical-align:middle;` to my `.slideshow` and my content goes straight to the top of my page, even above my navigation heh.
Matt Untsaiyi
@Matt maybe you must define its width and height. If it didn't work, i think you should follow @mjsarfatti's way.
Jeaffrey Gilbert
I did, oh well though ty anyway. I'm gonna try replacing the spans with a table cell like he suggested, I'm just not too sure how. Gonna google tables.
Matt Untsaiyi