Solved

How can i make the text vertical align middle in span box?

Posted on 2008-10-14
2
1,214 Views
Last Modified: 2012-05-05
hi,

how can i make the following box's text align vertical middle?

thanks
<span style="border: 2px solid purple;

			width: 10em;

			height: 10em;

			margin: 2px;

			display: inline-block;

			vertical-align: middle;

			text-align: center;

			overflow: hidden;">1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _ </span>

Open in new window

0
Comment
Question by:Valimai
2 Comments
 
LVL 44

Accepted Solution

by:
scrathcyboy earned 250 total points
Comment Utility
SPAN is usually for inline text, not for block level container alignment.  If you want to vertically align text in this, you are better to use a DIV than a span.  There are many ways to do this for DIV, see these --

http://webdesign.about.com/od/beginningcss/a/aa012207.htm
http://www.hicksdesign.co.uk/journal/how-to-vertical-centering-with-css
www.zoffix.com/zoffix/css/vertcenter.shtml
http://phrogz.net/CSS/vertical-align/index.html

basically the vertical-align: middle; does it for a DIV
    .vcenter {

      min-height: 12em;

      display: table-cell;

      vertical-align: middle;

    }
 

    <div class="vcenter">

    <p>This text is vertically centered in the box.</p>

    </div>

Open in new window

0
 
LVL 1

Author Comment

by:Valimai
Comment Utility
hi,

the following works in firefox but not IE. the following link you provided me gives an IE fix using wrappers. So much code, so looks like i wont use it.
www.zoffix.com/zoffix/css/vertcenter.shtml

thanks for your help.
<div style="

		border: 2px solid purple;

		width: 10em;

		height: 10em;

		display: table-cell;

		vertical-align: middle;">

		<p>1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _ 1 2 3 4 5 6 7 8 9 _</p>

</div>

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Add code to body in wordpress site 8 35
reposition hamburger icon to top of screen 5 45
HTML Lists 3 29
CSS grid style change 2 13
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now