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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:39:46+00:00 2026-05-23T02:39:46+00:00

Sorry, weird title. Anyway, I add a div and some text to a Control

  • 0

Sorry, weird title.

Anyway, I add a div and some text to a Control like so, in C#.

lit.Text = "<div class=\"event\">" + text + "</div>";

And I style it like this:

.event:hover  
{
    background: #F0F0F0;
}

I’d like the background change to only be as long as the text, not the whole div. How can I do this?

UPDATE: Wrapping it in a span and styling the span works to an extent. I didn’t mention that the control I’m adding it to is a table cell. I’ve got:

style="width:50%"

which was forcing the cell to take up exactly half the table, despite how much text was in it or the second cell in the same row. With the span, this is no longer true and the table is misaligned. How do I fix that?

  • 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-23T02:39:47+00:00Added an answer on May 23, 2026 at 2:39 am

    Than you have to apply it to the text.

    lit.Text = "<div class=\"event\"><span>" + text + "</span></div>";
    
        .event 
        {
          width:50%;
        }
    
    
        .event span:hover  
        {
            background-color: #F0F0F0;
        }
    

    Should do the trick;

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

Sidebar

Related Questions

I’m sorry if the title isn’t clear, but this is a weird problem. I
Sorry for the unhelpful title, but hopefully I can explain this well enough. Lets
Sorry about the weird title, I'm currently playing around with WinForms and I'm wondering
Sorry for the length of the post. This is quite a weird problem and
Sorry about the weird question title, but I don't really know what to call
I'm sorry in advance if this question is really weird. I am sending data
Sorry for the weird title, but well, that's exactly what I need. I know
Sorry for the really weird title, but here’s what I’m trying to do: var
Sorry for the weird title, I could't think of anything better! Anyways, I'm half
Sorry about the weird title... all will be explained. Basically I have an array/dictionary

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.