I've looked around but can't find the right answer for this... How do I set an element to hover, assuming another is hovered?
Where Assuming "selector" is hovered, it will hover, box 1+2 etc...
http://jsfiddle.net/wgJRQ/
<div id="table">
<div id="row">
<div id="selector">selector 1</div>
<div id="selector2">selector 2</div>
</div>
<br />
<div id="row">
<div id="box1">box 1</div>
<div id="box2">box 2</div>
</div>
<div id="row">
<div id="box3">box 3</div>
<div id="box4">box 4</div>
</div>
Try something like
#box1:hover, #box1:hover~#box2 {
display: table-cell;
background-color:#FFFFFF;
border:2px solid #666666;
text-align: center;
vertical-align: middle;
}
Demo: Fiddle
jQuery:
$('#table > div:first > div')
.hover(function() {
$('#table').children('div')
.eq($(this).index() + 1)
.children('div')
.toggleClass('active');
return false;
});
http://jsfiddle.net/samliew/pyY5u/
You might want to optimize your hover states and reduce it to a single declaration, something like this:
#table > div:nth-child(n+1) > div {
border:2px solid #FFFFFF;
display: table-cell;
text-align: center;
vertical-align: middle;
width: 100px;
}
#table > div:nth-child(n+1) > div:hover,
#table > div:nth-child(n+1) > div.active {
background-color:#FFFFFF;
border:2px solid #666666;
}
#box1, #box2 {
background-color:#E07586;
}
#box3, #box4 {
background-color:#837C71;
}
With CSS you can only do it if the "target" element is inside the one being hovered.
In your case, you should change your layout to be arranged in columns instead of rows, so that you have box 1 and box 2 inside selector 1. That way you can change the look of box1 when you hover on its selector: .selector:hover .box1 {...}
If you cannot do this, then you will have to use Javascript.
Keep in mind that you cannot trigger :hover with Javascript, you will have to add a class to the boxes when the mouse enters the selectors, and remove the class when it exits them.
Related
i have few divs that are in same class and have diffrent id's. I need to change color for each div, and i don't know how to do it
I would like to have something like this
HTML code:
<div class="thing" id="one"></div>
<div class="thing" id="two"></div>
<div class="thing" id="three"></div>
CSS code:
#one{
color:green;
}
#two{
color:red;
}
.thing{
background-color: get color from id;
}
color - changing the text color
background-color - change the background of the element
Change all 'color' to 'background-color' and see if this is what you trying to do.
Instead of using color directly, you can use variables.
#one {
--thing-color: green;
}
#two {
--thing-color: red;
}
.thing {
color: var(--thing-color);
background-color: var(--thing-color);
}
.things{border-size = 10px} //for all element in class .things
#one{border-color = #blue} //for specific element id one
id element inherit by default
Could just set inline style for background colour for each?
<div class="thing" id="one" style="background: green;"></div>
<div class="thing" id="two" style="background: red;"></div>
<div class="thing" id="three" style="background: blue;"></div>
When I tested this it worked using background: red; and background-color: red;
Your mistake is using 'color' in the IDs instead of 'background-color'. This overrides the class' background color, if any.
#one{
background-color: green;
}
#two{
background-color: red;
}
#three{
background-color: blue;
}
should do the trick.
Use CSS pseudo element as first-child, last-child, nth-child(n)
.thing:first-child{
background-color: green;
}
.thing:nth-child(2){
background-color: red;
}
.thing:last-child{
background-color: blue;
}
I'm working on a tiny css action which based on A element hover, will display another element. The code is pretty basic:
<a title="#" class="portfolio-reaction" href="#">
<img src="http://i.imgur.com/OZb7SI8.png" class="attachment-grid-feat" />
<div class="headline-overlay">LOREM IPSUM</div>
</a>
.portfolio-reaction {
width:250px;
height:250px;
display:block;
}
.headline-overlay {
background:none;
height:100%;
width:100%;
display:none;
position:absolute;
top:10%;
z-index:999;
text-align:left;
padding-left:0.5em;
font-weight:bold;
font-size:1.3em;
color:#000;
}
.attachment-grid-feat:hover ~ .headline-overlay {
display:block;
}
and jsfiddle: https://jsfiddle.net/yL231zsk/1/
This solution works in 99%. The missing percent is the effect - while moving mouse arrow through the button, text is blinking. I have no idea why. Secondly - what if I want to extend number of appearing elements from 1 to 3. So to have:
<a title="#" class="portfolio-reaction" href="#">
<img src="http://i.imgur.com/OZb7SI8.png" class="attachment-grid-feat" />
<div class="headline-overlay">
<p class="element-1">abc</p>
<p class="element-2">111</p>
<div class="element-3">X</div>
</div>
</a>
Thank you for any tips and advices.
You wrote the following in your css file :
.attachment-grid-feat:hover ~ .headline-overlay {
display:block;
}
It won't work since .attachment-grid-feat isn't the parent of .headline-overlay. So it won't select the state when the parent is selected because there are no element .healine-overlay inside .attachment-grid-feat. Also no need to add ~ between the two. The right selector is the following :
.portfolio-reaction:hover .headline-overlay {
display: block;
}
This way you are targeting the child div .healine-overlay when parent div .portfolio-reaction (you might want to make the <a> tag a <div> tag) is hovered.
.portfolio-reaction {
width: 250px;
height: 250px;
display: block;
}
.headline-overlay {
background: none;
display: none;
position: absolute;
top: 10%;
z-index: 999;
text-align: left;
padding-left: 0.5em;
font-weight: bold;
font-size: 1.3em;
color: #000;
}
.portfolio-reaction:hover .headline-overlay {
display: block;
}
<div title="#" class="portfolio-reaction" href="#">
<img src="http://i.imgur.com/OZb7SI8.png" class="attachment-grid-feat" />
<div class="headline-overlay">
<div id="element-1">Hello 1</div>
<div id="element-2">Hello 2</div>
<div id="element-3">Hello 3</div>
</div>
</div>
In this code snippet, three elements are contained inside .headline-overlay. On hover, all three elements are displayed.
First, change the last CSS line from this:
.attachment-grid-feat:hover ~ .headline-overlay {
display:block;
}
into this:
.attachment-grid-feat:hover .headline-overlay {
display:block;
}
And will "half" work. You need after to change the width and height of your <div class="headline-overlay"> from a smaller percentage to match your square width and height(leaving it to 100% covers the entire screen, and as a result, the text wont dissapear, no matter where you will move the cursor). Or, If you want your <div> element to match automaticaly the square size, then you leave the width and height unchanged and change only his position:absolute into position:relative and of course, a little adjusting his position from top.
Here is a working fiddle: https://jsfiddle.net/yL231zsk/9/
<style>
.main_block{}
.main_block:hover{}
.heading{background-color:red}
.content{background-color:blue}
</style>
<div class="main_block">
<div class="heading">
New Product
</div><br>
<div class="content">
This is my new product
</div>
</div>
I want to change heading div to background-color:orange and content div to background-color:yellow whenever hovering over the main_block using only CSS
Voila!
You need to start with the main-block, isolate its :hover state, then narrow by the child element- requiring one rule for each per below:
.heading {
background-color: red
}
.content {
background-color: blue
}
.main_block:hover .heading {
background-color: orange
}
.main_block:hover .content {
background-color: yellow
}
<div class="main_block">
<div class="heading">
New Product
</div>
<br>
<div class="content">
This is my new product
</div>
</div>
you can do this in LESS or SASS like so.
.main_block{
&:hover{
.heading {
background-color:orange;
}
.content {
background-color:yellow;
}
}
}
Hi I'm trying to find a way to skip the first element that are dynamically generated (div class="Title") within the (div class="MyList") class. I've tried with :first-child and :first-of-type but no luck. Basically, I'm trying to remove the double border for the first Title element. Your help would be greatly appreciated!
HTML
<div class="MyList">
<div class="Title">
<h3></h3>
</div>
<div class="List"></div>
<div class="List"></div>
<div class="List"></div>
<div class="List"></div>
<div class="Title">
<h3></h3>
</div>
<div class="List"></div>
<div class="List"></div>
</div>
CSS
.MyList > :first-child{
border-top:none;
}
.Title {
text-align: center;
border-left-width:15px;
border-bottom-width:5px;
border-top: 3px solid black;
padding-top: 1px;
}
.Title:before {
content: '';
border-top: 1px solid black;
display: block;
width: 100%;
}
.Title h3 { padding: 20px;}
Check out this fiddle: http://jsfiddle.net/j2QLY/
You need to also override the :before code you are applying to the Title element:
.MyList > :first-child {
border-top:none;
}
.MyList > :first-child:before {
border-top: none;
}
i have two divs and and i want if when i hover on one div, border color of both divs should be change...
CSS :
.uperdiv {
width:80%;
background-color:black;
margin-left:10%;
border-style:none solid none solid ;
border-width:5px;
border-color:#fff;
border-top-style:none;
height:170px;
margin-top:-220px;
transition:border-color 2s;
-moz-transition:border-color 2s;
-webkit-transition:border-color 2s;
-o-transition:border-color 2s;
}
.uperdiv:hover + .lowerdiv{
border-color:#9900ff;
}
.lowerdiv {
border-style:none solid solid solid ;
border-color:#fff;
border-width:5px;
background-color:black;
width:80%;
border-bottom-left-radius:15px;
border-bottom-right-radius:15px;
height:50px;
margin-left:10%;
}
HTML
<div class="uperdiv">
Some text
</div>
<div class="lowerdiv">
</div>
I tried + sign but it changes lower div border color when i hover on uper div...and you can say that i want to create effects as of one div.
And now i have no idea.. is there any way to do it??
And plz don't use jquery and javascript only css and css3
Thanks in advance :)
Unfortunately, you can't (yet) target the previous sibling using CSS. You could put the two divs in a container, though, and apply the :hover to that.
html
<div class="container">
<div class="upperdiv">
Some text
</div>
<div class="lowerdiv">
Some text 2
</div>
</div>
css
.container:hover .upperdiv,
.container:hover .lowerdiv {
border-color: #9900ff;
}
This way, when you hover either .upperdiv or .lowerdiv, both will have the border-color applied.
We might be able to do this without the container in the future, using the subject indicator
It would look something like this;
.upperdiv:hover,
.upperdiv:hover + .lowerdiv,
.lowerdiv:hover,
!.upperdiv + .lowerdiv:hover { /* target .upperdiv when the next sibling is hovered */
border-color: #9900ff;
}
HTML:
<div class="anyClass">
<div class="upper">
</div>
<div class="lower">
</div>
</div>
Css:
.anyClass:hover div{
border:1px solid #ccc;
}
Just add a container with anyClass to hold your div's
then add the css
You need to add hover for the uper div class:
.uperdiv:hover
FIDDLE
Check it out:
html:
<div class="upperdiv">Some text</div>
<div class="lowerdiv"></div>
css:
.upperdiv, .lowerdiv{
width: 100px;
height: 100px;
border: 1px solid blue;
}
.upperdiv:hover, .upperdiv:hover+.lowerdiv{
border-color: red;
}
It's kind of simplified but it's what you want.
Fiddle: http://jsfiddle.net/b58CU/
Try this
.uperdiv:hover, .uperdiv:hover + .lowerdiv{
border-color:#9900ff;
}
DEMO