Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML title attribute style [duplicate]

Tags:

html

How do I change the styling of the title attribute in the following tag without using javascript or CSS, since I am inserting the HTML into a specific spot in an otherwise uneditable doc.

    <span title = "This is information"> This is a test
    </span>
like image 883
user6556957 Avatar asked Jul 06 '16 16:07

user6556957


People also ask

Can you style title attribute?

You can't style an actual title attribute How the text in the title attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title attribute.

How do you style a tooltip title in CSS?

The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" . CSS: The tooltip class use position:relative , which is needed to position the tooltip text ( position:absolute ). Note: See examples below on how to position the tooltip.

How do I change the position of my title in HTML?

You can't. You'd need to make a custom tooltip to do that. There are libraries for that if you don't want to roll your own.


1 Answers

https://jsfiddle.net/LvjaxLfn/153/

<span aria-label="This is information">This is a test</span>

span:hover {
    position: relative;
}

span[aria-label]:hover:after {
     content: attr(aria-label);
     padding: 4px 8px;
     position: absolute;
     left: 0;
     top: 100%;
     white-space: nowrap;
     z-index: 20;
     background:red;
}

Using an aria label to keep accessibility

You could also add a transition delay to make it show up after a delay like a native html title

https://jsfiddle.net/f9zna6k2/10/

span {
  position: relative;
  cursor: pointer;
}

span[aria-label]:after {
  opacity:0;
  content: attr(aria-label);
  padding: 4px 8px;
  position: absolute;
  left: 0;
  top: 100%;
  white-space: nowrap;
  z-index: 20;
  background:red;
  transition: opacity 0.5s;
  pointer-events:none;
}

span[aria-label]:hover:after {
  opacity:1;
  transition-delay:1.5s;
}
like image 104
BritishSam Avatar answered Oct 17 '22 23:10

BritishSam