I have css
div{margin-left:15px;}
div:hover{color:red;}
and I have multiple divs
<div>
<div>123</div>
<div>456</div>
<div>
<div>789</div>
<div>
<div>10 11 12</div>
</div>
</div>
</div>
I need that only one div became hilighted when it's under mouse pointer.
Now, when mouse is over any of these, they all become red.
Is it possible with pure CSS code?
I'm not sure why you have so many divs, if you want them indented like a list you should use ul and li but to solve your issue you could wrap all of them in a container and target the div hover within that container:
.all div:hover{color:red;}
JSFIDDLE
EDIT
Just add class names to them and target the class then
JS
Given the details the OP provided in the comments of the question I would suggest following solution:
I would add a span wrapper around every text. So the abstract function that generates the HTML would become this:
function(){
$a.="<div><span>$inc</span>"; // span tag added
if(1){
$a.=function();
}
$a.='</div>';
return $a;
}
Now the HTML output should look somewhat like this:
<div>
<div><span>123</span></div>
<div><span>456</span></div>
<div>
<div><span>789</span></div>
<div>
<div><span>10 11 12</span></div>
</div>
</div>
</div>
Which gives the possibility to style it with this CSS:
div span:hover {
color:red;
}
Related
I know it might sound awkward and kind of rookie, but still.
So the problem is a have a site on CMS with no acces to html source code (i know you could that, by searching for that specific .php file but it is a bit too much), and have to change some of it's elements style.
This is how that div i must modify looks like:
<div class="tg-feature-product-widget element-item uxdesign tg-column-3 portfolio "
data-category="portfolio " style="position: relative; left: 359.95px; top: px;left: 500px;"><figure><img>
blah blah blah
There is that annoying style i can't acces within F12 moreover the class can't be accessed with
.tg-feature-product-widget element-item uxdesign tg-column-3 portfolio{
in CSS (i do not exclude that i might not know how to access such complicated stuff).
So how do i change it's style?
You can access it like so: .tg-feature-product-widget.element-item.uxdesign.tg-column-3.portfolio
Thats how the CSS selectors work
<div class="element top"> //first div
</div>
<div class="element"> //second div
<div class="top"> //third div
</div>
</div>
.element.top{
//Selects the first div aka every div with the class element AND top
}
.element{
//Selects the first and second div aka every div with the class element
}
.element .top{
//Selects the third div nested in the second div aka every div with the
class top thats nested in a div with the class element
}
Is it possible to select the div elements with same class using css and apply different css attributes to these div elements.
My HTML:
<div class="image"><br/>a</div>
<div class="image"><br/>b</div>
<div class="image"><br/>c</div>
CSS:
div.image:before {
content:url(http://placehold.it/350x150);
}
//want to show different image for the three divs in html
JSfiddle: http://jsfiddle.net/htfhjzbo/1/
you can use nth of type selector
.image:nth-of-type(2) {
background: #ff0000;
}
<div class="image"><br/>a</div>
<div class="image"><br/>b</div>
<div class="image"><br/>c</div>
Just use the nth-child pseudoselector [parent element] .image:nth-child(n) and you can select them individually based on their position in the array of children with that class name (starting from 1).
As Alaa Mohammead mentioned, you can change the styles inline, but then it requires an !important declaration later if the site is responsive, so it's usually not a good practice to get into over simply using a stylesheet to apply the styles you want.
This is a simple question. However, I couldn't find an answer after 10 minutes search. I would like to explain my question with examples, so you can understand what I am exactly talking about.
Let's say there is a div tag with an id and it has also some text inside:
<div id="text">Hello World</div>
and I also have css rule which will turn the text into red.
.makeRed{
color: #FF0000;
}
The question is I want to make the text red in my div tag. I can simply do it like this:
<div id="text" class="makeRed">Hello World</div>
Instead of doing it, is there another way to make that text turn to red? Because if I keep adding makeRed rule to my every div that I need, it will turn my html into garbage. So I wonder if there is any way to do it clearly. I would like to use that way for "clearfix" method for some of my divs.
Whenever I need clearfix, I do like this and this is bad:
<div class="clearfix">
<div id="text">Hello World</div>
</div>
The question is: which text do you want to make red, and why?
If you want the text of all your divs red, you can just write
div{ color: red; }
If it's just for, say, an error message, I would add the class 'error' rather than 'red'. That way, you can make the HTML more semantic. You still have to add a class, but it has more meaning:
.message.error { color: red; }
You can add the ID of your div to your css like so:
.makeRed, #text{
color: #FF0000;
}
You can separate targets by commas to include multiple different elements in the style. This will maintain the styles applied to .makeRed and apply to your #text div.
There is my code :
<div class='f-left vignetteFamille box-sizing'>
<div class='relative contenuVignetteFamille box-sizing' style='z-index:1;'>
<br/><br/><br/><br/>
<img class='absolute' src='./charte/famille/fondBasGaucheVignetteFamille' style='bottom:-21px;left:-4px;z-index:0;'>
</div>
</div>
I want my div contenuVignetteFamille hover the image but this doesn't work and I don't know why
EDIT:
there is my css but I don't know if will help you :
.vignetteFamille{background-image:url('./charte/famille/fondVignetteFamille.png'); background-repeat:no-repeat;background-position:bottom right;margin-right:16px;width:201px;margin-top:2px;padding-bottom:19px;padding-right:19px;}
.contenuVignetteFamille{width:100%;border:solid 4px #FFC600;}
I'm not sure if I understood your question correctly but I'm assuming you want to highlight the image when hovering the div contenuVignetteFamille?
This can be solved by adding css to the child when hovering the parent, like this:
.contenuVignetteFamille:hover img {
opacity: 0.5;
}
See my fiddle here.
On another note, don't use br tags to get some height on your div, add a height value instead. I've also moved your inline styling to the external one.
Maybe this is an easy stuff for all web designers out there. So here goes. I just want to add a padding-left property to my div which is inside an div element.
This is the structure of my html
<div id="content-sub">
<form action="/en/contact" method="post" id="contact-mail-page">
<div> <!-- *This part is where I want to add the property padding-left*-->
You can leave a message using the contact form below.
...........
</div>
</form>
</div>
Points to consider:
If you're suggesting of adding a class name or id name. No can't do cause I can't find/don't know the location of the contact form file so I can only add this property in the style.css.
Here is some CSS to add:
#contact-mail-page > div { padding-left: 10px; }
This will only apply to the first level of children in the form element, so any divs inside that div tag will not get the padding applied to it.
#content-sub div { padding-left : 10px;}
Here is you can do
#content-sub div {
//add stuff
}