Wrap text onto next line if no more space - html

I have this tooltip when hovering over the info icon next to the header. I can't make it wrap text to the next line if there's not enough space to display all of it. I've tried so many different versions of white-space and line-break I've run out of ideas.
On top of that IE doesn't display full width at all. I don't want to give my div a fixed width. I want it to dynamically wrap when there's no more space in the parent.
My desired result would be something like that in both IE and Chrome
.info-tooltip {
position: relative;
display: inline;
top: 1px;
cursor: default;
white-space: pre;
}
.info-tooltip:before {
content: url("https://image.flaticon.com/icons/svg/685/685815.svg");
width: 20px;
height: 20px;
display: inline-block;
}
/* Tooltip text */
.info-tooltip .info-tooltip-text {
visibility: hidden;
background-color: #0BC6DD;
color: #fff;
border-radius: 4px;
font-size: 14px;
/* Position the tooltip text */
position: absolute;
top: 37px;
left: -50px;
display: table;
z-index: 1;
padding: 8px 8px 4px 8px ;
/* Fade in tooltip */
opacity: 0;
transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
-moz-transition: opacity 0.3s;
-ms-transition: opacity 0.3s;
-o-transition: opacity 0.3s;
transition: opacity 0.3s;
}
/* Tooltip arrow */
.info-tooltip .info-tooltip-text::after {
content: "";
position: absolute;
bottom: 100%;
left: 60px;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #0BC6DD transparent;
}
/* Show the tooltip text when you mouse over the tooltip container */
.info-tooltip:hover .info-tooltip-text {
visibility: visible;
opacity: 1;
}
.info-tooltip .info-tooltip-text p {
padding-bottom: 4px;
margin: 0;
font-weight: 100;
}
<h1>There is a tooltip next to me <i class="info-tooltip"/>
<div class="info-tooltip-text">
<p>This is the actual tooltip to be displayed. A bit longer than expected. Should wrap where necessary.</p>
</div>
</i></h1>

added
width: 250px;
white-space: normal;
to .info-tooltip .info-tooltip-text p
.info-tooltip {
position: relative;
display: inline;
top: 1px;
cursor: default;
white-space: pre;
}
.info-tooltip:before {
content: url("https://image.flaticon.com/icons/svg/685/685815.svg");
width: 20px;
height: 20px;
display: inline-block;
}
/* Tooltip text */
.info-tooltip .info-tooltip-text {
visibility: hidden;
background-color: #0BC6DD;
color: #fff;
border-radius: 4px;
font-size: 14px;
/* Position the tooltip text */
position: absolute;
top: 37px;
left: -50px;
display: table;
z-index: 1;
padding: 8px 8px 4px 8px;
/* Fade in tooltip */
opacity: 0;
transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
-moz-transition: opacity 0.3s;
-ms-transition: opacity 0.3s;
-o-transition: opacity 0.3s;
transition: opacity 0.3s;
}
/* Tooltip arrow */
.info-tooltip .info-tooltip-text::after {
content: "";
position: absolute;
bottom: 100%;
left: 60px;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #0BC6DD transparent;
}
/* Show the tooltip text when you mouse over the tooltip container */
.info-tooltip:hover .info-tooltip-text {
visibility: visible;
opacity: 1;
}
.info-tooltip .info-tooltip-text p {
padding-bottom: 4px;
margin: 0;
font-weight: 100;
width: 250px;
white-space: normal;
}
<h1>There is a tooltip next to me <i class="info-tooltip" />
<div class="info-tooltip-text">
<p>This is the actual tooltip to be displayed. A bit longer than expected. Should wrap where necessary.</p>
</div>
</i>
</h1>

Related

IE - Radio button checked with styles makes the page scrolling down

I am encountering a problem with a radio button in IE 11.
I have a simple radio button that makes my content scroll down once checked.
Without any styles applied, there is no problem. But with, the problem is back.
Does it have something to do with the IE render engine?
.switch {
position: relative;
display: block;
width: 34px;
height: 18px;
border-radius: 8px;
cursor: pointer;
outline: 0;
height: 18px;
top: 5px;
background-color: $grey-light;
box-shadow: $switch-shadow;
&::before {
content: " ";
position: absolute;
left: 2px;
top: 2px;
border-radius: 50%;
margin: 0;
outline: none;
height: 14px;
width: 14px;
background: white;
transition: background-color .08s ease-in;
}
&.active::before {
background-color: $green-dark;
left: 18px;
transition: background-color .08s ease-in, left .08s ease-in;
}
&.inactive::before {
background-color: $grey-dark;
left: 2px;
transition: background-color .08s ease-in, left .08s ease-in;
}
input[type=checkbox] {
// display: none;
visibility: hidden;
position: absolute;
z-index: -1;
}
}
Thanks for your help!
EDIT.
I forgot to precise that the scrolling box (flex: 1) has a parent which has display: flex.

Button Padding Not Working

I have an image banner which I'm trying to add a button on top of it. The button is in HTML format and not an image. However, the problem is that I'm unable to move the button on top of the image. I believe it has to do with the margin of the button. I've implemented the following codes into my Weebly website, and though the button seems to fit perfectly well inside the editor, after publishing, the button displays on the bottom of the banner. Here is my HTML code:
The "margin:-70px" seems to be correct, though it doesn't apply after publishing. So what's wrong? Is there something missing?
.btn_action_1 {
border: 5px solid #000 !important;
/* Change button border color */
color: #000 !important;
/* Change button text color */
font-size: 22px;
font-family: 'Ubuntu';
line-height: 0;
display: inline-block;
padding: 10px 15px 10px;
position: relative;
text-decoration: none;
z-index: 3;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.btn_action_1 span {
left: 10px;
position: relative;
-o-transition: all .4s;
-moz-transition: all .4s;
-webkit-transition: all .4s;
transition: all .4s;
}
.btn_action_1 .ico_arrow {
background: url(ico_arrow_w.png) 0 center no-repeat;
display: inline-block;
height: 17px;
width: 17px;
position: relative;
left: -12px;
top: 0px;
opacity: 0;
filter: alpha(opacity=0);
-o-transition: all .4s;
-moz-transition: all .4s;
-webkit-transition: all .4s;
transition: all .4s;
}
.btn_action_1:hover {
background: #000 !important;
/* Change button background color when mouse over */
color: #fff !important;
/* Change button text color when mouse over */
}
.btn_action_1:hover span {
left: -5px;
}
.btn_action_1:hover .ico_arrow {
opacity: 1;
filter: alpha(opacity=100);
left: 5px;
}
#media (max-width: 479px) {
.btn_action_1 {
padding: 18px 30px;
}
}
.btn_action_1:not(:hover)>.hover,
.btn_action_1:hover>.default {
display: none
}
<img src="http://unlckpaypal.weebly.com/uploads/6/3/8/8/63884033/left_banner.png" style="margin: 10px 0px 0px 0px;width:440px;height:210px;">
<a href="http://unlckpaypal.weebly.com/trending-127809.html" style="margin:-70px 0px 0px 200px;width:180px;height:45px;" class="btn_action_1">
<span>SHOP NOW</span>
<i class="ico_arrow"></i>
</a>
Give this code to padding: 10px 15px 10px; to .btn_action_1 span this class, I think it will work
.btn_action_1 {
border: 5px solid #000 !important; /* Change button border color */
color: #000 !important; /* Change button text color */
font-size: 22px;
font-family: 'Ubuntu';
line-height: 0;
display: inline-block;
padding: 10px 15px 10px;
position: relative;
text-decoration: none;
z-index: 3;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.btn_action_1 span {
left: 10px;
position: relative;
-o-transition: all .4s;
-moz-transition: all .4s;
-webkit-transition: all .4s;
transition: all .4s;
}
.btn_action_1 .ico_arrow {
background: url(ico_arrow_w.png) 0 center no-repeat;
display: inline-block;
height: 17px;
width: 17px;
position: relative;
left: -12px;
top: 0px;
opacity: 0;
filter: alpha(opacity=0);
-o-transition: all .4s;
-moz-transition: all .4s;
-webkit-transition: all .4s;
transition: all .4s;
}
.btn_action_1:hover {
background: #000 !important; /* Change button background color when mouse over */
color: #fff !important; /* Change button text color when mouse over */
}
.btn_action_1:hover span {
left: -5px;
}
.btn_action_1:hover .ico_arrow {
opacity: 1;
filter: alpha(opacity=100);
left: 5px;
}
#media (max-width: 479px) {
.btn_action_1 {
padding: 18px 30px;
}
}
.btn_action_1:not(:hover)>.hover,
.btn_action_1:hover>
.default {display:none}
<img src="http://unlckpaypal.weebly.com/uploads/6/3/8/8/63884033/left_banner.png"
style="margin: 10px 0px -50px 0px;width:440px;height:210px; position:relative;">
<a href="http://unlckpaypal.weebly.com/trending-127809.html"
style="margin:-30px 10px 10px 220px;width:180px;height:45px; "
class="btn_action_1">
<span>SHOP NOW</span>
<i class="ico_arrow"></i>
</a>
Just add this class
.img-wrapper .btn_action_1{
display:block;
margin-top:-100px
}
Fiddler https://jsfiddle.net/ov9rxuys/
i recommend using absolute position for the button since there is no alternative
.btn_action_1 {
position: absolute; /* remove margin from HTML if possible */
bottom: 20px; /* adjust as you want it to be */
right: 50px; /* adjust as you want it to be */
}
i have jsfiddle for it https://jsfiddle.net/Ls6coLb7/

