I wanted to have multiple tooltips within a text on my website. I have tried to use both span and div tags to make a tooltip with CSS only and it worked for the most purt, however I have trouble positioning the tooltiptext correctly. It is supposed to show up above the hoverable word, but currently it just shows up in the line below on the left. My code:
.tooltip {
position: relative;
display: inline;
text-decoration: underline dotted black;
}
.tooltip:hover .tooltiptext {
display: block;
position: absolute;
z-index: 3;
padding: 0.3vw;
}
.tooltiptext {
display: none;
color: white;
background-color: black;
border-radius: 0.3vw;
}
<p>Lorem ipsum dolor sit amet,
<span class="tooltip"> consectetuer<span class="tooltiptext"> Some Text</span></span>
adipiscing elit. Aenean commodo ligula eget dolor.</p>
Are there any solutions to this problem?
I suppose you wanted something like this.
p {
padding:10px;
}
.tooltip {
position: relative;
display: inline;
text-decoration: underline dotted black;
}
.tooltip:hover .tooltiptext {
display: block;
position: absolute;
z-index: 3;
padding: 0.3vw;
left:50%;
top:-19px;
transform:translateX(-50%);
width:100%;
text-align:center;
}
.tooltiptext {
display: none;
color: white;
background-color: black;
border-radius: 0.3vw;
}
<p>Lorem ipsum dolor sit amet,
<span class="tooltip"> consectetuer<span class="tooltiptext"> Some Text</span></span>
adipiscing elit. Aenean commodo ligula eget dolor.</p>
Related
How can I keep a label and it's text starting on the same place?
For example, what I want to achieve:
☑️ Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
And here is my attempt:
div {
width:300px;
}
label:before {
content: "";
display: inline-block;
margin-right: 10px;
height: 15px;
width: 15px;
border: 2px solid #666;
border-radius: 3px;
background-color: #fff;
transition: background-color 0.2s;
}
<div>
<label>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at molestie mi.</label>
</div>
You could use flexbox from CSS like so:
div {
width:300px;
}
/* lines I added */
label{
display: flex;
align-items:flex-start;
}
label:before {
content: "";
display: inline-block;
margin-right: 10px;
height: 15px;
width: 15px;
/* line I added */
flex:none;
border: 2px solid #666;
border-radius: 3px;
background-color: #fff;
transition: background-color 0.2s;
}
<div>
<label>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at molestie mi.</label>
</div>
I've text to show inside a tooltip on hover of an icon.
The tooltips width need to be:
max-width:300px
if the text fit in one line and less than 300px, adjust to text width
if the text need many lines, the tooltip width need to be 300px
How can I define the .tooltip .content-tooltip to work like describe before ?
I've tried using white-space: nowrap; and some word-break ...
.tooltip {
position: relative;
margin-right: 5px;
display: block;
text-align: center;
width: 75px;
padding: 5px;
border: 1px dotted #000;
margin: 70px auto;
}
.tooltip .content-tooltip {
position: absolute;
bottom: calc(100% + 13px);
background: #000;
color: #fff;
display: block;
left: 50%;
transform: translateX(-50%);
padding: 5px 10px 6px;
display: none;
text-align: left;
max-width: 300px;
width: auto;
}
.tooltip:hover .content-tooltip {
display: block;
}
<h1>Example</h1>
<span class="tooltip">
short text
<span class="content-tooltip">
Lorem
</span>
</span>
<span class="tooltip">
long text
<span class="content-tooltip">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla nunc massa, eleifend a feugiat ac, varius eu eros.
Praesent at vulputate risus. Pellentesque dictum pulvinar lectus.
</span>
</span>
<hr><hr>
<h1>What I expect</h1>
<span class="tooltip">
short text
<span class="content-tooltip">
Lorem
</span>
</span>
<span class="tooltip">
long text
<span class="content-tooltip" style="width: 300px">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla nunc massa, eleifend a feugiat ac, varius eu eros.
Praesent at vulputate risus. Pellentesque dictum pulvinar lectus.
</span>
</span>
I fixed the issue by taking out the tooltip from the text content element, and wrapped the tooltip and text content width another div which will act container for both of them, so that tooltip won't take up the width as per the text content instead it will take the width as specified.
This how you should do it:
body {
display: flex;
gap: 30px;
padding: 1rem;
}
.text {
padding: 10px;
}
.tooltip {
display: none;
position: absolute;
background: #000;
color: #fff;
max-width: 300px;
padding: 10px;
}
.text-contianer:hover > .tooltip {
display: inline-block;
}
<div class="text-contianer">
<div class="text">
Short
</div>
<span class="tooltip">
Lorem
</span>
</div>
<div class="text-contianer">
<div class="text">
Long
</div>
<span class="tooltip">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla nunc massa, eleifend a feugiat ac, varius eu eros.
Praesent at vulputate risus. Pellentesque dictum pulvinar lectus.
</span>
</div>
The desired solution can be attained if you set a height value to the tooltip.
I see that you've used max-width, which is the desirable here but one thing which I guess you missed is that the default value of height for tooltip is auto, due to which if you reduce the width of the tooltip, the component will adjust to increase the height. One simple solution as I mentioned is to set a height value, and overflow to hidden
Updated CSS Code:
.tooltip {
position: relative;
margin-right: 5px;
display: block;
text-align: center;
width: 75px;
padding: 5px;
border: 1px dotted #000;
margin: 70px auto;
}
.tooltip .content-tooltip {
position: absolute;
bottom: calc(100% + 13px);
background: #000;
color: #fff;
display: block;
left: 50%;
transform: translateX(-50%);
padding: 5px 10px 6px;
display: none;
text-align: left;
max-width: 320px;
height: 15px; //height value set to avoid component auto adjust
overflow: hidden; //overflow hidden
}
.tooltip:hover .content-tooltip {
display: block;
}
Found myself a solution :
.tooltip {
position: relative;
margin-right: 5px;
display: block;
text-align: center;
width: 75px;
padding: 5px;
border: 1px dotted #000;
margin: 70px auto;
}
.tooltip .sizing-tooltip {
position: absolute;
bottom: calc(100% + 13px);
left: 50%;
transform: translateX(-50%);
display: none;
width: 300px;
}
.tooltip .content-tooltip {
background: #000;
color: #fff;
padding: 5px 10px 6px;
display: block;
text-align: left;
max-width: 300px;
width: auto;
margin: 0 auto;
}
.tooltip:hover .sizing-tooltip {
display: flex;
}
<h1>Example</h1>
<span class="tooltip">
short text
<span class="sizing-tooltip">
<span class="content-tooltip">
Lorem
</span>
</span>
</span>
<span class="tooltip">
long text
<span class="sizing-tooltip">
<span class="content-tooltip">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla nunc massa, eleifend a feugiat ac, varius eu eros.
Praesent at vulputate risus. Pellentesque dictum pulvinar lectus.
</span>
</span>
</span>
I have this image I am trying to replicate:
Basically, I want the border to go around the image and cut off within a certain distance.
I cannot seem to get the border to cut off.
This is the HTML for this quote and image
<div class="quote-container">
<img class="testimonial-img" src="./Photos/StethoscopeVector.png" alt="">
<div class="quote-container-text">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
CSS for Quote and Image
.quote-container {
padding: 5em 0;
height: 100%
}
.testimonial-img {
position: absolute;
margin-left: 11.5em;
margin-top: -3em;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border: 2px solid white;
width: 65%;
padding: 2em;
margin: auto;
}
Which currently looks like this image:
I have tried using shape-outside but it doesn't work and I believe it's because the image is being set to absolute.
This is the stethoscope image. White image, no background.
first of all move your image inside of your container-text and then give border to the right and bottom of it and use pseudo selectors :after and :before for the left border and top border.
for more explanation please refer this snippet.
.quote-container {
padding: 5em 0;
height: 100%;
}
.testimonial-img {
position: absolute;
top: -50px;
left: -13px;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border-right: 2px solid white;
border-bottom: 2px solid #fff;
width: 65%;
padding: 2em;
margin: auto;
position: relative;
}
.quote-container-text:before {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 2px;
height: calc(100% - 60px);
background-color: #fff;
}
.quote-container-text:after {
position: absolute;
height: 2px;
width: calc(100% - 100px);
right: 0;
top: 0;
content: "";
background-color: #fff;
}
<body style="background-color: #2196F3">
<div class="quote-container">
<div class="quote-container-text">
<img class="testimonial-img" src="https://i.stack.imgur.com/nj8on.png" alt="">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
</body>
for background-image instead of bg-color.
.quote-container {
padding: 5em 0;
height: 100%;
background-image: url('https://media.istockphoto.com/photos/vintage-retro-grungy-background-design-and-pattern-texture-picture-id656453072?k=6&m=656453072&s=612x612&w=0&h=4TW6UwMWJrHwF4SiNBwCZfZNJ1jVvkwgz3agbGBihyE=');
background-repeat: no-repeat;
background-size: cover;
}
.testimonial-img {
position: absolute;
top: -50px;
left: -13px;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border-right: 2px solid white;
border-bottom: 2px solid #fff;
width: 65%;
padding: 2em;
margin: auto;
position: relative;
}
.quote-container-text:before {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 2px;
height: calc(100% - 60px);
background-color: #fff;
}
.quote-container-text:after {
position: absolute;
height: 2px;
width: calc(100% - 100px);
right: 0;
top: 0;
content: "";
background-color: #fff;
}
<body>
<div class="quote-container">
<div class="quote-container-text">
<img class="testimonial-img" src="https://i.stack.imgur.com/nj8on.png" alt="">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
</body>
Thank You...
Your image has a transparent background, and it appears above the border. To fix that, you can set the border on an absolutely positioned pseudo-element (::before), and use clip-path to remove the top left corner:
.quote-container {
padding: 5em;
background: steelblue;
}
.quote-container-text {
position: relative;
width: 65%;
padding: 2em;
margin: auto;
text-align: center;
color: white;
}
.quote-container-text::before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: 2px solid white;
clip-path: polygon(55px 0%, 100% 0%, 100% 100%, 0% 100%, 0% 55px, 55px 55px);
content: '';
}
.testimonial-img {
position: absolute;
top: 0;
left: 0;
transform: translate(-50%, -50%);
}
body {
margin: 0;
}
<div class="quote-container">
<div class="quote-container-text">
<img class="testimonial-img" src="https://i.stack.imgur.com/nj8on.png" alt="">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/> adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
An easy way to do this would be to use an image with a background color the same as the background color of the outermost container. Also, it's important to realize that setting something to absolute will make it absolute to the innermost container that has a relative positioning. Note that I used some random image from the web for the example, but you can conform it to your image. If you want your transparent image to have a background, wrap it in a div and set the background of the div.
First move the image inside the quote container text.
<div class="quote-container">
<div class="quote-container-text">
<div id="test-img-container">
<img class="testimonial-img" src="https://cdn3.iconfinder.com/data/icons/medical-174/100/healthy-06-512.png" alt="">
</div>
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
Next set the image to absolute with top and left stylings and make the quote-container-text element to be relatively positioned:
.quote-container {
padding: 5em 0;
height: 100%;
background:steelblue;
}
#test-img-container{
position: absolute;
left:-25px;
top:-25px;
background:steelblue;
}
.testimonial-img {
width:50px;
height:auto;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border: 2px solid white;
width: 65%;
padding: 2em;
position:relative;
margin: auto;
}
Also note that this works best if you specify a hard width to the image so that you can evenly use the margin stylings on the image.
https://jsfiddle.net/dgf1ms8r/7/
I need to add an image to overlay a play button only when you hover over an image, I have it somewhat working, however I can't get it over the image, it only shows up behind the image. I've tried setting the Z-index to be higher but it still wont' work.
Here is my markup for the HTML
<div class="articles"><img alt="image1" src="Resources/092812newshubgmtseg1b_167x94.jpg">
<figcaption>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Beatus sibi videtur. 3:40</figcaption>
</div>
and here is my CSS
.articles img {
width: 143px;
height: 85px;
z-index: 1;
}
.articles img:hover {
border-bottom: 5px #2ecc71 solid;
border-top: 5px #2ecc71 solid;
z-index: 1;
}
.articles:hover{
color:#2ecc71;
background: url(Resources/play.png);
z-index:10;
}
First: parent elements will never get "on top" of their child elements. So setting .article to a higher z-index than its child .article img will never work.
You could use the :after pseudo selector to dynamically add some extra content to the .article element on :hover. Here's an example:
.articles img {
width: 143px;
height: 85px;
}
.articles img:hover {
border-bottom: 5px #2ecc71 solid;
border-top: 5px #2ecc71 solid;
}
.articles:hover:after{
content: " ";
display: block;
position: absolute;
left: 70px;
top: 40px;
width: 40px;
height: 20px;
color: #2ecc71;
background: url("http://dummyimage.com/40x20/666666/fff&text=PLAY");
}
<div class="articles">
<img alt="image1" src="http://dummyimage.com/143x85/666/fff">
<figcaption>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Beatus sibi videtur. 3:40</figcaption>
</div>
Please check out this solution jsfiddle, hope it will help you
.articles img {width:143px;height:85px;z-index:1;}
.articles img:hover {border-bottom: 5px #2ecc71 solid;border-top: 5px #2ecc71 solid;z-index: 1;}
.top {Position:absolute;z-index:999;top:5px;opacity:0;}
.top:hover{opacity:1;}
.behind {position:relative;z-index:10;}
<div class="articles"><div class="behind"><img alt="image1" src="http://media.marketwatch.com/video/20120928/092812newshubgmtseg1b/092812newshubgmtseg1b_1280x720.jpg"></div><div class="top"><img style="z-index:1;position:absolute;" alt="image1" src="http://wyeoakmusic.com/site/wp-content/plugins/haiku-minimalist-audio-player/resources/play.png"></div>
<figcaption>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Beatus sibi videtur. 3:40</figcaption>
</div>
I'm trying to determine if there is a way to style inline headers that span multiple lines using a background color.
The issue I'm having is with the padding is broken on any lines that wrap.
Example
CSS and HTML
h1 {
display: inline;
padding: 20px;
background: purple;
font-family: sans-serif;
color: #fff;
line-height: 60px;
}
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel scelerisque neque.</h1>
Here is the link to my fiddle
Any help would be appreciated
After looking at the image you posted this is the solution I came up with:
CSS and HTML
.header-container{
position: relative;
background: purple;
overflow: hidden;
padding: 20px;
}
h1 {
display: inline;
font-family: sans-serif;
color: #fff;
line-height: 60px;
}
h1:after{
content: '';
width: 100%;
background-color: #fff; /*your page bg color*/
height: 50px;
position: absolute;
bottom: 0;
margin-left: 20px;
}
<div class="header-container">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel scelerisque neque.</h1>
</div>
Here's the updated JSFiddle
try
http://jsfiddle.net/hMMxM/10/
$("h1").each(function()
{
var headerContent = $(this).text().split(' ');
for (var i = 1; i < headerContent.length; i++)
{
headerContent[i] = '<span class="subhead">' + headerContent[i] + '</span>';
}
$(this).html(headerContent.join(' '));
}
);
Why not wrap it in a container with padding? And then remove padding and line height from the h1.
CSS and HTML
div {
padding:20px;
}
h1 {
display: inline;
background: purple;
font-family: sans-serif;
color: #fff;
}
<div>
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vel scelerisque neque</h1>
</div>
Here is a working example: http://jsfiddle.net/hMMxM/5/