This is the HTML:
<div class="arrow">
i need to hide the overflown text which comes out of the div
</div>
and the corresponding CSS is:
.arrow {
width: 5%;
position: relative;
}
.arrow:before {
content: " ";
width: 0;
position: absolute;
left: -0.58em;
border-style: solid;
border-width: .585em .585em .585em 0;
}
I need to hide the overflowing text.
If I apply overflow:hidden the pointed triangle disappears instead of the text.
Can someone please help me with this.
The following might work if you wrap your content in an extra element:
<div class="arrow">
<span>i need to hide the overflown
text which comes out of the div</span>
</div>
For the CSS:
.arrow {
width: 5%;
position: relative;
}
.arrow:before {
content:"";
width: 0;
position: absolute;
left: -0.58em;
border-style: solid;
border-width: .585em .585em .585em 0;
border-color: red yellow green blue;
}
.arrow span {
width: auto;
display: block;
white-space: nowrap;
overflow: hidden;
}
I tweaked the border colors since the arrow shape was not obvious, but you can fix that easily enough.
I wrapped the text in a span, set white-space: nowrap to get the text to form a single line and then set overflow: hidden to hide any text wider than the width. Set display: block or else use a div instead of a span.
Fiddle demo: http://jsfiddle.net/audetwebdesign/nukeL/
You can do this without adding any more elements to your html:
Added white-space: nowrap to keep the text from wrapping
Added padding-left: 1em to make room for the arrow
Set left: 0 for your arrow
and fixed the arrow display...
CSS
.arrow {
white-space: nowrap;
width: 10%;
position: relative;
overflow: hidden;
padding-left: 1em;
}
.arrow:before {
content:" ";
width: 0;
height: 0;
position: absolute;
left: 0;
border-right: 0;
border-bottom: .585em solid transparent;
border-top: .585em solid transparent;
border-left: .585em solid black;
}
Demo
Add a container inside the arrow to constrain your text (assuming fixed height).
HTML
<div class="arrow">
<div class="container">
I need to hide the overflown text which comes out of the div.
</div>
</div>
CSS
.container {
height: 30px; /** assuming fixed height here. **/
max-height: 30px;
overflow: hidden;
}
JSFiddle example: http://jsfiddle.net/xBM88/
I don't find any pointed triangle in your fiddle.
But I would suggest you to take a look at text-overflow
overflow:hidden;
text-overflow:ellipsis; //don't hide content, instead render an ellipsis ("...")
Check this JSFiddle
Related
I have a text with a tooltip in the box. I cannot change the properties of the box itself, but I would like to make it so that the tooltip is above the text. Here is what I have now:
.tt-container .tooltiptext {
display: none;
background-color: white;
border-style: solid;
position: absolute;
border-color: #1a7bc9;
color: #000;
text-align: left;
border-radius: 6px;
padding: 15px 15px;
width: 300px;
/*bottom: 100%;*/
}
.tt-container:hover .tooltiptext {
display: block;
}
.tt-container {
border-style: solid;
display: inline;
}
.box {
/*I cannot make changes to this*/
width: 200px;
height: 200px;
border-style: solid;
border-color: red;
overflow: auto;
}
<div class="box"><br><br>
<div class="tt-container">
<span class="tooltiptext">some more text which takes a bunch of space maan</span>
text
</div>
</div>
I think that the best way to achieve what I want would be doing bottom: 100% inside tooltip-text, but when I do so, the bottom is computed relative to the bottom of the page, not the bottom of the tt-container. I figure that this is because I have to use position: relative on the tt-container, but this will make it so that the tooltip is covered under the edge of the box. I have tried creating another div outside the tt-container with position: relative, but the result is the same and I don't know of any other ways. Is it possible to make this happen?
.tt-container .tooltiptext {
display: none;
background-color: white;
border-style: solid;
position: absolute;
bottom:100%;
border-color: #1a7bc9;
color: #000;
text-align: left;
border-radius: 6px;
padding: 15px 15px;
width: 300px;
}
.tt-container:hover .tooltiptext {
display: block;
}
.tt-container {
border-style: solid;
display: inline;
position:relative;
}
.box {
/*I cannot make changes to this*/
width: 200px;
height: 200px;
border-style: solid;
border-color: red;
overflow: auto;
}
<div class="box"><br><br>
<div class="tt-container">
<span class="tooltiptext">some more text which takes a bunch of space maan</span>
text
</div>
</div>
You should make the parent position: relative for position:absolute to know that it should be positioned relative to the parent.
It's not possible to make the tooltip go out of the box, because it has overflow: auto;.
I want to make my table columns resizable. So I put a div inside the th and made those divs resizable. Problem is, there is an ugly pair of diagonal lines inside each of those resizable divs. How do I get rid of it?
This element is rendered by the browser itself and is not part of the HTML spec. There is one work around and that is to position another element over the top of the corner to hide it.
The text area will still be resizable keep in mind.
textarea {
position: relative;
margin: 20px 0 0 20px;
z-index: 1;
}
.wrap {
position: relative;
display: inline-block;
}
.corner {
height: 0px;
width: 0px;
border-top: 10px solid #fff;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
-webkit-transform: rotate(-45deg);
position: absolute;
bottom: 4px;
right: -5px;
pointer-events: none;
z-index: 2;
}
<div class="wrap">
<div class="corner"></div>
<textarea></textarea>
</div>
I have a div that needs to have relative positioning and limited width and height. I want scrollbars added if the content overflows. For this, I have style overflow:auto. This much works. Now I have a tooltip that I want to display when mousing over a target. I want the tooltip to display in its entirety, so it should display beyond the bounds of the enclosing div if necessary. For that I have the tooltip style overflow:visible. Problem is, the tooltip does not display beyond the bounds of the div. If I remove the positioning of the div, it works as expected: the div has the scrollbar, and the tooltip extends beyond the div. How can I get this to work when the div is relatively positioned? Any assistance would be appreciated.
.tooltip {
position: relative;
display: inline-block;
width: 18px;
height: 18px;
background-color: steelblue;
color: yellow;
border: solid;
border-width: 1px;
border-radius: 50%;
text-align: center;
vertical-align: central;
cursor: help;
}
.tooltip:before {
content: '?';
}
.tooltip + .tooltiptext {
position: absolute;
display: none;
margin: 5px;
padding: 5px;
min-width: 200px;
max-width: 400px;
background-color: steelblue;
color: #fff;
text-align: left;
border-radius: 6px;
overflow: visible;
}
.tooltip:hover + .tooltiptext {
display: inline;
}
.scrollIfNeeded {
position: relative;
left: 100px;
top: 100px;
overflow: auto;
background-color: lightgoldenrodyellow;
}
<div id="ModePage" class="scrollIfNeeded" style="width:300px; max-height:100px; margin-right:5px;">
<span class="tooltip"></span>
<span class="tooltiptext">
This is my tooltip. I want it to display beyond the bounds of the ModePage div. I have the tooltip style set to overflow:visible, however it is behaving as if it inherits the setting of the ModePage div.
</span>
Scale: <input id="ScaleUpButton" type="text" /> This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear.
</div>
You need to add position:fixed; to fix that. try this one
.tooltip {
position: relative;
display: inline-block;
width: 18px;
height: 18px;
background-color: steelblue;
color: yellow;
border: solid;
border-width: 1px;
border-radius: 50%;
text-align: center;
vertical-align: central;
cursor: help;
}
.tooltip:before {
content: '?';
}
.tooltip + .tooltiptext {
position: absolute;
display: none;
margin: 5px;
padding: 5px;
min-width: 200px;
max-width: 400px;
background-color: steelblue;
color: #fff;
text-align: left;
border-radius: 6px;
overflow: visible;
}
.tooltip:hover + .tooltiptext {
display: inline;
/* here need to set position and width [optionally]*/
position: fixed;
max-width: 200px;
}
.scrollIfNeeded {
position: relative;
left: 100px;
top: 100px;
overflow: auto;
background-color: lightgoldenrodyellow;
}
<div id="ModePage" class="scrollIfNeeded" style="width:300px; max-height:100px; margin-right:5px;">
<span class="tooltip"></span>
<span class="tooltiptext">
This is my tooltip. I want it to display beyond the bounds of the ModePage div. I have the tooltip style set to overflow:visible, however it is behaving as if it inherits the setting of the ModePage div.
</span>
Scale:
<input id="ScaleUpButton" type="text" />This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear.
This is some extra text to make the vertical scrollbar appear. This is some extra text to make the vertical scrollbar appear.
</div>
I am trying to create a css tool-tip, the html and css code and also link to fiddle is given below
CHECK MY CODE HERE #JSFIDDLE
HTML
<a class="tooltip" href="#">CSS Tooltips 1
<span>Tooltip1</span></a>
</br>
<a class="tooltip" href="#">CSS Tooltips
<span>Tooltip This is not working for me </span></a>
CSS
.tooltip {
position: relative;
}
.tooltip span {
position: absolute;
width:140px;
color: #FFFFFF;
background: #000000;
height: 30px;
line-height: 30px;
text-align: center;
display:none;
border-radius: 2px;
padding:2px;
}
.tooltip span:after {
content: '';
position: absolute;
top: 50%;
right: 100%;
margin-top: -8px;
width: 0; height: 0;
border-right: 8px solid #000000;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
}
.tooltip:hover span {
display: block;
opacity: 0.8;
left: 100%;
top: 50%;
margin-top: -15px;
margin-left: 15px;
z-index: 999;
}
My issue is only half the text from <span>Tooltip This is not working for me </span> is shown in the corresponding tool-tip. I tried hard but couldn't debug it. Please help.
Thanking You
It's because you have a fixed width. To allow the tooltip to dynamically expand to the content's width remove the width property and set white-space:nowrap to keep the text inline.
.tooltip span {
position: absolute;
color: #FFFFFF;
background: #000000;
white-space: nowrap;
height: 30px;
line-height: 30px;
text-align: center;
display:none;
border-radius: 2px;
padding:2px;
}
http://jsfiddle.net/89rwu2db/3/
EDIT
As commented bellow, if you want to keep the fixed width, but wants the text to expand in height, remove the height property of the span, and it will grow (also, don't use white-space anymore):
.tooltip span {
position: absolute;
color: #FFFFFF;
background: #000000;
width:140px;
line-height: 30px;
text-align: center;
display:none;
border-radius: 2px;
padding:2px;
}
http://jsfiddle.net/89rwu2db/9/
The point is, setting a specific width or height prevents your element of growing automatically.
You need to change the width property of the second tooltip to fit all the text you want display.
Fixed Fiddle: http://jsfiddle.net/89rwu2db/8/
I added styling to the second span to increase the width.
<span style="width: 250px;">Tooltip This is not working for me </span>
Trying to apply max-width in case of text wrap for tooltip in this jsfiddle, but it applies the default width.
HTML:
<div id="container" style="margin: 167px 135px 0px 0px; height: 400px">
<a class="tooltip" tip="television">content1</a>
<a class="tooltip" tip="By noon yesterday, news television screens were filled with visuals of a Delhi we have been familiarized with over the past year.">content2</a>
</div>
CSS:
.tooltip{
display: inline;
position: relative;
white-space: pre-wrap; /* css-3 */
margin: 20px 20px 20px 20px;
height: 30px;
width: 50px
}
.tooltip:hover:after{
background: #8FBC8F;
border-radius: 5px;
bottom: 26px;
color: #000;
content: attr(tip);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width:auto;
min-width:50px;
max-width:500px;
}
.tooltip:hover:before{
border: solid;
border-color: #8FBC8F transparent;
border-width: 6px 6px 0 6px;
bottom: 20px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
when the text in the tooltip is getting word wrapped, width should go up to some max width instead of the default width so that it is convenient for reading.
this jsfiddle works when i put display: inline-table; like below
.tooltip:hover:after{
:
:
display: inline-table;
}
But it works only in Chrome and not on IE
You have to use display:inline and max-width and for some browser use word wrap.There is a good tutorial to create css3 tooltip create css3 tooltip.
Here's some code from that tutorial:
.tooltip
{
display: inline;
position: relative;
}
.tooltip:hover:after
{
background: #333;
background: rgba(0,0,0,.8);
border-radius: 5px;
bottom: 26px;
color: #fff;
content: attr(title);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 220px;
max-width: 220px;
}
Stumbled upon the same problem, and after some fiddling found following workaround for my case: you have to wrap tooltip content in another element, which will have your expected max-width for the tooltip in width, and positioned absolute. Then wrapped content will use this as baseline max width while wrapping text.
Verified that it works in latest public IE/Edge/Chrome/FF at the time of writing
Codepen: https://codepen.io/jfhs/pen/LzbwgJ
In code:
<div class="tooltip">
<div class="tooltip-content-wrapper">
<div class="tooltip-content">Long long text</div>
</div>
</div>
CSS:
.tooltip {
position: relative;
}
.tooltip-content-wrapper {
position: absolute;
width: 100px; /* THIS is your max-width for tooltip */
visibility: hidden;
}
.tooltip:hover .tooltip-content-wrapper {
visibility: visible;
}
.tooltip-content {
display: inline-block;
}
Please change your CSS min-width and max-width like below:
.tooltip:hover:after{
background: #8FBC8F;
border-radius: 5px;
bottom: 26px;
color: #000;
content: attr(tip);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width:auto;
min-width:500px; /* I have changed here */
max-width:500px;
}
I came across this old question as I too was looking to see if it was possible to get min-width and max-width to work without having to add JavaScript or extra elements (as I was sourcing the tooltip text from an attribute). It turns out that changing width: auto; to width: max-content; in your jsfiddle does the trick (as suggested at: https://stackoverflow.com/a/62853552). Screenshot: