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

The Archive Base Latest Questions

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

I know it is possible to create a custom "tooltip" with the :hover:after selectors

  • 0

I know it is possible to create a custom "tooltip" with the :hover:after selectors and to align this tooltip relative to the original element by marking the original element as position:relative and the tooltip as absolute.

HTML:

test
<span custom-tooltip="testing a custom tooltip" class="tooltip">
    test
</span>
test

CSS:

.tooltip {
    position: relative;
}

.tooltip:hover:after {
    content: attr(custom-tooltip);
    position: absolute;
    background: black;
    color: white;
}

However, I must use absolute values to position or size this :after element

top: 30px;
left: -30px;
width: 300px;

What if I want to make the element as wide as it needs to be (Percentages are relative to the parent element creating a large vertical box so I can’t tell it to go width: 100%)

And centered under the parent (left: -50% results in it being moved 50% of the parent to the left, not centered)

Is this possible without javascript? (If not, are there some magic selectors or functions to get the width of this or that and calc() the correct values?

  • 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-27T00:23:47+00:00Added an answer on May 27, 2026 at 12:23 am

    You can force the tooltip onto a single line by using white-space:nowrap. I don’t know of any way to center the tooltip without forcing a specific width on both the tooltip and the item the tooltip applies to. Here’s a general-purpose example (without centering):

    <p>Lorem <span tooltip="Lorem ipsum">ipsum</span> dolor sit amet.</p>
    

    And the CSS:

    *[tooltip] {
      position: relative;
      border-bottom: dotted 1px #000;
    }
    *[tooltip]:hover:before {
      content: attr(tooltip);
      background-color: #000;
      color: #fff;
      top: 1em;
      position: absolute;
      white-space: nowrap;
    }
    

    Note that I’m using :before instead of :after. If you want to center the tooltip and are able to define a fixed width, you can use this CSS instead:

    *[tooltip] {
      position: relative;
      display: inline-block;
      text-align: center;
      width: 200px;
      margin: 0 -75px;
    }
    *[tooltip]:hover:before {
      content: attr(tooltip);
      background-color: #000;
      color: #fff;
      top: 1em;
      position: absolute;
      white-space: nowrap;
      width: 200px;
    }
    

    Here, the item is given a fixed width equal to the width of the tooltip then negative left/right margins to collapse it back down to the desired size. Note the addition of display:inline-block and text-align:center.

    This technique isn’t practical for inline tooltips, but works well for buttons and “call to action” links.

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

Sidebar

Related Questions

I would like to know if this is possible to create a custom validation
I would like to know Is it possible to create a custom control like
Does somebody know if is it possible somehow to create a custom NSAnimationCurve so
I know it is possible to create a custom group indicator in an expandable
I know it's possible in asp.net to create a custom error page in a
Of course I know is possible to create a file with a certain size
I know it's possible to create a friend function in C++: class box {
Does anyone know if its possible to create a new property on an existing
Hi it'd like to know if it's at all possible create a parametric equalizer
I know that it is possible to create .xls files from Delphi using ADO,

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.