I would like to make a custom tooltip for the element, but I have it contained in the box, which doesn't have enough space for the tooltip, so it just crops (well, technically I can scroll to reveal it because overflow is set to auto, but I would like it to be visible without doing that). Is there a way to make it pop over the edge? I have tried using z-index to no result.
Here is what I am talking about:
.box {
width: 100px;
height: 100px;
overflow: auto;
border-style: solid;
border-color: red;
}
.tooltip {
padding-top: 20px;
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
display: none;
max-width: 60vw;
min-width: 15vw;
background-color: white;
border-style: solid;
border-color: #1a7bd9;
position: absolute;
z-index: 1000000;
}
.tooltip:hover .tooltiptext {
display: block;
}
<div class='box'>
<div class='tooltip'> Hover for tooltip
<div class='tooltiptext'>
Wow, this is amazing, such an epic tooltip text
</div>
</div>
</div>
Edit: It is important that hover works on the element, not the box that it is in.
Lot of ways to go about it, but if you're just looking for the tooltip to be visible outside the container, you don't need z-index or overflow. You just need to move your tooltip so it comes next in the positioning context inside of a relative container.
Per your comment, since you want the tooltip to appear only when hovering over the text, I'd recommend having your relative container wrap precisely around just the content you want to hover. To illustrate this, I added a border on the outer box versus where you decide to use the relative container.
Then, simply change box:hover to relative-container:hover to target the the appropriate element.
I attempted to organize the HTML and classes to be a bit more semantic and succinct for illustration. Hope that helps!
Example
.box {
padding: 30px;
border: blue solid;
width: 300px;
display: flex;
align-items: center;
}
.relative-container {
position: relative;
}
.box-content {
border-style: solid;
border-color: red;
padding: 10px;
}
.tooltip {
position: absolute;
left: 0;
top: 0;
max-width: 60vw;
min-width: 15vw;
background-color: white;
border: #1a7bd9 solid;
display: none;
}
.relative-container:hover .tooltip {
display: block;
cursor: pointer;
}
<div class='box'>
<div class='relative-container'>
<div class='box-content'>
Hover for tooltip. I have a little padding to give the text some room.
</div>
<div class='tooltip'>
Wow, this is amazing, such an epic tooltip text. I'm aligned with the top of the box content containing text and take up the full width. I only appear when hovering over the box content (red outline), not the surrounding container (blue outline).
</div>
</div>
</div>
Is there a way to make the tooltip above the text?
Example with Tooltip Position Above Text
Sure, just read a bit about position: absolute; - you can position it with respect to the relative container however you like. Using this in combination with how you decide to position your actual content inside the container gives you many options, but you have to keep in mind the dynamic size of the tooltip based on content length, screen/browser dimensions, and location of hover target element and tooltip! :) JS can be handy here.
.box {
padding: 30px;
border: blue solid;
width: 300px;
display: flex;
align-items: center;
}
.relative-container {
position: relative;
}
.box-content {
border-style: solid;
border-color: red;
}
.tooltip {
position: absolute;
left: 0;
/* minus surrounding container padding and border*/
top: -34px;
border: #1a7bd9 solid;
min-width: 15vw;
/* full width accounting for subtracting left/right margins from body in snippet (8x2 = 16) minus border widths and left padding of surrounding container (30 + 8 = 38)* - content is fluid though so up to you how you deal with it if the tooltip content grows bigger, can't just keep it on top without accounting for fact content is dynamic :) */
width:calc(100vw - 54px);
background-color: white;
display: none;
}
.relative-container:hover .tooltip {
display: inline;
cursor: pointer;
}
<div class='box'>
<div class='relative-container'>
<div class='box-content'>
Hover for tooltip. I'm just an element with some text, so only hovering on the text brings up the tooltip.
</div>
<div class='tooltip'>
I'm aligned with the top left of the box content, and I'm given some additional width to overflow it. I'm mostly on top of the text - that is if the content isn't too long and screen size not too narrow! :)
</div>
</div>
</div>
In practice, you may find that placing the tooltip directly over the hovered content is undesirable (if it covers it up, user can't easily reference what they just hovered over while looking at tooltip). Also, as mentioned above, content is fluid and needs space to run, so it will overflow somewhere depending on its length and other factors.
Positioning Context
The takeaway is just to think of your relative container as the reference point for the absolutely positioned tooltip. You generally don’t need or want to style it much in most cases, just give it a position of relative and then let the child element(s) dictate size/positioning of content inside.
More on positioning context here.
Showing/Hiding the Tooltip
The other consideration is whether to remove the tooltip from the document flow (ex. display property) and/or change the visibility or opacity. I've just used display to remove and add the tooltip, which is the simple approach. This ensures that when hovering over the area taken up by the tooltip itself (which may extend outside the original hover text bordered in red) but before hovering on the actual text, the tooltip doesn’t unintentionally show. I also set the tooltip cursor to pointer during hover.
Other approaches probably fall outside the scope of what you're asking, but thought it was worth mentioning there are considerations here.
One way to implement this is to make a ::before pseudo-element that positioned above and next to the text being hovered.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box {
width: 100px;
height: 100px;
padding-top: 20px;
border-style: solid;
border-color: red;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip::before {
content: "Wow, this is amazing, such an epic tooltip text";
position: absolute;
left: 25%;
bottom: -75%;
display: none;
width: 500px;
background-color: white;
border: 2px solid pink;
}
.tooltip:hover::before {
display: flex;
}
<div class='box'>
<div class='tooltip'>
Hover for tooltip
</div>
</div>
You can change overflow to be visible and it will pop over the edge.
.box {
overflow: visible;
}
Related
Image attached in this link
In number 9 cell border is over the background color
How do I show the border over the div or background Color and it should be responsive?
<div className="borderOverDiv"><div>
<div className="backgroundClr"></div>
.borderOverDiv{
position: absolute;
border: 1px solid red;
width: calc(100% - 94%);
height: 30px;
border-radius: 10px;
}
.backgroundClr{
background: blue
}
this code as I tried, seems not working
I am assuming that you are new to css so I will try to explain what is going on with this code the best that i can.
The fun part is in .element.active:after
There is a few thing
position: absolute this will allow us to set this element absolutly to container. But witch container? First that has position set to a different value than static or its initial value. That is why .element has position: relative which doesn't do anything on its own.
top, right, bottom, left which tell that this element will be exceeding parent element on every side by 5px.
z-index Simply the higher the value the "closer" this element is to user. initial value is 0 so 1 is placing this element above every other element.
content is required in pseudo-element :after in order to show them. This property just needs to be set and doesn't have to have any value specified.
The reis is just to make it look nicer.
And thats it.
You can use other element inside .element if you feel like it.
For example
<div class="element">
<div class="overlay"></div>
</div>
and it will work just fine if you will follow point form 1 to 3 (point 4 is required, as I said earlier, only in pseudo-element) but it will be less responsive. For example what will you have to do when other element needs this overlay? You will have to use javascript to append .overlay element to .element and with pseudo-element you just need to append class. or just show this overlay on hover. Other advantage is that it look prettier and doesn't bloat you html.
.container {
padding: 5px;
display: flex;
}
.element {
position: relative;
background-color: #0000ff;
padding: 10px 20px;
display: inline-block;
color: #ffffff;
}
.element.active:after {
content: '';
position: absolute;
top: -5px;
right: -5px;
bottom: -5px;
left: -5px;
border-radius: 40px;
background-color: rgba(200, 200, 200, .4);
border: 1px solid rgba(200, 200, 200 ,.8);
z-index: 1;
}
<div class="container">
<div class="element">7</div>
<div class="element active">8</div>
<div class="element">9</div>
</div>
replacing className with class should do the trick
I have a bound class inside a div whose data changes dynamically (every day). Some of this data which exceeds the length of the div is overflowing. I want to rectify these overflow errors by implementing a tooltip. I already have ellipsis in place which I implemented using css. I now want to implement a tooltip such that when I move the mouse and hover over the text which has been wrapped using ellipsis a tooltip should show up showing the complete text. I have done a lot of research on this and came up on a dead end since I havent found anything that explains how to get the tooltip to work on data whose length can change dynamically and to display the entire text in it. This is what I have in my code now:
<div class="BoundClass">
<div class="EllipsisOverflow">
<%#Container.DataItem("cClassName")%>
</div>
</div>
.BoundClass
{
font-size: 14px;
color: #fff;
margin-left: -10px;
position: relative;
height: 20px;
margin-bottom: 6px;
}
.EllipsisOverflow
{
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.EllipsisOverflow:hover:after
{
content: attr(title);
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 220px;
overflow:visible;
text-overflow:clip;
}
This is the CSS for the bound class, and I also applied ellipsis to it
I am looking for a straightforward answer on this so anyone who could help out please do
A basic tooltip can be created like this
HTML:
<div class='parent'>
Content
<span class="tooltip">More Content</span>
</div>
CSS:
.parent {
position: relative;
}
.tooltip {
display: none;
position: absolute;
}
.parent:hover .tooltip {
display: block;
}
Basically, make the tooltip then hide it until you hover on the parent.
You can see a working example with your CSS and code here
I'm not super comfortable with JS , but that seems to be the best way to do this , having a hard time applying other peoples solutions to my scenario.
Want an image to appear when hover over text.
I can get the image to appear on hover, but it appears up way up at top of page, and I am having a hard time getting it to appear in the viewport without indicating what the top margins is. Is that the best way to do it?
So far I have:
<div id="popup">
<div class="large-6 columns">
Bristol Hayward-Hughes <span> <img src="bristol.jpg" alt="Bristol" id="bristol"> </span>
</div>
</div>
and
#popup span {
display: none;
}
#popup a:hover span {
display: block;
position: absolute;
top: 0px;
left: 170px;
width: 400px;
margin: auto;
}
#bristol {
position: absolute;
z-index: 1;
margin-top: 100px;
}
If I'm understanding the question correctly, you'll need to place position:relative; in the parent Div: #popup that the image is residing in.
Check this Fiddle for reference: https://jsfiddle.net/rjschie/q87um7wd/2/
For an example: comment the position:relative; line under #popup and re-run the example. You'll see that the Image appears at the top of the window. Then uncomment it, and re-run and it will appear relative to the #popup div.
Please give relative positioning to your span that holds your image.
#popup a:hover span {
display: block;
position: relative; // Changed absolute to relative
//Give top and left position with respect to your anchor tag.
top: 0px;
left: 170px;
width: 400px;
margin: auto;
}
Remove the margin-top from the image tag as well.
#bristol {
position: absolute;
z-index: 1;
/*margin-top: 100px;*/ //Removed margin-top on the image
}
I can't seem to get the black box to the center of the screen as opposed to the center of the div its inside in.
EDIT: For clarification, I only want the black box in the center of the results panel not the pink box with it. Also I would also like to keep my javascript intact.
EDIT 2: I'm trying to have something like an overlay that popsup in the middle of the screen when a user clicks on the image. Not sure if this is the best way or the best code to achieve that!
Would appreciate if anyone can help.
Here's my attempt: http://jsfiddle.net/BPLcv/1/
HTML
<div class="tooltip">
<div class="description">Here is the big fat description box</div>
</div>
<div class="tooltip">
<div class="description">Poop</div>
</div>
CSS
.tooltip {
position: relative;
border: 1px #333 solid;
width: 200px;
height: 200px;
background-image: url('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSkI2PXYOOOHltHwgIz6xwfuN079IAJDLsmOV68rQNNLCE-GFZ1_aQN89U');
}
.overlay {
position: absolute;
display: none;
background-color: rgba(0, 0, 0, 0.7);
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.description {
position: absolute;
width: 300px;
height: 300px;
display: none;
background-color: black;
text-align: center;
z-index: 1;
/* centering???? */
top: 50%;
left: 50%;
margin-left: -150px;
margin-top: -75px;
}
Thank you!
If you want the description/overlay in the middle of the screen, your best bet is to use an element outside of your tooltip-elements, as these are fixed width.
If you have a top-element with width: 100%, your centering css wil work for any immidiate children.
Working fiddle: http://jsfiddle.net/BPLcv/4/
Here the overlay is filled with whatever is in the description element of the tooltip you're hovering:
overlay.html($(this).find(".description").html());
The description class is always hidden.
Check this Demo jsFiddle
CSS
body{
margin:auto;
width:50%;
}
Try this. Assign the div of interest id = CenterDiv, then add this css:
z-index:10;//remove left:50%
Now try adding this function via onload or onclick, etc:
function centerDiv() {
document.getElementById("CenterDiv").style.marginLeft = ((screen.availWidth - 300)
/ 2) + 'px';
}
The number 300 can be any number that represents the width of your element of interest.
Substituting the width of your element (here, 300px), this function will center an element with absolute position.
http://jsfiddle.net/waitinforatrain/sEX3n/
I have two divs in a container with absolute position. Both of them are set to be outside the boundaries of the container. If I uncomment the overflow: hidden line it will hide everything outside the container.
However, I only want div1's overflow to be hidden, and div2's to be visible. But because overflow:hidden has to be set in the parent, it will hide both of them. Is there any way to hide one?
Even if I could get it so that it shows overflow at the top and bottom boundaries but not at left and right that would suit (I tried messing with overflow-x and overflow-y but I gather that that's not their intended purpose).
<div id="container">
<div id="div1"></div>
<div id="div2">Test</div>
</div>
#container {
width: 300px;
position: relative;
border: 1px solid #000;
height: 10px;
/*overflow: hidden;*/
}
#div2 {
position: absolute;
top: 16px;
border: 1px solid #444;
}
#div1 {
position: absolute;
height: 10px;
left: 90%;
width: 15%;
background-color: purple;
}
The most obvious solution is to:
Add an extra wrapper div.
Apply overflow: hidden to this div.
Move the time outside this div.
Like this: http://jsfiddle.net/sEX3n/4/
Why not just move div#time outside the div#video-seek ?
Like this : http://jsfiddle.net/moeishaa/XNAmn/