Afternoon.
I am creating objects on an HTML page that display a tool-tip when you hover over the object.
I can't seem to get the tool tips to hover in front of all the objects. It only seems to sit in front of the one it relates too.
Below is an example:
.red
{
height: 75px;width: 75px;
background: red;
position: absolute;z-index: 1;
}
#red_tip
{
display: none;
}
.red:hover #red_tip
{
display: block;
background: blue;
position: absolute; z-index:2;
top:50px; left:50px;
width: 100px;
}
.green
{
height: 75px;width: 75px;
background: green;
position: absolute; z-index: 1;
top: 75px;
}
#green_tip
{
display: none;
}
.green:hover #green_tip
{
display: block;
background: blue;
position: absolute; z-index:2;
top:50px; left:50px;
width: 100px;
}
<div class="red">Red
<div id="red_tip">A tip for red goes here</div>
</div>
<div class="green">Green
<div id="green_tip">A tip for green goes here</div>
</div>
If you hover over the red box, you will see the tip sits behind the green box, I need it in front.
Many thanks,
Michael.
As long as the red and green divs have the same z-index, any higher z-indices within them don't actually make any difference. So you could simply give the red div a higher z-index than the green—as long as this order will reliably remain the same.
There's some useful info on z-index stacking contexts here: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context
Each stacking context is self-contained: after the element's contents are stacked, the whole element is considered in the stacking order of the parent stacking context.
just make green dive position to relative and z-index to -1
.red
{
height: 75px;width: 75px;
background: red;
position: absolute;z-index: 1;
}
#red_tip
{
display: none;
}
.red:hover #red_tip
{
display: block;
background: blue;
position: absolute; z-index:15;
top:50px; left:50px;
width: 100px;
}
.green
{
height: 75px;width: 75px;
background: green;
position: relative; z-index:-1;
top: 75px;
}
#green_tip
{
display: none;
}
.green:hover #green_tip
{
display: block;
background: blue;
position: absolute; z-index:2;
top:50px; left:50px;
width: 100px;
}
That's a tricky one. in the .red style, set its z-index: 2;.
.red
{
height: 75px;width: 75px;
background: red;
position: absolute;z-index: 2;
}
Removing the z-index from .red and .green should fix your issue. Additionally, you should set the body's margin to 0. This will help prevent the those two divs from overlapping as they currently do.
body {
margin: 0;
}
.red {
height: 75px;
width: 75px;
background: red;
position: absolute;
}
#red_tip {
display: none;
}
.red:hover #red_tip {
display: block;
background: blue;
position: absolute; z-index:2;
top:50px; left:50px;
width: 100px;
}
.green {
height: 75px;
width: 75px;
background: green;
position: absolute;
top: 75px;
}
#green_tip {
display: none;
}
.green:hover #green_tip {
display: block;
background: blue;
position: absolute; z-index:2;
top:50px; left:50px;
width: 100px;
}
You can also simplify it by wrapping your class like so and then all you have to do is call the class tooltips.
a.tooltips {
position: relative;
display: inline;
margin:50px 0 0 50px;
top:50px;
}
a.tooltips span {
position: absolute;
width:140px;
color: #FFFFFF;
background: #000000;
height: 30px;
line-height: 30px;
text-align: center;
visibility: hidden;
border-radius: 6px;
}
a.tooltips span:after {
content: '';
position: absolute;
top: 100%;
left: 50%;
margin-left: -8px;
width: 0; height: 0;
border-top: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
a:hover.tooltips span {
visibility: visible;
opacity: 0.8;
bottom: 30px;
left: 50%;
margin-left: -76px;
z-index: 999;
}
Then call it doing something like so
<a class="tooltips" href="#">CSS Tooltips
<span>Tooltip</span></a>
Check if you have any <div> not closed.
Related
Hi I've got follow div:
.box {
width: 100px;
height: 20px;
border: 1px solid black;
}
.box:after {
content: '';
width: 20px;
height: 20px;
background-color: blue;
}
<div class="box"></div>
I would like to add a second div to the .box with pseudo class after. I thought it would work like this, but nothing happens. It should look like this:
How to do this with after?
Thanks.
Try This
.box {
width: 100px;
height: 20px;
border: 1px solid black;
}
.box:after {
content: '';
width: 20px;
height: 20px;
background-color: blue;
display:block;
float:right;
}
<div class="box"></div>
You're code is right, the only thing missing is the property display to that element. Just add a display: block on the :after element. To easily manipulate the pseudo-element, make the main element position: relative, then the :after as position: absolute and place it based on the .box div, something like this :
.box {
width: 100px;
height: 20px;
border: 1px solid black;
position: relative; /* Made it relative */
}
.box:after {
content: '';
position: absolute;
display: block;
width: 20px;
height: 20px;
border: 1px solid blue;
top: -1px; /* To compensate the border on the main element */
background-color: blue;
left: 100%; /* To place it after the main element */
}
If you truly need another div, try adding some javascript, like this
$(document).ready(function() {
$('.box').append('<div class="another-box"></div>');
});
.box {
width: 100px;
height: 20px;
position: relative;
border: 1px solid black;
}
.box:after {
content: '';
width: 20px;
bottom: -1px;
right: -21px;
top: -1px;
position: absolute;
background-color: blue;
}
<div class="box"></div>
I have a div with a hamburger sign on, covered by another div. I want the burger sign to stack on top of everything. So I applied z-index values to the places I thought appropriate. However it doesn't work. Can anyone explain why? Here is my codepen below please take a look.
codepen:
http://codepen.io/tbeckett24/pen/qORBbE
html:
<body>
<div id="photoCover">
<nav id="menu" class="menu">
<span>Menu</span>
</nav>
</div><!--photoCover-->
<div id="entryMenu"></div><!--entryMenu-->
</body>
css:
html {
background: green;
width: 100%;
height:100%;
}
body {
width: 100%;
height:100%;
position: relative;
}
#photoCover {
width:100%;
height:100%;
position: fixed;
top: 0;
left:0;
background-color: rgba(0,0,0,0.6);
}
.menu {
position: fixed;
top: 0; right: 0;
width: 100%;
background-color: rgba(0,0,0,0);
-webkit-backface-visibility: hidden;
}
.menu-trigger {
position: fixed;
top: 2%; right: 2%;
display: block;
width: 60px; height: 60px;
cursor: pointer;
background: red;
z-index:3000;
}
.menu-trigger span {
position: absolute;
top: 50%; left: 0;
display: block;
width: 100%; height: 6px;
margin-top: -2px;
background-color: #fff;
font-size: 0px;
-webkit-touch-callout: none;
user-select: none;
-webkit-transition: background-color 0.3s;
transition: background-color 0.3s;
z-index: 2000;
}
.menu-trigger span:before,
.menu-trigger span:after {
position: absolute;
left: 0;
width: 100%; height: 100%;
background: #fff;
content: '';
}
.menu-trigger span:before {
-webkit-transform: translateY(-270%);
transform: translateY(-270%);
}
.menu-trigger span:after {
-webkit-transform: translateY(270%);
transform: translateY(270%);
}
#entryMenu {
position: fixed;
top:0;
left:0;
height:100%;
width:100%;
background-color: rgba(0,0,0,0.9);
}
By adding a z-index to the parent-div, I got the "hamburger" on the top layer.
#photoCover {
(...)
z-index:99;
}
I would believe that the reason why, is that both the #photoCover and the #entryMenu is fixed and in the same place, the #entryMenu is on top, because it is added last.
Add z-index: 1; for div with id=photoCover.
Add z-index to the wrapper div
#photoCover {
width:100%;
height:100%;
position: fixed;
top: 0;
left:0;
background-color: rgba(0,0,0,0.6);
z-index: 1;
}
Demo URL
I am trying to achieve the following, with pure CSS and no images:
As you can see, its a heading with a line afterwards. The problem is, that the line should has 2 different colors and more important, 2 different heights.
The first parts color is orange, has a height of 3px and a fixed width of 100px (padding-left: 15px)
The sedond parts color is #E1E1E1 and should fill the rest of the line.
My first try was this:
<h1><span>OUR ARTICLES</span></h1>
<style>
h1 {
overflow: hidden;
}
h1 span {
display: inline-block;
position: relative;
}
h1 span:after {
content: "";
position: absolute;
height: 1px;
top: 45%;
width: 999px;
background: #E1E1E1;
border-left: 100px solid orange;
left: 100%;
margin-left: 15px;
}
</style>
See http://jsfiddle.net/oyxmxoLs/
But as you can see, I can't make the orange part thicker than the grey one.
Any ideas?
Another way: Flexbox
With display: flex you don't have to give the line a certain width and you can make sure it is always responsive.
We are going here with an progressive enhancement approach. We'll make a cut after IE8 by using ::before instead of :before. In IE9 only the grey line will be shown (underneath the title).
h1 {
align-items: center;
color: #444;
display: flex;
font: 18px/1.3 sans-serif;
margin: 18px 15px;
white-space: nowrap;
}
h1::before {
background-color: orange;
content: "";
height: 4px;
margin-left: 10px;
order: 2;
width: 100px;
}
h1::after {
background-color: #E1E1E1;
content: "";
display: block;
height: 2px;
order: 3;
width: 100%;
}
<h1>Our articles</h1>
Do not forget to add vendor-prefixes!
You can solve this by using :before and :after
http://jsfiddle.net/oyxmxoLs/1/
h1 {
overflow: hidden;
}
h1 span {
display: inline-block;
position: relative;
}
h1 span:before {
content: "";
position: absolute;
height: 1px;
top: 45%;
width: 999px;
background: #E1E1E1;
left: 100%;
margin-left: 15px;
}
h1 span:after {
content: "";
position: absolute;
height: 3px;
top: 45%;
width: 100px;
background: orange;
left: 100%;
margin-left: 15px;
margin-top:-1px;
}
<h1><span>OUR ARTICLES</span></h1>
You can also use the :before pseudo-element to add the orange line.
h1 {
overflow: hidden;
}
h1 span {
display: inline-block;
position: relative;
}
h1 span:after, h1 span:before {
content: "";
position: absolute;
height: 1px;
left: 100%;
top: 45%;
margin-left: 15px;
}
h1 span:after {
width: 999px;
background: #E1E1E1;
}
h1 span:before {
height: 3px;
z-index: 1;
margin-top: -1px;
border-radius: 2px;
width: 100px;
background: orange;
}
<h1><span>OUR ARTICLES</span></h1>
I want to create a hover effect on an image that when hovered over multiple colored divs appear. I figure I can do this with CSS, but am having trouble getting the result I want.
What I am aiming for it to look like in the end:
HTML:
<div class="row thumbrow">
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-4 thumbgrid">
<li>
<div class="thumb">
{{ cms:page_file:thumb_one.image:image}}
<span class="center">{{ cms:page:thumb_one.text:string }}</span>
<div class="yellow">
</div>
</div>
</li>
</ul>
</div>
CSS:
.thumb {
display:inline-block;
position: relative;
height: 170px;
overflow: hidden;
}
.thumb:after {
background: rgba(255,255,255,.8);
content:'';
display: block;
height: 170px;
left: 0;
opacity: 0;
padding: 20px;
position: absolute;
top: 0;
width: 100%;
z-index: 1;
}
.thumb:hover:after {
opacity: 1;
padding: 20px;
transition: opacity .4s;
}
.thumb:hover .yellow {
content:'';
display: block;
height: 170px;
left: 0;
opacity: 1;
position: relative;
top: 0;
width: 100%;
z-index: 5;
background: #f9d33a;
}
span.center {
color: white;
position: relative;
top: -100px;
z-index: 3;
}
As comments, the essential part was the missing of css position:absolute for the elements .yellow and .center
I have run up a demo here
The use of the selectors :after are not necessary , in the demo the CSS has been shortened to :
.thumb {
display:inline-block;
position: relative;
height: 170px; width:100%;
overflow: hidden;
}
.thumb .yellow, .thumb .center { display:none; }
.thumb:hover .yellow {
content:'.'; display: block;
position: absolute; z-index: 1;
bottom:10px; left: 10px; right:10px; top: 10px;
background: #f9d33a; opacity: 0.5;
}
.thumb:hover .center {
display:block; color: white;
position: absolute; z-index: 2;
top: 20px; left: 20px; right: 20px; bottom:20px;
}
Some values ( like the top, bottom, left, right offsets I made up ), the key part is the position:absolute
You can use hover selectors along with sibling selectors to display on hover, similar to the suckerfish menu:
http://jsbin.com/qerucawe/3
http://jsbin.com/qerucawe/3/edit
I have list items set up in 2 columns, with a bottom margin separating each 'row' of 2 items.
It's easy to set a left border on every even list item...
But I'm wondering if it's possible to set up the border such that it continues in a continuous vertical line with it's height as high as the second column.
Also, I don't want to use bottom padding on the list items, because then (amongst other things) the the separator will jut out below the list item.
This is what have so far:
(This is good)
(This is not what I want because the bottom margin of the items 'cuts' the silver line
FIDDLE
Markup:
<ul>
<li></li><li></li><li></li>
</ul>
CSS:
ul
{
list-style: none;
width: 220px;
background: wheat;
}
li
{
display:inline-block;
background: pink;
width: 100px;
height: 100px;
margin-bottom: 25px;
position: relative;
}
li:nth-child(even)
{
margin-left: 18px;
}
li:nth-child(even):before
{
content: '';
position: absolute;
left: -11px;
top:0;
width: 4px;
height: 100%;
background: silver;
}
Would this suit you?
I hust modified the li:before so it take the whole height including the li margins using padding-top
Then I positioned it heigher (top:-30px;) so only the next evn li has the separator. This makes the separator overflow the on of the ul so I set it to overflow:hidden
FIDDLE
CSS:
*
{
margin:0;padding:0;
}
ul
{
list-style: none;
width: 220px;
background: wheat;
overflow:hidden;
}
li
{
display:inline-block;
background: pink;
width: 100px;
height: 100px;
margin-bottom: 25px;
position: relative;
}
li:nth-child(even)
{
margin-left: 18px;
}
li:nth-child(even):before
{
content: '';
position: absolute;
left: -11px;
top:-30px;
width: 4px;
height: 100%;
background: silver;
padding-top:30px;
}
A simple idea which I would do is to put all the left side items in one div, right side items in another div and apply styles to it.
.right,.left{
float:left;
}
.left{
border-right:2px solid grey;
}
OPTION 2:
Replace the following lines of code
li:nth-child(even):before
{
content: '';
position: absolute;
left: -11px;
top:0;
width: 4px;
height: 100%;
background: silver;
}
with the following...
li:nth-child(odd):after
{
content: '';
position: absolute;
right: -11px;
top:0;
width: 4px;
height: 130%;
background: silver;
}
//this is optional in according to the look and feel you are expecting
li:last-child:after{
content: '';
position: absolute;
right: -11px;
top:0;
width: 4px;
height: 100%;
background: silver;
}
li:last-child:after
{
content: '';
position: absolute;
right: -11px;
top:0;
width: 4px;
height: 130%;
background: transparent;
}
li:nth-last-child(3):after
{
content: '';
position: absolute;
right: -11px;
top:0;
width: 4px;
height: 100%;
background: silver;
}
It is possible. However, I needed to encapsulate the contents of each list item into a div, which in my example has a height of 90% of the list item (so I could have a margin bottom). Then, add 2 style rules for gaining the silver lines.
li:nth-child(even):not(:nth-last-child(1)):not(:nth-last-child(2)):before
{
content: '';
position: absolute;
left: -11px;
top:10;
width: 4px;
height: 100%;
background: silver;
}
li:nth-child(even):nth-last-child(1):before,
li:nth-child(even):nth-last-child(2):before
{
content: '';
position: absolute;
left: -11px;
top:10;
width: 4px;
height: 90%;
background: silver;
}
Working demo: http://jsfiddle.net/er144/mUAPT/