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

  • Home
  • SEARCH
  • 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 9030649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:32:34+00:00 2026-06-16T07:32:34+00:00

I have a variable size block of text, which I would like centered in

  • 0

I have a variable size block of text, which I would like centered in a div. The width of the div is a % of its parent element, and the height is defined by padding however tall the center text is. This is easily achieved via:

<div style="width: 50%; padding: 15px; text-align: center;">
    Lorem ipsum...
</div>

That works fine.

But when I try to add the part on the right:

<div style="width: 50%; padding: 15px; text-align: center;">
    Lorem ipsum...
    <div style="float: right;">ASDF!</div>
</div>

then it counts the width of the text on the right towards the total width of the text, and puts the “ASDF!” on the right, but puts the “Lorem ipsum…” more to the left than it ought to be (as if the total length of lorem… included the asdf!).

Here’s a mockup of what I’m trying to achieve:

Mockup of what I'm trying to achieve.

I think this would be pretty easy with flexbox, but I want to avoid using anything recent because I need to support old browsers.

This question seems relevant, but (correct me if I’m wrong) it seems to require known widths.

How would I best go about doing this?

  • 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-06-16T07:32:36+00:00Added an answer on June 16, 2026 at 7:32 am

    Try this:

    <div class='content' style="width: 50%; padding: 15px; text-align: center; position: relative">
        <div class="noDown" style="position: absolute; right: 0;">ASDF!</div>
        Lorem ipsum...
    </div>​
    

    JsFiddle Test: http://jsfiddle.net/3Y7ty/2/

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

Sidebar

Related Questions

I'm trying to have a variable-height UITextView which changes size to accomodate its contents,
Ok so the question is simple: I have a variable width and height div
I have a block of a variable height in which I want to put
I have a variable that has this string: <DIV><SPAN style=FONT-FAMILY: Tahoma; FONT-SIZE: 10pt>[If the
I have variable in the parent document eg. $var = 'blah'; Then a div
I have variable which I populate from JSON formated data. Something like: var time=my_data[data.results[i].id].time;
I would like very much to create a web page which would have the
I have a variable called $driveusage that contains the following block of text: Filesystem
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
I have this array, for example (the size is variable): x = [1.111, 1.122,

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.