Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6797593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:37:39+00:00 2026-05-26T18:37:39+00:00

I have a div containing a span and I want the span to vertically

  • 0

I have a div containing a span and I want the span to vertically and horizontally align to the center of my div.

Here’s the fiddle : http://jsfiddle.net/RhNc2/1/

I’ve try margin:auto on the span and the vertical-align on the div, but it’s not working

EDIT : My div and my span don’t have a fixed height, it depends of the content, i’ve put it fixed on the fiddle just to show you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:37:39+00:00Added an answer on May 26, 2026 at 6:37 pm

    Vertical alignment is a tricky business, and I don’t know if there’s one tried-and-true way. The most reliable technique available in the last couple of years is to use a CSS table layout. The only downside to this approach is that it may not work on outdated browsers. Still, in my experience this is probably the best overall solution. See my example below:

    <style type="text/css">
        #container {    
            display:table;    
            border-collapse:collapse;  
            height:200px;  
            width:100%;
            border:1px solid #000;
        }         
        #layout {    
            display:table-row;   
        }           
        #content {    
            display:table-cell;  
            text-align:center; 
            vertical-align:middle;    
        }           
    </style>
    
    <div id="container">    
        <div id="layout">    
            <div id="content"> 
                Hello world! 
            </div>     
        </div>   
    </div> 
    

    Here’s a jsFiddle: http://jsfiddle.net/aGKfd/2/

    There’s another technique, but it’s not as foolproof as the above technique. It involves two containers, with the outer container’s position set to relative and the inner set to absolute. Using absolute positioning on the inner container you can get close, but it requires some tweaking to get it just right:

    <style type="text/css">
        #vertical{ 
            position:absolute; 
            top:50%;     
            left:0; 
            width:100%; 
            text-align:center;
        } 
        #container {
            position:relative;
            height:200px;
            border:1px solid #000;
        }
    </style>         
    <div id="container"> 
        <div id="vertical"> 
            Hello world! 
        </div>               
    </div> 
    

    Here’s a jsFiddle: http://jsfiddle.net/6SWPe/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div, containing text and a few links. I want to trigger
I have a div containing several other divs with setting float:left. Now I want
I have the following jsFiddle: http://jsfiddle.net/tad604/dpRca/2/ That works as desired on IE and Chrome,
I have a div containing an event I want it to look like this
I have a div which contains a series of span tags, each containing a
I have div containing a list of flash objects. The list is long so
Say I have a div containing an unlimited number of child div s. Is
I have a div element containing some text. When the user clicks a word
I have an absolutely positioned div containing several children, one of which is a
I have a fixed width DIV containing a table with many columns, and need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.