Tool-tip with scroll. Scroll is disappearing when mouse hover on arrows.

Hi the tooltip in this sniped closes when trying to hover on the arrows of the scroll. With the mouse scroll it works fine but i need it to work with mousehover.
Got any suggestions?
Thank you in advance
.wrapper{
position:relative;
}
.tooltip {
transform: none;
margin: 50px;
}
.tooltip:hover > .tooltip-text, .tooltip:hover > .wrapper {
pointer-events: auto;
opacity: 1.0;
}
.tooltip > .tooltip-text, .tooltip >.wrapper {
display: block;
position: absolute;
z-index: 6000;
overflow: visible;
padding: 5px 8px;
margin-top: 10px;
line-height: 16px;
border-radius: 4px;
text-align: left;
color: #fff;
background: #000;
pointer-events: none;
opacity: 0.0;
-o-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
/* Arrow */
.tooltip > .tooltip-text:before, .tooltip > .wrapper:before {
display: inline;
top: -5px;
content: "";
position: absolute;
border: solid;
border-color: rgba(0, 0, 0, 1) transparent;
border-width: 0 .5em .5em .5em;
z-index: 6000;
left: 20px;
}
/* Invisible area so you can hover over tooltip */
.tooltip > .tooltip-text:after, .tooltip > .wrapper:after {
top: -20px;
content: " ";
display: block;
height: 20px;
position: absolute;
width: 60px;
left: 20px;
}
.wrapper > .tooltip-text {
overflow-y: auto;
max-height: 100px;
display: block;
}
<div class="tooltip tooltip-scroll">Hover over me for scrollbar
<div class="wrapper">
<span class="tooltip-text">Hello there<br/>Hello there<br/>Hello there<br/>Hello there<br/>Hello there<br/>Hello there<br/>abc<br/>def<br/><br/>def<br/><br/>def<br/><br/>def<br/>ghi<br/>jkl<br/></span>
</div>
</div>
based on my try-error research, I got a solution for webkit based on applying styles to "force" the browser to handle the scrollbar as another page element:
.tooltip.tooltip-scroll ::-webkit-scrollbar {
background-color: #F1F1F1;
}
.tooltip.tooltip-scroll ::-webkit-scrollbar-thumb {
background-color: #C1C1C1;
border: 1px solid #F1F1F1;
}
/* optional */
.tooltip.tooltip-scroll ::-webkit-scrollbar-button {
background-color: #F1F1F1;
}
(More examples on how to style the scrollbar #CSS-Tricks.)
Also, here goes an extra help.
Change style .tooltip for this:
.tooltip {
transform: none;
padding: 10px;
}
The padding allows the element that triggers the tooltip to do not lose the :hover state when moving the mouse pointer from the element to the tooltip. Since the padding area is still considered part of the element.
Note for Stack Overflow community: please, feel free to provide extra information on how this works.

HTML+CSS tooltip: Weird behavior in table with rowspan

I have created a html table which contains tooltips for each cell. I don't understand at this point, why most of the tooltips are drawn above the table while some of the tooltips are covered by neighbouring cells? I just played around with the z-index, but could get it working properly.
Do you you have any ideas?
Since I am not allowed to post images, here is only a link:
Comparing image of working and non working tooltip
Please don't take the css stuff too serious, I am no web developer, I just wanted a quick html table solution.
So the example can be found right here:
https://jsfiddle.net/6foqnLkm/
The related tooltip css code (found on the web)
/* Hide the tooltip content by default */
[data-tooltip]:before,
[data-tooltip]:after {
visibility: hidden;
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
opacity: 0;
pointer-events: none;
-moz-transition: ease 0.5s all;
-o-transition: ease 0.5s all;
-webkit-transition: ease 0.5s all;
transition: ease 0.5s all;
}
/* Position tooltip above the element */
[data-tooltip]:before {
position: absolute;
bottom: 110%;
left: 50%;
margin-bottom: 5px;
margin-left: -80px;
padding: 7px;
width: 160px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
background-color: black;
color: #fff;
content: attr(data-tooltip);
text-align: center;
font-size: 14px;
line-height: 1.2;
}
/* Triangle hack to make tooltip look like a speech bubble */
[data-tooltip]:after {
position: absolute;
bottom: 110%;
left: 50%;
margin-left: -5px;
width: 0;
border-top: 5px solid black;
border-right: 5px solid transparent;
border-left: 5px solid transparent;
content: " ";
font-size: 0;
line-height: 0;
}
/* Show tooltip content on hover */
[data-tooltip]:hover:before,
[data-tooltip]:hover:after {
visibility: visible;
bottom: 90%;
filter: progid:DXImageTransform.Microsoft.Alpha(enabled=false);
opacity: 1;
display: block;
white-space: pre-wrap;
}
Remove "z-index : 2" in [data-tooltip] and add "z-index: 9" in [data-tooltip]:before
[data-tooltip] {
position: relative;
cursor: pointer;
}
[data-tooltip]:before {
z-index:9;
position: absolute;
bottom: 110%;
left: 50%;
margin-bottom: 5px;
margin-left: -80px;
padding: 7px;
width: 160px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
background-color: black;
color: #fff;
content: attr(data-tooltip);
text-align: center;
font-size: 14px;
line-height: 1.2;
}
Try this
[data-tooltip]:before {z-index:9;}
Click here for Demo

Tooltip with HTML content without JavaScript

There are plenty of JavaScript-based libraries that show tooltips when you hover your mouse over a certain area of a web page. Some are rather plain, some allow the tooltip to display HTML content styled with CSS.
But is there a way to show a styled tooltip without using JavaScript? If you just use the title attribute, tags are not processed (e.g. foo<br />bar doesn't produce a line break). I'm looking for a solution that allows one to display styled HTML content without using any JavaScript.
I have made a little example using css
.hover {
position: relative;
top: 50px;
left: 50px;
}
.tooltip {
/* hide and position tooltip */
top: -10px;
background-color: black;
color: white;
border-radius: 5px;
opacity: 0;
position: absolute;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
-ms-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
transition: opacity 0.5s;
}
.hover:hover .tooltip {
/* display tooltip on hover */
opacity: 1;
}
<div class="hover">hover
<div class="tooltip">asdadasd
</div>
</div>
FIDDLE
http://jsfiddle.net/8gC3D/471/
Using the title attribute:
Link
Similar to koningdavid's, but works on display:none and block, and adds additional styling.
div.tooltip {
position: relative;
/* DO NOT include below two lines, as they were added so that the text that
is hovered over is offset from top of page*/
top: 10em;
left: 10em;
/* if want hover over icon instead of text based, uncomment below */
/* background-image: url("../images/info_tooltip.svg");
/!* width and height of svg *!/
width: 16px;
height: 16px;*/
}
/* hide tooltip */
div.tooltip span {
display: none;
}
/* show and style tooltip */
div.tooltip:hover span {
/* show tooltip */
display: block;
/* position relative to container div.tooltip */
position: absolute;
bottom: 1em;
/* prettify */
padding: 0.5em;
color: #000000;
background: #ebf4fb;
border: 0.1em solid #b7ddf2;
/* round the corners */
border-radius: 0.5em;
/* prevent too wide tooltip */
max-width: 10em;
}
<div class="tooltip">
hover_over_me
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis purus dui. Sed at orci. </span>
</div>
This one is very interesting,
HTML and CSS only
.help-tip {
position: absolute;
top: 18px;
left: 18px;
text-align: center;
background-color: #BCDBEA;
border-radius: 50%;
width: 24px;
height: 24px;
font-size: 14px;
line-height: 26px;
cursor: default;
}
.help-tip:before {
content: '?';
font-weight: bold;
color: #fff;
}
.help-tip:hover span {
display: block;
transform-origin: 100% 0%;
-webkit-animation: fadeIn 0.3s ease-in-out;
animation: fadeIn 0.3s ease-in-out;
}
.help-tip span {
display: none;
text-align: left;
background-color: #1E2021;
padding: 5px;
width: 200px;
position: absolute;
border-radius: 3px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
left: -4px;
color: #FFF;
font-size: 13px;
line-height: 1.4;
}
.help-tip span:before {
position: absolute;
content: '';
width: 0;
height: 0;
border: 6px solid transparent;
border-bottom-color: #1E2021;
left: 10px;
top: -12px;
}
.help-tip span:after {
width: 100%;
height: 40px;
content: '';
position: absolute;
top: -40px;
left: 0;
}
<span class="help-tip">
<span > This is the inline help tip! </span>
</span>
Pure CSS:
.app-tooltip {
position: relative;
}
.app-tooltip:before {
content: attr(data-title);
background-color: rgba(97, 97, 97, 0.9);
color: #fff;
font-size: 12px;
padding: 10px;
position: absolute;
bottom: -50px;
opacity: 0;
transition: all 0.4s ease;
font-weight: 500;
z-index: 2;
}
.app-tooltip:after {
content: '';
position: absolute;
opacity: 0;
left: 5px;
bottom: -16px;
border-style: solid;
border-width: 0 10px 10px 10px;
border-color: transparent transparent rgba(97, 97, 97, 0.9) transparent;
transition: all 0.4s ease;
}
.app-tooltip:hover:after,
.app-tooltip:hover:before {
opacity: 1;
}
<div href="#" class="app-tooltip" data-title="Your message here"> Test here</div>
Another similar way to do it with CSS:
#img { }
#img:hover {visibility:hidden}
#thistext {font-size:22px;color:white }
#thistext:hover {color:black;}
#hoverme {width:50px;height:50px;}
#hoverme:hover {
background-color:green;
position:absolute ;
left:300px;
top:100px;
width:40%;
height:20%;
}
<p id="hoverme"><img id="img" src="http://a.deviantart.net/avatars/l/o/lol-cat.jpg"></img><span id="thistext">LOCATZ!!!!</span></p>
Try the Js Fiddle
Here are some links about transitions and other ways to do it:
http://www.w3schools.com/css3/css3_transitions.asp
http://dev.opera.com/articles/view/css3-show-and-hide/
You can use the title attribute, e.g. if you want to have a Tooltip over a text, just make:
<span title="This is a Tooltip">This is a text</span>
This is my solution for this:
https://gist.github.com/BryanMoslo/808f7acb1dafcd049a1aebbeef8c2755
The element recibes a "tooltip-title" attribute with the tooltip text and it is displayed with CSS on hover, I prefer this solution because I don't have to include the tooltip text as a HTML element!
#HTML
<button class="tooltip" tooltip-title="Save">Hover over me</button>
#CSS
body{
padding: 50px;
}
.tooltip {
position: relative;
}
.tooltip:before {
content: attr(tooltip-title);
min-width: 54px;
background-color: #999999;
color: #fff;
font-size: 12px;
border-radius: 4px;
padding: 9px 0;
position: absolute;
top: -42px;
left: 50%;
margin-left: -27px;
visibility: hidden;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:after {
content: "";
position: absolute;
top: -9px;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #999999 transparent transparent;
visibility: hidden;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:hover:before,
.tooltip:hover:after{
visibility: visible;
opacity: 1;
}