I'm trying to create a hover tooltip using inline CSS without JavaScript.
This is the code I have now
<a href="#"
style="{position:relative; top:50px; left:50px;}
:hover span {opacity:1; visibility:visible;}">
hover text
<span
style="top:-10px; background-color:black; color:white; border-radius:5px; opacity:0; position:absolute; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; -ms-transition: all 0.5s; -o-transition: all 0.5s; transition: all 0.5s; visibility:hidden;">
tooltip text
</span>
</a>
According to this it should be allowed: http://www.w3.org/TR/2002/WD-css-style-attr-20020515
I know this is not the recommended way to do it, but it needs to be usable where only inline CSS can be used.
You were pretty close, I've added some properties:
HTML Markup:
<a href="#" class="tooltip">hover text
<span>tooltip thisIsALongTextMadeToBeBreak</span>
</a>
CSS Markup:
a.tooltip {
position: relative;
top: 50px;
left: 50px;
}
a.tooltip:hover span {
opacity: 1;
visibility: visible;
}
a.tooltip span {
padding: 10px;
top: 20px;
min-width: 75px;
max-width: 150px;
background-color: #000000;
color: #FFFFFF;
height: auto;
border-radius: 5px;
opacity: 0;
position:absolute;
visibility: hidden;
word-wrap: break-word;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
Here's a live demo if you want to check it out
If you want, you can check it out some more examples/ideas here
Hope it helps!
try this sample.....
a.tooltip {
outline:none;
}
a.tooltip strong {
line-height:30px;
}
a.tooltip:hover {
text-decoration:none;
}
a.tooltip span {
z-index:10;
display:none;
padding:14px 20px;
margin-top:-30px;
margin-left:28px;
width:240px;
line-height:16px;
}
a.tooltip:hover span {
display:inline;
position:absolute;
color:#111;
border:1px solid #DCA;
background:#fffAF0;
}
.callout {
z-index:20;
position:absolute;
top:30px;
border:0;
left:-12px;
}
/*CSS3 extras*/
a.tooltip span {
border-radius:4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-moz-box-shadow: 5px 5px 8px #CCC;
-webkit-box-shadow: 5px 5px 8px #CCC;
box-shadow: 5px 5px 8px #CCC;
}
above css create a tooltip ...
for demo
JsFiddle demo
The top answer doesn't quite address the specific letter of the question (which as a comment suggests may just be impossible), but provides a valuable plug and play solution (if you have access to a stylesheet). I found myself in a similar situation, but where I wasn't able to modify the page style sheet (only insert html), so I thought i'd also give an answer that is effective but misses the specifics of the question.
In particular, should you be willing to use a little bit of javascript, then you can make use of this hacky approach:
<div
onMouseOver="this.children[0].style.display = 'block'"
onMouseOut="this.children[0].style.display = 'none';"
>Example Content
<span id="innerContent" style="
display: none;
background: #C8C8C8;
margin-left: 28px;
padding: 10px;
position: absolute;
z-index: 1000;
width:200px;
height:100px;">Inner Content</span>
</div>
The use of this.children instead of querySelector is intentional, as it makes it easier to just drop in, without the need for adjusting ids to get the inner element. This styling is drawn from this fiddle.
Related
I'm trying to make a hidden div to be reavelead using transition but I mess things up and it doesn't work.
I got a div on top of another but I have it hidden using the visibility property. Now when I hover over the bottom div (.hexagon) I have the top div (.product-text) displayed. Everything works just fine. Although I want to make it a little bit smoother using a transition, but it just doesn't work.
The css (I'm using Sass) :
(the bottom div):
.hexagon {
position: relative;
background-color: black;
width: 240px;
height: 138.56px;
margin: 69.28px 0;
border-left: solid 5px $honey;
border-right: solid 5px $honey;
display:flex;
justify-content: center;
img{
height:100%;
z-index: 1;
}
&:hover{
background-color:white;
cursor: pointer;
.product-text{
visibility: visible;
transition: visibility 3s;
}
}
}
.....
(the top div):
.product-text{
text-align: center;
font-size:18px;
color: black;
text-shadow: 2px 2px 3px $honey;
border-radius: 7px;
font-weight:bold;
opacity: 0.8;
z-index:2;
position:absolute;
bottom:0;
left:0;
width: 100%;
height:100%;
visibility:hidden;
background-color: rgba(15, 1, 1, 0.555);
p{
margin:0em;
}
}
You can't transition visibility (nor any other binary property). What you can do is an opacity transition.
.hexagon {
&:hover {
.product-text {
opacity: 1;
}
}
}
.product-text {
opacity: 0;
transition: opacity 3s;
}
You probably want the transition property applied directly to the class and not to the hover state.
Example:
.parent {
width: 200px;
height: 200px;
background-color: red;
}
.child {
width: 100px;
height: 100px;
background-color: blue;
opacity: 0;
transition: opacity 2s;
}
.parent:hover .child {
opacity: 1;
}
<div class="parent">
<div class="child"></div>
</div>
I need a button whose after selector expands and gets disappeared when clicked. I need this effect via CSS.
When i click this button it's after selector expands.
Like
#button::after{
transform: scale(2);
}
But this is not happening for me. Please help me. When clicked the after selector button should expand then should disappear. In a nutshell, i need button scaling effect.
Do you mean something like this?
As far as I know you can't get an onclick event with CSS only and without using JavaScript. You can use :active, but this will only apply the style when the mouse button is held down. See Bojangles answer on "Can I have an Onclick effect in CSS".
#button {
display: block;
border: none;
position: relative;
color: red;
background-color: white;
font-size: 30px;
padding: 15px 30px;
}
#button:after {
content: '';
position: absolute;
display: block;
height: 100%;
width: 100%;
top: 0;
left: 0;
border: 4px solid red;
color: black;
font-size: 8px;
opacity: 1;
transition: transform .3s ease, opacity .5s ease;
}
#button:active:after {
transform: scale(5);
opacity: 0;
}
<button id="button">BUTTON</button>
**The code snippet is built upon on benedikt's answer.
#button:after's border color is set to transparent, adds border-color during the animation. this creates the illusion that it disappears. I hope this helps.
#button {
display: block;
border: 4px solid red;
position: relative;
color: red;
background-color: white;
font-size: 30px;
padding: 15px 30px;
}
#button:after {
content: '';
position: absolute;
display: block;
width:100%;
height:100%;
top:0;
left:0;
border: 4px solid transparent;
color: black;
font-size: 8px;
opacity: 1;
transition: transform 0.3s ease, opacity 0.5s ease, border-color 0.1s ease;
}
#button:active:after {
transform: scale(2);
border-color:red;
opacity: 0;
}
<button id="button">BUTTON</button>
I'm trying to create a css effect on hover but that's don't work. I would like that the grey div don't move.
I use bootstrap 3 for the grid with 24px for the gutter (12px on each side).
This effect must be compatible with IE8.
Can I have some help please ?
.bgd-effect {
position: absolute;
height: 100%;
display: block;
left: 12px;
right: 12px;
background-color: blue;
z-index: 1;
}
.bgd-effect:hover {
left: 17px;
right: 8px;
}
Judging by the image you have used for your question the solution below is a simple one that will work on multiple different browser's.
CHECK IT OUT HERE: http://codepen.io/jacobg182/pen/Vvebxy
Simply add the following css using a pseudo hover effect:
.div:hover {
cursor: pointer;
-moz-box-shadow: 8px 15px 0px #00C2F1;
-webkit-box-shadow: 8px 15px 0px #00C2F1;
box-shadow: 8px 15px 0px #00C2F1;
-webkit-transition: all 500ms ease;
}
Also be sure to add a transition to the div without the pseudo hover state (Just to slow it down so it looks better)
.div {
transition: all 0.8s ease;
}
According to caniuse, you can use a pseudo element to create a copy and put it in the back.
.bgd-effect {
height: 100px;
width: 100px;
display: block;
background-color: black;
z-index: 2;
position:relative;
}
.bgd-effect:before {
content:"";
width:inherit;
height:inherit;
top:0;
left:0;
right:0;
bottom:0;
background-color: blue;
z-index:1;
position:absolute;
}
.bgd-effect:hover:before{
margin:10px;
}
First of all, I'm sorry if this question was already answered but I couldn't find it anywhere.
I'm trying to get a smooth transition when hovering over a div. On top of this div is another div, which gets visible when hovering. The transition didn't seem to do the trick, so how can I pull this off? (jquery instead of CSS, or other/better code?)
Maybe there's another way of doing this, I hope you guys can help me.
HTML:
<ul>
<li>
<div class="hover">
<a href="#">
<p>Test</p>
</a>
</div>
<img src="#" alt="img" />
<div class="text">
<p>Test</p>
</div>
</li>
</ul>
CSS:
body { background-color: #eee;
}
ul { margin: 0;
padding: 0;
list-style: none;}
ul li { width: 30.33%;
height: auto;
margin-right: 3%;
padding: 5px;
background-color: #fff;
float: left;
position: relative;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li img { width: 100%;
max-height: 100%;
z-index: 1;
background-color: #ddd;
border: 0;}
.text { width: 100%;
padding-top: 7%;}
.text p { margin: 0 10px;
padding-bottom: 7%;}
.hover { height: 100%;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 0;
display: none;}
.hover a { width:100%;
height: 100%;
margin: 0;
padding: 25px;
display: block;
color: #fff;
text-decoration: none;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li:hover > .hover { display: block;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;}
Here's the code: http://jsfiddle.net/HAFEx/
Thanks in advance!
A couple things need to be changed. Firstly, you can't animate the display property, so you should toggle opacity on hover instead.
Secondly, you should apply the transition on .hover, not just on parent:hover .hover so that it transitions both ways.
Using both of those improvements (and some formatting of your code) you get this result
.hover {
transition: all 0.2s ease;
opacity:0;
... Other properties ...
}
display:block can't be afected by a transition.
Instead use opacity.
.hover { height: 100%;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 0;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
opacity:0;
}
ul li:hover > .hover{
display: block;
opacity:1;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;
}
http://jsfiddle.net/Rjq3y/
You cannot transition css display. Try opacity.
http://jsfiddle.net/HAFEx/2/
ul li:hover .hover {
opacity:1;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;
}
You can also jquery to animate the display:none property.
$("li").mouseover(function(){
$(".hover").fadeIn(1000);
});
$(".hover").mouseout(function(){
$(".hover").fadeOut(1000);
});
Check out this codepen.
http://codepen.io/anon/pen/rqozA
The display property is a number or hexadecimal value, so it cannot be tweened. In this circumstance, you can't simply have the hover state opacity: 0.
Two work arounds are Javascript (messy) and using CSS Keyframe animations. http://hschwarz77.wordpress.com/2013/10/16/css-transition-from-display-none-to-display-block-on-hover/
To the best of my knowledge, these are the only solutions to have the div completely hidden (and unusable...visibility:hidden occupies the space) and fade in.
I got a pseudo-element that marks the user's current choice in a navigation bar. It's a small upward triangle, an icon font from Font-Awesome. here's a jsFiddle DEMO of it (you need to stretch the result panel so everything will be lined).
.subnav > ul > li.active > a:after {
position: relative;
text-align: center;
font-family: FontAwesome;
top: 25px;
right: 50%;
content: "\f0de";
color: #c1c1c1;
}
I've added some basic jQuery function that switches the .active class, and I'm wondering if there's a way to animate the transition of the pseudo element so it'll move horizontally to the new position.
I know pseudo-elements transition are a thing, but searching and googling around I couldn't find anything similar to what I'm looking for. Is this even possible?
In this solution I used the :target pseudo class to switch states, but I recommend you stick with the jQuery function that switches the .active class.
FIDDLE
Markup
<div class="page" id="one">page one</div>
<div class="page" id="two">page two</div>
<div class="page" id="three">page three</div>
<div class="top">
<div class="arrow"></div>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</div>
CSS
.top
{
background: #eee;
position:relative;
overflow: hidden;
}
.arrow
{
border-bottom: 1px solid #c2c2c2;
height: 50px;
}
.arrow:before
{
content: '';
display: block;
width: 14px;
height: 14px;
border: 1px solid #c2c2c2;
border-radius: 3px;
position:absolute;
bottom:-9px;
left: 30px;
background: #fff;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: left, 0.5s;
-moz-transition: left, 0.5s;
-o-transition: left, 0.5s;
transition: left, 0.5s;
}
ul
{
position: absolute;
top: 0;
list-style: none;
padding-left: 20px;
margin-top: 15px;
}
li
{
display: inline-block;
text-decoration: none;
font-size: 18px;
color: #676767;
margin-right: 40px;
}
.page
{
width: 100%;
height: 200px;
position: absolute;
top: 80px;
opacity: 0;
background: yellow;
-webkit-transition: opacity, 0.5s;
-moz-transition: opacity, 0.5s;
-o-transition: opacity, 0.5s;
transition: opacity, 0.5s;
}
.page:target
{
opacity: 1;
}
#two
{
background: pink;
}
#three
{
background: brown;
}
#one:target ~ .top .arrow:before
{
left: 30px;
}
#two:target ~ .top .arrow:before
{
left: 105px;
}
#three:target ~ .top .arrow:before
{
left: 189px;
}