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 7429099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:54:57+00:00 2026-05-29T08:54:57+00:00

I’ll let you see the code first then tell you what my problem is:

  • 0

I’ll let you see the code first then tell you what my problem is:

Tinkerbin: http://tinkerbin.com/x8iGCFsZ

<style>
  div.container{
    height: 200px;
    width: 200px;
    background-color:red;
    margin-top: 10px;
  }

  div.subContainer{
    position: relative;
    text-align: center;
  }

  div.inner{
   position: absolute;
   background-color:yellow;
   width: 150px;
  }
</style>

<div class="container">
  <div class="subContainer">
    <div class="inner">bananas for breakfast</div>
  </div>
</div>

So, according to the textbook, text-align: center;, when applied to a parent element, only centers its child elements if they have display: inline;.

Therefore, and as you’d expect, since a <div> has by default display set to block (display:block;) the text-align: center; applied to the parent div.subContainer doesn’t do anything to its child div.inner.

Everything fine so far. Nothing weird.

My problem arouses when I try using <span>, instead of <div> on the .inner element, and I position it absolutely (position: absolute;) — which, as you know force changes the display, from its default inline, to block.

Take a look:

<style>
  div.container{
    height: 200px;
    width: 200px;
    background-color:red;
    margin-top: 10px;
  }

  div.subContainer{
    position: relative;
    text-align: center;
  }

  span.inner{
   position: absolute;
   background-color:yellow;
   width: 150px;
  }
</style>

<div class="container">
  <div class="subContainer">
    <span class="inner">bananas for breakfast</span>
  </div>
</div>

What happens is weird. In spite of having the forced display value of block (thanks to the position: absolute;) the span is still centered. And even more, the centering is actually weird. It takes the left side of the block and aligns it with the center of the containing element, instead of, as usual, aligning both center.

The behavior is fixed — starts acting like a block — when I manually set the display on the span.inner to block.

span.inner{
   position: absolute;
   display: block;
   background-color:yellow;
   width: 150px;
}

So, what’s happening here? Does the absolutely positioning not force change the display to block? Why is the centering weird?

  • 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-29T08:54:58+00:00Added an answer on May 29, 2026 at 8:54 am

    When you set it to position: absolute, it does become a block, but it gets removed from the flow of content at the point it would have originally appeared. Since you are not using top, left, bottom, and right, this is much more noticeable.

    When using a <div>: A division, by default, is block-level and will take up the entire width possible. So it would, by default, start at the left side of the box and expand to the right. Positioning this absolutely would keep it at the top left corner where it originally appeared, the only noticeable difference being the width of the box.

    result-with-div

    When using a <span>: A span, by default, is an inline element which is affected by the text-align property of it’s parent. The text cursor starts at the center of the element, and as text is entered, the characters are added and re-centered to adjust to the width of the text. When you remove the span from the flow, it starts at the point where the text would have started. The text cursor is at the very center (horizontally) of the element, since now there is no text in the actual parent.

    result-with-span

    You’ve already found the solution: adding display: block will force the element to actually be a block-level element. The thing is, just because position: absolute “forces” this property, it’s not an actual property, only a computed value for the element. That being said, it only gets applied to the element’s position when its explicitly set in its CSS definitions.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.