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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:58:03+00:00 2026-05-22T14:58:03+00:00

I imagine this is straight forward, but I haven’t been able to work out

  • 0

I imagine this is straight forward, but I haven’t been able to work out how to do it. I would like to center some text in a div, and then apply a background color to just the width of the text, without having to enter a width for the div (so that the background color is automatically the width of the text)

At the moment my CSS looks like this:

.heading {
text-align: center;
background-color:red;
}

which centers the text, but makes the background of the entire line on the page red.

When I add display:inline the background is just the width of the text, but the text is no longer centred.

Could someone help with this?

Thanks,

Nick

  • 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-22T14:58:04+00:00Added an answer on May 22, 2026 at 2:58 pm

    Wrap your text inside .heading in a span and then:

    .heading {
      text-align: center;
    }
    
    .heading span {
      background-color:red;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I imagine this is a question that has been asked a thousand times but
I would like to perform some arbitrarily expensive work on an arbitrarily large set
I imagine this should be very straight forward and after fruitless searching it seems
Imagine this case, but with a lot more component buckets and a lot more
Imagine this code: class foo { foo fff; int m_id; f & work() {
In straight SQL, I'd probably wrap some logic over a simple join, but how
This might be a pretty straightforward question, but I'm trying to understand some of
No, this is not a straight forward toggle question. I am aware of the
Imagine an account table that looks like this: Column | Type | Modifiers ------------+-----------------------------+-----------
I would like to know how many times an object has been autoreleased. I've

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.