I have some HTML/CSS that looks something like this:
#left a:hover img {
border: 5px solid red;
}
<div id="information">
<div id="left">
<a href="URL">
<img src="IMG">
<span id="button">CLICK</span>
</a>
</div>
<div id="right">
CLICK
</div>
</div>
I want to make it so that when you hover over either link, a CSS rule is applied to the image in left. I can get the link on the left, but not the right.
I want to make it so that all hovering over any links in "#information" will apply this rule to any image that fits "#information #left a img". What's the best way to do this? Is there a way to do it in one line?
We weren't able to figure out how to do this with exclusively CSS, therefore see below for a jquery alternative.
(function(){
$('#information').find('a').each(function(i, element){
$(element).mouseover(function(){
$('#left img').addClass("hoveredThing");
});
$(element).mouseleave(function(){
$('#left img').removeClass("hoveredThing");
});
});
}());
.hoveredThing { border:5px solid red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="information">
<div id="left">
<a href="URL">
<img src="img" >
<span id="button">CLICK</span>
</a>
</div>
<div id="right">
<a href="URL">
CLICK
</a>
</div>
</div>
This doesn't work because of the structure of your html. You are saying to select the img inside the hovered "a" tag. You need the img outside of the "a" and use a sibling selector.
A fiddle
https://jsfiddle.net/05jwnw7v/
#information a:hover~img{border: 1px solid red;}
<div id="information">
<div id="NewContainer">
CLICK
<a href="URL">
<span id="button">CLICK</span>
</a>
<img src="IMG" >
</div>
</div>
try this
#information div a:hover img{border:5px solid red;}
Related
i have two div . from second div a:hover i want to add opacity on img
<div class="hide">
<img src="/img.png">
</div>
<div class="onhover">
<a class=""onhover_change>
</div>
If anyone have idea let me know.
I am not getting how to apply css on above div
Change Your HTML Like
.wrapper{
display:flex;
flex-direction:column;
}
.onhover{order:1}
.hide{order:0}
.onhover:hover + .hide{
opacity:0.3;
}
<div class="wrapper">
<div class="onhover">
<a class=""onhover_change>dsd</a>
</div>
<div class="hide">
<img src="/img.png">
</div>
</div>
https://jsfiddle.net/lalji1051/w40jxaf5/3/
how do i add a link to a Div like below and make it clickable? I am using an image for the background of the Div and i want to make the whole image clickable.
<div class="grid__item-wrap">
<div class="grid__item" style="background-image: url(img/5.jpg)">
</div>
</div>
I have tried below two methods but none of them worked out for me.
Method 1:
<div class="grid__item-wrap">
<div class="grid__item" style="background-image: url(img/1.jpg)">
<div class="frame__links">
<a style="pointer-events: auto" class="frame__links" href="https://www.google.com/"></a>
</div>
</div>
</div>
Method 2:
<div class="grid__item-wrap">
<div class="grid__item" href="https://www.google.com/" style="background-image: url(img/4.jpg); pointer-events: auto;">
</div>
</div>
You need to put the div you wanted clickable inside <a> tag.
<a href="https://www.google.com/">
<div class="grid__item-wrap">
<div class="grid__item" style="background-image: url(img/5.jpg)">
</div>
</div>
</a>
.frame__links {
display:block;
height:100px;
}
.grid__item {
background-image: url(https://www.w3schools.com/w3css/img_forest.jpg);
background-repeat: no-repeat;
background-size: auto;
text-align: center;
color: white;
padding: 50px;
}
<a href="https://www.facebook.com/">
<div class="grid__item-wrap">
<div class="grid__item">
click here
</div>
</div>
</a>
Put the div element that you want to inside the a tag.
Wrapping the div inside an <a> tag should work. And style it in CSS with the cursor property to show that it is clickable.
You can do that by using onclick="window.location.href as you wanna redirect when you click on div
<div style="cursor:pointer;background-image: url(img/4.jpg)" onclick="window.location.href = 'https://www.w3schools.com';">Hello</div>
Method-2: You can wrap your div inside a tag and give background-image for the div and href path to a tag.
I have the following markup:
<div class="photo" style="float: left; margin: 2px;">
<a href="#">
<img src="images/image.jpg" alt="My Image" height="240" width="240" />
</a>
</div>
How can I create a layer on top of the image where I can write some text? The layer should have transparency, be aligned to bottom and having a size of 240x60?
Thanks!
Why not make the image a background?
<div class="photo" style="float:left; margin:2px">
<a href="#" style="background:url('images/image.jpg');
width:240px; height:240px; display:inline-block;">Your text here</a>
</div>
The display:inline-block allows you to apply width and height to an otherwise inline element, but here you might even want to just use display:block since it's the only child of the container.
EDIT: You can even put more containers in it, something like this:
<div class="photo" style="float:left; margin:2px">
<a href="#" style="background:url('images/image.jpg'); position:relative;
width:240px; height:240px; display:block;">
<span style="display:block;position:absolute;bottom:0;left:0;right:0;
background:white;background:rgba(255,255,255,0.25);">Your text here</span>
</a>
</div>
Text blocks over images. Website and demo as follows:
http://css-tricks.com/text-blocks-over-image/
I'll do it like with an image container like that :
Html
<div class="image-container">
<img src="path/to/image" />
<p class="caption">My text</p>
</div>
CSS
.image-container {
position:relative;
}
.caption {
width:100%;
background:rgba(0,0,0,0.5);
color:#ffffff;
position:absolute;
top:0;
}
See fiddle !
Markup
<div class="figure-container">
<img src="http://ipadwallsdepot.com/detail/solid-color_00015061.jpg" width="250" height="250" />
<span class="figure-label">FIG 1.1: Caption Text Here</span>
</div>
<div class="figure-container">
<img src="http://ipadwallsdepot.com/detail/solid-color_00015061.jpg" width="250" height="250" />
<span class="figure-label">FIG 1.2: Another Caption Here</span>
</div>
Stylesheet
.figure-container
{
position: relative;
display: inline-block;
}
.figure-label
{
position: absolute;
bottom: 10px;
right: 10px;
color: White
}
I created a JSFiddle here http://jsfiddle.net/AbBKx/ showing how to absolutely position a child element (label) relative to a parent container.
All I want is my two divs to stack next to one another. They are located inside a container. Why isn't it working?
This is my CSS:
#housecontainer {
height: 420px;
width: 1000px;
padding-left: 110px;
padding-top: 80px;
}
#houseimage {
float: left;
height: 388px;
width: 516px;
}
#rose {
width:200px;
height:100px;
float:left;
}
Judging by the HTML you posted in your comment, your page structure is:
#devcontainer
#develbox
#housecontainer
#houseimage
p
a
img
#rose
Since #rose is a child of #houseimage, it doesn't follow the same floating as it. Since #houseimage has a width of 516 and so does the image, there's no room left for #rose and it is forced below.
Just put one more </div> before <div id="rose">, so that it's inside #housecontainer and next to #houseimage, like you want. Then add the two other </div> you're missing.
You have several structure errors.
Try structuring your HTML like this:
http://jsfiddle.net/bGyV4/
This is the HTML you posted in your comment:
<div id="housecontainer">
<div id="houseimage">
<p>
<a href="images/rosebrook.pdf" target="_blank">
<img src="images/rosebrookthumb.png" width="516" height="388" />
</a>
<div id="rose">
<div id="rose">THIS ISNT WORKING!!!</div>
</div>
</p>
</div>
</div>
There are a number of issues with this:
The id of an element must be unique. It is used to identify the element. In your markup there are two div elements with id="rose".
From your question, it seems as if you want #houseimage and #rose to be side-by-side. This is not happening because #rose is inside #houseimage. That is, it is a child of #houseimage. You need to move it outside the div so that #rose is a sibling of #houseimage.
Change your HTML to be like this:
<div id="housecontainer">
<div id="houseimage">
<p>
<a href="images/rosebrook.pdf" target="_blank">
<img src="images/rosebrookthumb.png" width="516" height="388" />
</a>
</p>
</div>
<div id="rose">
<div id="roseChild">THIS ISNT WORKING!!!</div>
</div>
</div>
jsFiddle Demo
your html error,some DIV tag not closed,try this:
<div id="devcontainer">
<div id="develbox">
<div id="housecontainer">
<div id="houseimage">
<p>
<a href="images/rosebrook.pdf" target="_blank">
<img src="images/rosebrookthumb.png" width="516" height="388" />
</a>
</p>
</div>
<div id="rose">THIS ISNT WORKING!!!</div></div>
</div>
</div>
</div>
I've got the following...
<div id="nav-above" class="navigation">
<div class="nav-previous"><span class="meta-nav">«</span> title</div>
<div class="nav-next">title <span class="meta-nav">»</span></div>
</div><!– #nav-above –>
using external CSS alone is it possible to force all of that to remain on just one line?
Try this: http://jsfiddle.net/dT49F/
HTML:
<div class="container">
<div id="nav-above" class="navigation">
<div class="nav-previous">
<a href="link" rel="prev">
<span class="meta-nav">«</span>
much much longer link title here and here and here
</a>
</div>
<div class="nav-next">
<a href="link" rel="next">
much much longer link title here and here and here
<span class="meta-nav">»</span>
</a>
</div>
</div>
</div>
CSS:
.container div {
display: inline;
white-space: nowrap;
}
Any reason for the inner DIVs? I'd just drop them - and if you need the classes, assign them directly to the links:
<div id="nav-above" class="navigation">
<span class="meta-nav">«</span> title
title <span class="meta-nav">»</span>
</div><!– #nav-above –>
div[class^=nav-] {
float: left;
}
That should work. Please note my snippet is using CSS3 selectors, so it might not work in less-advanced browsers. Provide the same class to both divs, and then you can use normal selectors.
UPDATE:
This won't work in IE6, unless you do something like this:
<div id="nav-above" class="navigation">
<div class="nav-previous navigation-links"><span class="meta-nav">«</span> title</div>
<div class="nav-next navigation-links">title <span class="meta-nav">»</span></div>
</div><!– #nav-above –>
(Notice the new class .navigation-links)
And then just change the css selector:
div.navigation-links {
float: left;
}