CSS Making a div change opacity, lightness when hovered over - css

My objective is to create an area that displays clickable text content, has hover that changes the whole area, and does NOT spaz out when the whole div or text is rolled over. I want to do this with css.
For example, I want a div, say 500 x 500 px, inside of this div are p's and a's that need to be clickable. It works normally. Something like:
<div style="width:500px; height:500px;">
<p> xtext <a>xlink</a> </p>
<p> xtext <a>xlink</a> </p>
</div>
And then, I want a div on top, that has a rollover (hover) function that covers the whole first div, hazing out the whole div with a transparent color, until rolled over, when the transparency is set to 0.0, and appears gone. But I want the links from the first div to be clickable (to do this, I give this second div pointer-events:none). I place this code* inside the first div, so in total looks like this:
<div style="width:500px; height:500px;">
*<div class="divhover" style="width:500px; height:500px; position:absolute;">
</div>
<p> xtext <a>xlink</a> </p>
<p> xtext <a>xlink</a> </p>
</div>
Styling with css class:
div.divhover {
background-color: hsla(0, 100%, 100%, 0.5); }
div.divhover:hover {
background-color: hsla(0, 100%, 100%, 0.0);
pointer-events: none; }
Without pointer-events:none, this works like a normal hover function: if your mouse is not on the div area, there is a white layer of 0.5 transparency. If your mouse is on it, the transparency is 0.0 and looks as if it is uncovered. This, however, does not allow the text and links elements to be clicked.
With pointer-events:none, the text and links are clickable but it results in the hover to deactivate when a cursor is over the p or a elements. This makes the whole div spaz out and blink if the cursor moves around, and rapid blinking if the cursor is hovering on a link! I don't want this!
I hope all you with much more css/html know-how can help me (I don't know much). Before getting this far, I tried setting z-index:-1 on .divhover:hover to have the text and links in the first div be clickable. I also tried using position:absolute moving the second div off the page (left:2000px). These both resulted in the same situation, as they are only different ways to do the same thing with pointer-events.
Here is a jsfiddle where you can see the blinking:
http://jsfiddle.net/6wU8X/
Although it's not apparent here, if you take out pointer-events:none, the links and text would not be clickable.

The flicker you're seeing is caused by setting pointer-events:none; on the hover property.
You're telling the browser to ignore all pointer events, even the ones that trigger hover states. So the moment you activate the hover css you deactivate it, causing the flicker (it's updated by mouse pixel movement).
CSS:
.divhover:hover {
background-color: hsla(0, 100%, 100%, 0.0);
}
Update: If your ultimate goal is to simply grey out the text until you hover over it, then you might try this:
Working Demo
HTML:
<div class="hover">
<p> xtext <a>xlink</a> </p>
<p> xtext <a>xlink</a> </p>
</div>
CSS:
.hover {
width:500px;
height:500px;
background-color:#ccc;
color:#333;
opacity: .5;
}
.hover:hover{
opacity: 1;
}
I think you may be going about this effect in an odd way. You can add a hover state on the containing element and toggle the opacity.

I can't come up with a way to do this with CSS. If you're open to JavaScript and jQuery, here is a fall back if no one comes up with a CSS solution.
Add a class to the parent div:
<div class="parent" style="width:500px; height:500px; background-color:#ccc; color:#333;z-index:10">
<div class="divhover" style="width:500px; height:500px; position:absolute;">
</div>
<p> xtext <a>xlink</a> </p>
<p> xtext <a>xlink</a> </p>
</div>
Include jquery and add the following script:
$(document).ready(function(){
$(".divhover").mouseover(function(){
console.log("Over");
$(this).hide();
}
);
$(".parent").mouseleave(function(){
console.log("out");
$(".divhover").show();
});
});
See it in action here: http://jsfiddle.net/6wU8X/2/
Hopefully some one comes up with a CSS solution though!

Related

Change background color for all child elements without hiding images

I'm creating an application that edits the formatting of any webpage. I'm trying to change the background color of all the child divs of a selected div, but my current code makes images within the divs disappear.
.blah *:not(img) {
background-color: #fffdd0 !important;
}
I tried using :not() to make the formatting not apply to images, but it didn't change anything. Is there a way to make the background color not apply to images or not hide images?
i think your imgs are not children but they are grandchildren of your .blahdiv . that's why your code is not working. and so the parent of the img ( .child in my case ) gets the background and so a background appears under the image although the image doesn't get the background-color style
you could try something like this ( don't know your HTML structure or how complex it is )
div *:not(.child) { background-color: #fffdd0 !important;}
.parent > .child *:not(img){ background-color: red !important;}
<div class="parent">
<p>Child Text</p>
<h1>Child Heading</h1>
<div class="child">
<img src="http://placehold.it/350x150">
<p>grandChild Text</p>
</div>
</div>

keep div open after hover without jquery

I actually use css function :hover to make my div appear and no jquery. The problem is that the div disappear when the cursor goes out of the div.
I'm also avoiding using display:block; function because i cannot take advantage of the opacity transition features of css. I saw other posts solving the question using all built jquery code. I wondered if it could be done without rewriting the entire code in jquery.
Here is the fiddle http://jsfiddle.net/dandecasa/k22UG/1/
As you see, when hovering the black div on the left, the #zobbigmenu div appears. Could it be possible to let it be visible when the cursor is in the #zobbigmenu div?
Thank you for you help
Javascript/jQuery is not necessary.
Add the styling on :hover of #zobbigmenu too.
jsFiddle example
#zobmenu:hover ~ #zobbigmenu, #zobbigmenu:hover {
margin-left: 20px;
cursor:alias;
opacity:0.8;
margin-right: auto;
z-index:10;
}
Alternatively, I would suggest nesting #zobbigmenu in #zobmenu.
You could wrap everything inside a <div>:
<div id="wrap">
<div id="zobmenu"></div>
<div id="zobbigmenu">
<a href="http://instagram.com/dandecasa" target="_blank">
<img src="http://theyellowhopeproject.com/iconmonstr-instagram-4-icon.png" height="50px"></img>
</a>
</div>
</div>
And change the CSS:
#wrap:hover #zobmenu ~#zobbigmenu {
margin-left: 20px ;
cursor:alias;
opacity:0.8;
margin-right: auto ;
z-index:10;
}
jsFiddle

