css pseudo class last child issue - css

I have website
http://yournextleap.com/fresher-jobs
Please find out last div having HTML
<div data-recommendation="" data-id="3790" data-guidance="" data-bucket="jobs">
<div class="inn">
/* Some code*/
</div>
</div>
.inn having dashed bottom border
and it's parent div is dynamically generated
What I want:
The last DIV .inn must have border: none;
for That I tried :last-child
I don't want to use JS or Jquery
I added class for main div (temporarily I removed it); Now ther is only <div>
it was
<div class="main">
that's it, Here was my css
.main:last-child .inn{
border: none;}
But it's not working

Here's what I'm assuming you had:
<div class="main">
<div data-recommendation="" data-id="3790" data-guidance="" data-bucket="jobs">
<div class="inn">
/* Some code*/
</div>
</div>
</div>
If that's the case, you need:
.main div:last_child .inn {
border:none;
}

Hey i have tested and made the following changes in your css
div.hero-unit div.recommendation + div div:last-child div.inn {border:none !important;}
It works in Firefox and Chrome i am testing the same for IE This will work only in IE 9+ browsers IE 7 and IE 8 will not support this CSS selectors.
will explain the pattern here.
div.hero-unit is to select the parent div
div.recommendation is to select the child inside div.hero-unit
+ div will select the immediate next div
div:last-child will select the last child inside the div the one we have selected in point 3
div.inn setting the property border:none with !important so that the other borders are not applied because border:none will be given the highest priority due to !important.
Hope it helps to every read.. Best of luck

Related

[HTML][CSS] Display div on hover, targeted

