Bootstrap DIVs are stopping the CSS :hover from working. I think this is a selector issue?
This doesn't work:
div#testimonial1 {
display: none;
}
span:hover+div div#testimonial1 {
display: block;
}
<h2 style="text-align:center">Testimonials</h2>
<div class="col-sm-12 col-md-4 arrow_box" style="padding-top:20px">
<div class="col-xs-12 testimonial1h">
<span style="line-height:75px;font-size:16px;verticle-align:middle"><img src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Logo_TV_2015.png" width="75" height="75" alt="" /> Name Here</span>
</div>
</div>
<div class="col-sm-12 col-md-8">
<div id="testimonial1">
<p style="text-align: center">"Blah blah blah"</p>
<h3 style="text-align: center">Name Here</h3>
</div>
</div>
Yet this does:
div#testimonial1 {
display: none;
}
span:hover+div div#testimonial1 {
display: block;
}
<h2 style="text-align:center">Testimonials</h2>
<span class="button" style="line-height:75px;font-size:16px;verticle-align:middle"><img src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Logo_TV_2015.png" width="75" height="75" alt="" /> Name Here</span>
<div class="col-sm-12 col-md-8">
<div id="testimonial1">
<p style="text-align: center">"Blah blah blah"</p>
<h3 style="text-align: center">Name Here</h3>
</div>
</div>
I have tried selectors like span.button etc but I can't seem to get the right selector to target the span for a hover effect?
In your first example, the span is nested in a div and in the second example, it isn't. the + selector is an adjacent sibling selector. Meaning it selects the next element it's adjacent to. There is no adjacent element to the span in your first example.
To get your first example to work, you need to set the :hover pseudo class on the element that is adjacent to the div div#testimonial1 you want to show, which would be the div that precedes it. Like this.
div#testimonial1 {
display: none;
}
.arrow_box:hover + div div#testimonial1 {
display: block;
}
<h2 style="text-align:center">Testimonials</h2>
<div class="col-sm-12 col-md-4 arrow_box" style="padding-top:20px">
<div class="col-xs-12 testimonial1h">
<span style="line-height:75px;font-size:16px;verticle-align:middle"><img src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Logo_TV_2015.png" width="75" height="75" alt="" /> Name Here</span>
</div>
</div>
<div class="col-sm-12 col-md-8">
<div id="testimonial1">
<p style="text-align: center">"Blah blah blah"</p>
<h3 style="text-align: center">Name Here</h3>
</div>
</div>
In the first code block, the span is an only child of a div (.testimonial1h). (I think you mean .testimonial1.)
In the second code block, the span is not a child of a div, but a sibling of a div.
The adjacent sibling combinator (+) (also known as the next-sibling selector) targets an element that is immediately preceded by another element.
That's not going to work in the first code block, because the span has no siblings.
It works in the second code block because div#testimonial1 is a descendant of a div (you have div div#testimonial1), and that div is immediately preceded by a span sibling.
If you want the first code block to work (i.e., target an element when a sibling's child is hovered), that's not going to work with CSS. See here for details: Is there a CSS parent selector?
You are comparing apples to oranges because your first code snippet the html DOM structure is different from the second yet your are applying the same CSS which is not going to work.
On your first one you have two divs as the parents of the span. And on your second one the span is a direct child of the body.
Try this HTML structure, it should work.
<h2 style="text-align:center">Testimonials</h2>
<span class="col-sm-12 col-md-4 arrow_box" style="line-height:75px;font-size:16px;verticle-align:middle"><img src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Logo_TV_2015.png" width="75" height="75" alt="" /> Name Here</span>
<div class="col-sm-12 col-md-8">
<div id="testimonial1">
<p style="text-align: center">"Blah blah blah"</p>
<h3 style="text-align: center">Name Here</h3>
</div>
</div>
It is indeed a selector issue. The plus sign is an adjacent sibling selector but in your first example span has no siblings. In your second example it is followed by a div so the selector works as expected.
Related
I am working on my portfolio. I have this page here:
The first picture there is a date on. I would like a text in the bottom, like this:
But I cannot get that text placed. Everytime I add a div tag and set in a text, it is going outside of the picture. I guess it is a div tag there has to be somewhere?
<div class="portfolio logo" data-cat="logo">
<article class="block-thumbnail">
<a href="#" class="block-thumb">
<div class="date">
<span class="day">10</span>
<span class="month">aug</span>
<span class="month">2016</span>
</div>
</a>
<div class="portfolio-wrapper">
<div class="portfolio-hover">
<div class="image-caption">
<div class="col-md-4 col-sm-6 col-xs-12">
<h2>link</h2>
</div>
</div>
<img src="img/portfolios/logo/5.jpg" alt="" />
</div>
</div>
</div>
If we are talking about the h2 element, that html tag sits inside a element that is hidden by default and only appears on hover.
I will move it outside the .image-caption div
<div class="portfolio-wrapper">
<div class="portfolio-hover">
<div class="col-md-4 example col-sm-6 col-xs-12">
<h2>link</h2>
</div>
<div class="image-caption">
</div>
<img src="img/portfolios/logo/5.jpg" alt="" />
</div>
</div>
and give it those styles
.example {
position: absolute;
bottom: 0;
z-index: 1;
text-align: center;
left: 0;
}
Adjust than bottom and left values to match the positioning for your design
You'll have to create a css for your image-caption class, that will be in absolute position, meaning it can clash with other things. This should help you with that: Position absolute but relative to parent . Then just make sure you have your z-index right so it's not behind the image
I'm using CSS to target a specific element in the following code. The element I want to target is the last element in the first div (.1g07). I need to do this without referring to .1g07 as the class name is dynamic.
Here is the CSS I use:
[data-sigil="reactions-bling-bar"]:first-child:last-child
And the HTML:
<a href="#" data-sigil="feed-ufi-trigger">
<div class="_rnk _2eo- _1e6" id="u_1_k" data-sigil="reactions-bling-bar">
<div class="_1g07">
<div class="_1g05" style="z-index:3">
<i class="img sp_I5ooBdwh_8A sx_9a2202"></i>
</div>
<div class="_1g05" style="z-index:2">
<i class="img sp_I5ooBdwh_8A sx_1f77a0"></i>
</div>
<div class="_1g05" style="z-index:1">
<i class="img sp_I5ooBdwh_8A sx_fbc017"></i>
</div>
<div class="_1g06">48</div>
</div>
<div class="_1j-b"><span class="_1j-c">12 comments</span></div>
</div>
</a>
It's not targetting this element though (in this case the element that contains the number 48).
Any ideas on where I am going wrong?
You can do like this
[data-sigil="reactions-bling-bar"] div div:last-child
[data-sigil="reactions-bling-bar"] :first-child :last-child
Sample snippet
[data-sigil="reactions-bling-bar"] div div:last-child
{
color: red
}
<a href="#" data-sigil="feed-ufi-trigger">
<div class="_rnk _2eo- _1e6" id="u_1_k" data-sigil="reactions-bling-bar">
<div class="_1g07">
<div class="_1g05" style="z-index:3">
<i class="img sp_I5ooBdwh_8A sx_9a2202"></i>
</div>
<div class="_1g05" style="z-index:2">
<i class="img sp_I5ooBdwh_8A sx_1f77a0"></i>
</div>
<div class="_1g05" style="z-index:1">
<i class="img sp_I5ooBdwh_8A sx_fbc017"></i>
</div>
<div class="_1g06">48</div>
</div>
<div class="_1j-b"><span class="_1j-c">12 comments</span></div>
</div>
</a>
[data-sigil="reactions-bling-bar"]:first-child:last-child targets an element with a data attribute called sigil that is both the first and last child of its parent.
I think you're looking for [data-sigil="reactions-bling-bar"] > :first-child > :last-child, which would select the last child of the first child of the element with that data-sigil attribute.
you can try this
#u_1_k div div:last-child
{
/* css as you wants */
}
your CSS selector targets nothing, because:
[data-sigil="reactions-bling-bar"] targets the div with the attribute data-sigil having the value reactions-bling-bar;
[data-sigil="reactions-bling-bar"]:first-child targets the div with the attribute data-sigil having the value reactions-bling-bar AND which is the first child of its container;
[data-sigil="reactions-bling-bar"]:first-child targets the div with the attribute data-sigil having the value reactions-bling-bar AND which is the first child of its container AND which is the last child of its container.
This can't work.
If you can't modify the HTML, I dont think you can do what you want, maybe with:
[data-sigil="reactions-bling-bar"] > div > div:last-child {
/* CSS rules here */
}
I've tried #logos img:first-child{} to try and format my top img a little different from the rest but it just doesn't work. Can anyone help me figure out why?
<div id="logos" name="logos">
<div class="container">
<div class="row">
<br>
<h1 class="centered">SHOWS</h1>
<img src="img/kenshows400x300.jpg" class="img-responsive" alt="Ken Cooper" width="400px" height="300px">
<hr>
</div><!-- end row -->
<div class="row">
<div class="col-lg-6">
<img src="img/shows/jkllogo450x300.jpg" class="img-responsive" alt="Jimmy Kimmel Live" width="450px" height="300px">
</div>
<div class="col-lg-6">
<img src="img/shows/latelateshowlogo450x300.jpg" class="img-responsive" alt="Late Late Show" width="450px" height="300px">
</div>
</div><!-- end row -->
</div>
</div>
The first-child pseudo-selector selects any element which is the first child of its parent. In your example, in the first .row div, the h1 "SHOWS" is the first element and your img is the second element. So it doesn't get selected. In contrast, in the other div, both img tags are the first child of their parent, so they do get selected.
In other words, img:first-child doesn't select the first img tag, it selects the img tag which is the first child of its parent. If it has a previous sibling, then first-child doesn't apply.
We can fix your code by instead putting the first-child on .row so that the img in the first row div is selected, which also happens to be the first image.
#logos .row:first-child img {
border: 1px solid blue;
}
<div id="logos" name="logos">
<div class="container">
<div class="row">
<br>
<h1 class="centered">SHOWS</h1>
<img src="img/kenshows400x300.jpg" class="img-responsive" alt="Ken Cooper" width="400px" height="300px">
<hr>
</div> <!-- end row -->
<div class="row">
<div class="col-lg-6">
<img src="img/shows/jkllogo450x300.jpg" class="img-responsive" alt="Jimmy Kimmel Live" width="450px" height="300px">
</div>
<div class="col-lg-6">
<img src="img/shows/latelateshowlogo450x300.jpg" class="img-responsive" alt="Late Late Show" width="450px" height="300px">
</div>
</div> <!-- end row -->
</div>
</div>
:first-child / :last-child required any list in one section, but in your code img wrapped with div so try to add :first-child on just parent div, see below sample code
#logos .row:first-child img{}
Try this:-
#logos .row:first-child img{
}
Another option could be first-of-type
try #logos img:first-of-type{}
I know other people have had similar problems but their solutions do not work.
What is the reason for the following?
div.line_container:hover #sidebar_loader1 {
z-index: 2;
}
the above code does change the z-index.
div:hover #sidebar_loader1 {
z-index: 2;
}
but this one does.
what is the reason for this because i need to know because i need only that class when hovered to change a style. Please help.
MY HTML code
<img src="" alt="image" id="logo">
<div class="line_container">
<img src="http://png.findicons.com/files/icons/1580/devine_icons_part_2/128/png.png" alt="IMAGE" class="line_image">
<span class="line_text">
THIS IS SOME SAMPLE TEXT >
</span>
</div>
<div class="sidebar_loader" id="sidebar_loader1">
TEST for 1
</div>
<div class="line_container">
<img src="http://png.findicons.com/files/icons/1580/devine_icons_part_2/128/png.png" alt="IMAGE" class="line_image">
<span class="line_text">
THIS IS SOME SAMPLE TEXT >
</span>
</div>
<div class="sidebar_loader" id="sidebar_loader2">
TEST for 2
</div>
<div class="line_container">
<img src="http://png.findicons.com/files/icons/1580/devine_icons_part_2/128/png.png" alt="IMAGE" class="line_image">
<span class="line_text">
THIS IS SOME SAMPLE TEXT >
</span>
</div>
<div class="sidebar_loader" id="sidebar_loader3">
TEST for 3
</div>
</div>
#sidebar_loader_1 is not a descendant of div.line_container, so using the descendant combinator (space) is incorrect.
Try the sibling combinator. Either + or ~ should work.
The div with id sidebar_loader1 is not nested in any div with a class line_container
<!-- HTML -->
<section class="row slide">
<div class="span4">
<h1>
<span>Some</span>
<br />
<span>Title</span>
</h1>
</div>
</section>
<section class="row slide">
<div class="span4">
<h1>
<em>Some emphasis</em>
<br />
<span>Some</span>
<br />
<span>Title</span>
</h1>
</div>
</section>
<section class="row slide">
<div class="span4">
<h1>
<em>Some other emphasis</em>
<br />
<span>Some</span>
<br />
<span>Title</span>
</h1>
</div>
</section>
/* CSS */
section h1 span:first-child{
color:#FF0033;
}
I'm trying to target the first <span> in every <h1> tag that's in a <section> container but as soon as the <span> is not the first child element (like the <em>) then it's not applying the rule.
:first-child selects the first child. Use :first-of-type for your purpose:
section h1 span:first-of-type {
color: #FF0033;
}
:first-child does not reference the element to be the first child of that type, but generally to be the first child of its parent! Citing MDN on this:
The :first-child CSS pseudo-class represents any element that is the first child element of its parent.
What you need is the :first-of-type selector (MDN link) as follows:
section h1 span:first-of-type{
color:#FF0033;
}
Example fiddle.