anchor padding clickable only when opacity <1

Using trick from here: Making the clickable area of in-line links bigger without affecting the layout, I set positive padding and negative margin on an anchor element, with the goal of extending the clickable region into some text beyond the element.
It works, but only if opacity is some value below 1! Firefox and Chrome exhibit the same behavior.
Compact demo: http://jsfiddle.net/zGsZK/8/
CSS:
a { margin-right:-250px; padding-right:250px }
.nowork { opacity:1 }
.works { opacity:0.999999 }
HTML:
<body>
<a href=# class=nowork>?</a> this black text is not clickable :(
<p>
<a href=# class=works>!</a> this black text is clickable, as it should be
</body>
Is this how it's supposed to work? Why? Is there a way to make it work when opacity==1?
I'm really not sure why this works, but if you add position:relative; to the nowork class, the clickable area will appear above the text similar to the works class. I believe this has something to do with how browsers render CSS, and since the <p> tag is rendered after the anchor, its native CSS (where cursor:normal; rather than cursor:pointer;) takes priority.

CSS: icon for each <li> that floats in the middle of the line

At the get-go, here's the fiddle.
I want a <ul> in which each <li> has a <p> and then an icon floating on the rhs. The paragraph may take 1-4 lines, and I want the icon to sit nicely in the middle of the line no matter what. The double wrapping <p> is necessary, trust me :)
The width of the <p> has to be 100% less whatever space is necessary for the icon. Basically, I want the icon to sit halfway up the space left by the right-margin of the <p>.
The solution here uses background-image, but that's no good for me because the image has to serve as a draggable handle for mobile devices. (I'm using this approach to modify a jQuery sortable desktop site for touch screen.)
The fiddle uses a placeholder <img> because of the demands of jsfiddle, but I'll actually use an <a> with an image off a sprite.
I want to avoid having a negative top margin, because the margin will move into the preceding line and could mess up the dragging (i.e., you could inadvertently drag the wrong line).
Thanks.
Based on this answer by bfrohs,
DEMO here
HTML
<ul>
<li class="absoluteCenterWrapper">
<p class="text">This is some text that flows over multiple lines and I want it to have the icon on the rhs that stays in the middle of the line no matter how many lines of text (and I'd really like not to use a negative top margin on the image).</p>
<img class="icon" src="http://placekitten.com/g/20/20">
</li>
</ul>
CSS
.text {
margin-right:35px;
}
.absoluteCenterWrapper {
position:relative;
}
.icon {
margin:auto;
position:absolute;
max-height:100%;
max-width:100%;
top:0;
bottom:0;
right:0;
}
Change the position of the li element to be absolute and that of the img also absolute. Consider adding this code instead of using your css.
.icon{
margin:40% 5%;
float:right;position:absolute;
}
​
See this fiddle.
http://jsfiddle.net/NXWPE/47/

Different Links CSS Hover change a picture

I would like a CSS hover affect for multiple links that affect the same image. If you look at this example site I have Repair, Sales, Upgrades and Data Recovery links. When you hover over any one of them I would like the image to their left to change. You can hover over the image currently there to see what I mean.
website: http://ctuchicago.squarespace.com/
I would create a box that contains the image and all of the links. Then when the box is hovered over the image will change. This doesn't get you exactly what you want - which is only hovering over the link changes the image, but I think it is close enough and far easier.
http://jsfiddle.net/mrtsherman/D5ZRs/
div:hover img { background: url('blah'); }
<div>
<img src="" />
Repair
Sales
</div>
Put the image inside the a tag. Then use position: relative to position the image...
for example
a img{
position: relative;
left: -50px;
}
This seems to work... partially XD
<div class="frontdiv fblankd">
<a href="/audio-video" id="hav" style="width: auto;">
<div style="
height: 80px;
margin-left: 81px;
background: white;
color: black;
">
<h3>AUDIO / VIDEO</h3>
<p>Music Server, Home Theatre, Zone Systems, Universal Remote Control</p>
</div>
</a>
</div>
The basic idea is to have your content in the a tag (like ever body has been saying).
What I've done with the styling is set the anchor to width:auto and wrapped the content in a div. this div I then gave a height of 80px, left margin of 81px, background of white and font color of black.
Wrap the <p>, and <h3> tags inside the <a> tags.

Resources