When displaying a div on hover, how can you target a specific div?
I need to display a hidden div from a link is on top of the page, and I can't figure out how.
When i tested, if the link and the div are one after the other, it displays corectly. but if i add another link before the first one, it does not work anymore.
From my testing using this CSS:
.expandable{
display: none;
}
.expand:hover+.expandable{
display:inline !important;
}
.expandable:hover{
display:inline !important;
}
And this HTML:
<div class="expand">expand</div> <!--this does not do anithing-->
<div class="expand">expand</div> <!--this works-->
<div class="expandable">expandable</div>
Try the below one
.expandable{
display: none;
}
.expand:hover ~.expandable{
display:inline !important;
}
.expandable:hover{
display:inline !important;
}
Only the hover on the second div works because of the behaviour of the '+' selector
https://www.w3schools.com/cssref/sel_element_pluss.asp
What W3C says :
Select and style every p element that are placed immediately after div elements:
div + p {
background-color: yellow;
}
you can hide div by id using : jQuery :
<div id=“div”>
</div>
<script>
$(“#div”).hide("slow"); // you can change "hide" to "show"
</script>

:first-child not being applied

On this page, I want to hide the incorrect HTML displayed above the logo. It is generated by an old plugin we are replacing soon.
To start with, I tried the CSS:
.vine-home-block-grapes:first-child {display: none;}
but this does not remove the highlighted block below:
Can you help me determine why please?
Use css :first-of-type selector
.vine-home-block-grapes:first-of-type{
display:none;
}
That selector won't work as the element you are attempting to select is not the :first-child of its parent.
One way to do what you want is select all elements with that class name, set their styles as you wish and then, using a new rule with the sibling selector, override those styles for any element of that class appearing later in the parent.
.vine-home-block-grapes{
display:none;
}
.vine-home-block-grapes~.vine-home-block-grapes{
display:block;
}
Add this script. It would work fine without any problem:
<script>
var fourthChild = document.body.getElementsByTagName("div")[0];
document.body.removeChild(fourthChild);
</script>
Thanks to #FelixKling
Try wrapping the child elements in a <div> so the element can BE the first child of its wrapping element. Right now, your element is not the first child of <body> See the experiment here to show how :first-child doesn't work as expected, because really it's not the first child of its parent.
p:first-child {
background-color: aqua;
}
.vino:first-child {
background-color: lightgreen;
}
WORKS
<p>First</p>
<p>Second</p>
<p>Third</p>
DOESN'T WORK (because none of these are the first child of its parent, in this case, <body>
<p class="vino">First</p>
<p class="vino">Second</p>
<p class="vino">Third</p>
Adding a wrapping div works.
<div>
<p class="vino">First</p>
<p class="vino">Second</p>
<p class="vino">Third</p>
</div>

hide a div by clicking a non-parent div

In my site there're two different div, but they have the same parent div (two child div). So, I want to do this: div.1:hover -> div.2{display:none}. How can I do it using CSS?
Depending on the way your HTML is laid out it can work. The divs need to be next to each other like so:
<div class="first">
First div
</div>
<div class="second">
Second div
</div>
Then use this CSS:
div.first:hover + div.second { display: none; }
Fiddle here: http://jsfiddle.net/CyT2N/
You can easily accomplish that with JQuery.
$(document).ready(function(){$("#first").hover(function(){$("#second").hide();}, function(){$("#second").show();});});
Explanation:
this code adds a "hover" handler for the first element on document.ready, when the mouse enters we hide the second element, and when the mouse leaves, we show it again.
This way, it will work no matter where the elements are within the layout.
See here: http://jsfiddle.net/avrahamcool/RenK2/
Edit
If you want the second div to hide when the first one is clicked, use $("#first").click(function(){$("#second").hide();}) instead of hover(..)
See here: http://jsfiddle.net/avrahamcool/RenK2/1/
Here is a simple way of doing it:
If you have HTML similar to this:
<div class="wrap">
<div class="first">First div</div>
<p>some other element...</p>
<div class="second">Second div</div>
</div>
your CSS would be:
.first:hover ~ .second {
display: none;
}
Demo at: http://jsfiddle.net/audetwebdesign/HQN6n/
The one limitation that .first and .second must be sibling elements within the same parent element, .wrap in this example.
The general sibling combinator ~ is supported for IE7+
Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_selectors

Floating span increases width of div in IE

Hellas,
I'm having a styling issue in IE8. The goal is to have two div's in one row without setting a width (div should expand with text). It's working in all browser except for IE. Here the span element I'm floating inside the divs stretches each div to max-width forcing the other div to start in the next row. Here's the jsfiddle demo:
http://jsfiddle.net/TFnsV/
I could not make it work with this html structure in IE7, (In IE8 it works for me).
But you can change the HTML a little like this:
<div>
<h2><span class="left">Test one two three</span>
<span class="right">USD</span>
</h2>
<p>Test test test</p>
</div>
And the css:
.right{
width: 20px;
}
.left{
float:left;
}
Look at this: http://jsfiddle.net/Zn8cU/
EDIT: you can add this:
h2{
text-align:right;
}
The updated example:
http://jsfiddle.net/5bgH2/

What CSS selector can be used to select the first div within another div

I have something like:
<div id="content>
<h1>Welcome to Motor City Deli!</h1>
<div style=" font-size: 1.2em; font-weight: bolder;">Sep 19, 2010</div>
<div > ... </div>
What is the css selector for the second div (1st div within the "content" div) such that I can set the font color of the date within that div?
The MOST CORRECT answer to your question is...
#content > div:first-of-type { /* css */ }
This will apply the CSS to the first div that is a direct child of #content (which may or may not be the first child element of #content)
Another option:
#content > div:nth-of-type(1) { /* css */ }
You want
#content div:first-child {
/*css*/
}
If we can assume that the H1 is always going to be there, then
div h1+div {...}
but don't be afraid to specify the id of the content div:
#content h1+div {...}
That's about as good as you can get cross-browser right now without resorting to a JavaScript library like jQuery. Using h1+div ensures that only the first div after the H1 gets the style. There are alternatives, but they rely on CSS3 selectors, and thus won't work on most IE installs.
The closest thing to what you're looking for is the :first-child pseudoclass; unfortunately this will not work in your case because you have an <h1> before the <div>s. What I would suggest is that you either add a class to the <div>, like <div class="first"> and then style it that way, or use jQuery if you really can't add a class:
$('#content > div.first')

Resources