Change CSS element that comes after another - html

I would like to hover in a.bio change the background .pic to green.
I tried some ways, but it did not work out.
I did not understand the logic of ~ and how even to make it work.
CODE
.executivo .pic::after {
background-color: #00845b;
content: "";
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
opacity: 0;
transition: .3s ease-in-out;
}
.equipe a.bio:hover ~ .pic::after {
opacity: 0.35;
}
.executivo .pic {
margin-bottom: 45px;
position: relative;
}
.executivo .pic img {
display: block;
}
<div class="executivo">
<div class="pic">
<img src="<?php echo $pic; ?>" alt="<?php echo $nome; ?>" />
</div>
<div class="title">
<h3><?php echo $nome; ?></h3>
</div>
<a class="bio" href="#">Bio+</a>
</div>

Move your a.bio in your HTML, because ~ is a sibling selector (however less strict than the +), and use position to stay as it was before moving the HTML:
Snippet
.executivo .pic::after {
background-color: #00845b;
content: "";
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
opacity: 0;
transition: .3s ease-in-out;
}
.executivo {
position: relative;
}
.executivo a.bio {
position: absolute;
bottom: -20px
}
.executivo a.bio:hover ~ .pic img {
opacity: 0.35;
}
.executivo .pic {
margin-bottom: 45px;
position: relative;
}
.executivo .pic img {
display: block;
max-width:100% /*demo*/
}
<div class="executivo">
<a class="bio" href="#">Bio+</a>
<div class="pic">
<img src="//lorempixel.com/1600/900" alt="alt text" />
</div>
<div class="title">
<h3>title</h3>
</div>
</div>

Nex element selector is
+
And direct decedent is
>
in css.
Does this help you answer your question?

Related

how to move elements in hover with transform?

i was messing around with transform and when i added it to a hover and it didn't work.
I wanna make a share button that when you hover it 3 buttons show them selves
transform works correct but when i use it in pseudo selector:hover its not working.
div {
width: 400px;
height: 400px;
margin: 10px auto auto 100px;
position: relative;
}
img {
position: absolute;
top: 0;
width: 60px;
height: 60px;
}
img[src="instagram.svg"] {
z-index: 1;
}
img[src="linked in.svg"] {
z-index: 2;
}
img[src="telegram i.svg"] {
z-index: 3;
}
img[src="share btn.svg"] {
z-index: 4;
transition: 600ms;
}
img[src="share btn.svg"]:hover {
opacity: 0;
transition: 600ms;
}
img[src="telegram i.svg"]:hover {
transform: translate(30px, 30px);
}
<div>
<img src="instagram.svg" alt="your browser is suck">
<img src="linked in.svg" alt="your browser is suck">
<img src="telegram i.svg" alt="your browser is suck">
<img src="share btn.svg" alt="your browser is suck">
</div>
If you stack two position: absolute items with the same size over each other you will only be able to trigger :hover on the item with the highest z-index
You'll also run into problems with user experience by putting your translates on the :hover of an img, instead try wrapping it in a container (as I did with the div class="share" below)
try this CSS
div {
width: 400px;
height: 400px;
margin: 10px auto auto 100px;
position: relative;
}
img {
position: absolute;
top: 0;
left: 0;
width: 60px;
height: 60px;
}
img[src="instagram.svg"] {
z-index: 1;
}
img[src="linked in.svg"] {
z-index: 2;
}
img[src="telegram i.svg"] {
z-index: 3;
}
img[src="share btn.svg"] {
z-index: 4;
transition: 600ms;
}
.share {
position: relative;
height: 30px;
width: 30px;
}
.share:hover {
height: 120px;
}
.share:hover > img[src="share btn.svg"] {
opacity: 0;
transition: 600ms;
}
.share:hover > img[src="telegram i.svg"] {
transform: translateY(30px);
}
.share:hover > img[src="linked in.svg"] {
transform: translateY(60px);
}
.share:hover > img[src="instagram.svg"] {
transform: translateY(90px);
}
with this HTML
<div>
<div class="share">
<img src="instagram.svg" alt="your browser is suck">
<img src="linked in.svg" alt="your browser is suck">
<img src="telegram i.svg" alt="your browser is suck">
<img src="share btn.svg" alt="your browser is suck">
</div>
</div>

CSS show a bigger image while hover

Ive got a product page with a smaller image of the product.
Now I want to show a bigger version of this image with a colored background covering the whole page, while I hover the smaller image.
The problem is, that the bigger image flickers while I move the mouse around.
My CSS:
#zoomed-product-img {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(162, 130, 192, 0.8);
z-index: 0;
visibility: hidden;
}
#zoomed-product-img img {
display: block;
margin: auto auto;
}
.productsdetail-image:hover~#zoomed-product-img {
visibility: visible;
}
My HTML:
<div class="productdetails">
<div class="productsdetail-image">
<img src="/assets/images/products/{{page.name}}.png" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
<div id="zoomed-product-img">
<img src="/assets/images/products/{{page.name}}.png" alt="Produktbild">
</div>
Can you help me? Maybe my way of thinking is wrong.
I think it flickers because when I show the bigger image, it is above (z index) the small one and I am not hovering the image anymore so it disappears.
I would also love to solve this with javascript, if you can give me any advice.
You need to specify dimensions for the container of the image. This is why it is flickering. I also used display: none; and display:block to hide and show the images.
.productdetails {
position: relative;
}
#zoomed-product-img {
display: none;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
}
/* This is the product detail image styles */
.productsdetail-image {
display: block;
height: 200px;
width: 200px;
}
.productsdetail-image:hover img {
display: none;
}
.productsdetail-image:hover + #zoomed-product-img {
display: block;
}
HTML
<div class="productdetails">
<div class="productsdetail-image">
<img src="https://placeimg.com/200/200/animals" alt="Produktbild">
</div>
<div id="zoomed-product-img">
<img src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
Demo:
http://jsfiddle.net/n07bt46y/
Please check this in full page
$(document).ready(function(){
$('.productsdetail-image img').hover(function() {
$(this).hide();
$('#zoomed-product-img ').show(500);
});
$('#zoomed-product-img .close').click(function(){
$(this).parent().hide();
$('.productsdetail-image img ').show();
});
});
.productsdetail-image img {
width: 150px;
height: auto;
transition: all 0.5s ease;
}
#zoomed-product-img {
display: none;
position: absolute;
width: 100%;
height: 100%;
background-color: red;
}
#zoomed-product-img span.close {
position: absolute;
color: #fff;
cursor: pointer;
top: 20px;
right: 20px;
}
#zoomed-product-img img {
position: absolute;
width: 300px;
height: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: aUto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="productdetails">
<div class="productsdetail-image">
<img src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div id="zoomed-product-img">
<span class="close">close</span>
<img class="zoom-img" src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
Are you wanna build something like that? Hoppefully that fiddle can help you

:hover and :hover:before not working properly

I've gone through a lot of the resolved questions with a similar title but nothing I try seems to work.
I want the ava.png image to redirect to another page, but on hover I want a :before image (ava_background_hoover.png) to show up.
I may be going about it all wrong, but this is what I have so far:
#slide1 {
position: relative;
margin-left: 147px;
margin-top: 0px;
z-index: 100;
}
#slide1:hover {
position: relative;
}
#slide1:hover:before {
content: url("https://www.upload.ee/image/6050956/ava_background_hoover.png");
display: block;
position: absolute;
z-index: -1;
}
#slide2 {
opacity: 1;
position: relative;
z-index: 2;
margin-left: 7px;
margin-top: 0px;
}
#slide3 {
z-index: -1;
position: absolute;
}
<section id="header">
<div class="inner">
<img id="slide1" src="https://www.upload.ee/image/6050955/ava.png"/><img id="slide2" src="https://www.upload.ee/image/6050954/arrow.png" width="140" height="160" alt=""/>
</div>
</section>
Fiddle
You can set #slide1:before's content as the default image. Then, on :hover, change the content attribute to the hover image.
If you do so, you need to change the img to a div (or span, just not an img).
#slide1 {
position: relative;
margin-left: 147px;
margin-top: 0px;
z-index: 100;
display:inline-block;
}
#slide1:before {
content: url("https://www.upload.ee/image/6050955/ava.png");
}
#slide1:hover {
position: relative;
}
#slide1:hover:after {
content: url("https://www.upload.ee/image/6050956/ava_background_hoover.png");
display: block;
position: absolute;
z-index: -1;
}
#slide2 {
opacity: 1;
position: relative;
z-index: 2;
margin-left: 7px;
margin-top: 0px;
}
#slide3 {
z-index: -1;
position: absolute;
}
<section id="header">
<div class="inner">
<a id="slide1" href="http://google.com" target="_blank"></a>
<img id="slide2" src="https://www.upload.ee/image/6050954/arrow.png" width="140" height="160" alt=""/>
</div>
</section>
Working demo including the link: http://output.jsbin.com/cudimos
the :before and :after pseudo-elements are used to insert content before, or after, the content of an element . img doesn't have content. so you can't use pseudo-elements on img .
instead, you should use <div> with ids #slide1 and #slide2 in which you put img or use background-img on that divs , you choose.
i made a simple example below. click to show snippet. let me know if it helps
P.S. you can position the :before how you want. i just guessed how you wanted it
#slide1,#slide2 { display:inline-block}
#slide1 {
position: relative;
margin-left: 147px;
margin-top: 0px;
z-index: 100;
}
#slide1:hover {
position: relative;
}
#slide1:hover:before {
content: url("https://www.upload.ee/image/6050956/ava_background_hoover.png");
display: block;
position: absolute;
z-index: 1;
right: -150%;
bottom: -150%;
}
<section id="header">
<div class="inner">
<div id="slide1">
<img src="https://www.upload.ee/image/6050955/ava.png"/>
</div>
<div id="slide2">
<img src="https://www.upload.ee/image/6050954/arrow.png" width="140" height="160" alt=""/>
</div>
</div>
</section>

Custom CSS in Wordpress messing up

I'm managing the website of my company which is based on Wordpress and I try to figure out how to change my contact page.
I've made a codepen of what I want to do : http://codepen.io/EzhnoFR/pen/PNmdxm
html :
<img class="top" src="http://www.alabama-pub.com/wp-content/uploads/2016/03/Isa.png" />
<span>Hover</span>
</div>
<div id="cf">
<img class="bottom" src="http://www.alabama-pub.com/wp-content/uploads/2016/03/christine-chute.png" />
<img class="top" src="http://www.alabama-pub.com/wp-content/uploads/2016/03/christine-1.png" />
<span> Hover </span>
</div>
<div id="cf">
<img class="bottom" src="http://www.alabama-pub.com/wp-content/uploads/2016/03/cecile-chute.png" />
<img class="top" src="http://www.alabama-pub.com/wp-content/uploads/2016/03/cecile.png" />
<span> Hover </span>
</div>
</div>
css :
#cf img.top {
-webkit-filter: grayscale(80%);
filter: grayscale(80%);
}
#cf img.top:hover {
opacity:0;
}
span{
position: absolute;
bottom: -150px;
left: 0;
z-index: -1;
display: block;
width: 225px;
margin: 0;
padding: 0;
color: black;
font-size: 25px;
text-decoration: none;
text-align: center;
-webkit-transition: .7s ease-in-out;
transition: .7s ease-in-out;
opacity: 0;
}
#cf img.top:hover ~ span{
opacity: 1;
}
/*-----------------------------------------------------*/
.column {
margin: 15px 15px 0;
padding: 0;
}
.column:last-child {
padding-bottom: 90px;
}
.column::after {
content: '';
clear: both;
display: block;
}
.column div {
position: relative;
float: left;
width: 300px;
height: 200px;
margin: 0 0 0 50px;
padding: 0;
}
.column div:first-child {
margin-left: 0;
}
However, when I add this html to my page and the css in my wordpress custom css, it all mess up as you can see : http://www.alabama-pub.com/contact-new-test/
I've tried a lot of things but I can't get to fix it, does anyone has any idea ?
You have extra < br > under image tag which is causing the issue of height changes on hover.
According to other issue please remove z-index from span tag and you are done :)
see

I want to hide an image and display text in its place when hovering over it

I want to hover over my image and have the text appear in place of image
but I don't want to use jQuery or JavaScript .
#wrapper .text {
position: relative;
bottom: 30px;
left: 0px;
visibility: hidden;
}
#wrapper:hover .text {
visibility: visible;
}
<div id="wrapper">
<img src="kero.png" class="hover" height="200px" width="200px/>
<p class="text">text</p>
</div>​
Not sure if I understand correctly what you want, but does this work for you?
Initial Case
#wrapper {
position: relative;
}
.text {
opacity: 0;
position: absolute;
bottom: 0;
}
.hover:hover {
opacity: 0;
}
.hover:hover + .text {
opacity: 1;
}
<div id="wrapper">
<img src="http://placehold.it/200x200" class="hover" />
<p class="text">text</p>
</div>​
Extended Case
#wrapper {
display: inline-block;
position: relative;
}
.text {
opacity: 0;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
transition: opacity .5s;
background: rgba(0, 0, 0, .5);
color: white;
margin: 0;
padding: 10px;
}
.hover {
display: block;
}
#wrapper:hover .text {
opacity: 1;
}
<div id="wrapper">
<img src="http://placehold.it/200x200" class="hover" />
<p class="text">text</p>
</div>​
Working fiddle : https://jsfiddle.net/2y67zerm/
U can use either display or visibility attributes
#wrapper .text {
position: absolute;
bottom: 30px;
left: 10px;
top:10px;
visibility: hidden;
display:none;
}
#wrapper:hover .text {
visibility: visible;
display:block;
z-index:1000;
}
<div id="wrapper">
<img src="kero.png" class="hover" height="200px" width="200px" />
<p class="text">text</p>
</div>​
Look at this,
http://www.w3schools.com/cssref/tryit.asp?filename=trycss_sel_hover
This is an example of "hover".
Let me know if this helps you out.
Thanks
#wrapper{
position:relative;
}
#wrapper .text {
position: absolute;
bottom: 30px;
left: 0px;
visibility: hidden;
}
#wrapper:hover .text {
visibility: visible;
}
#wrapper:hover img{
visibility: hidden;
}
This can be achieved using the display css attribute.
#wrapper p { display: none; }
#wrapper:hover img { display: none; }
#wrapper:hover p { display: block; }
Your example had unecessary classes so they have been removed.
Solution:
<style>
#wrapper p { display: none; }
#wrapper:hover img { display: none; }
#wrapper:hover p { display: block; }
</style>
<div id="wrapper">
<img src="http://i.imgur.com/UHqk6nC.jpg" />
<p>Some text</p>
</div>
See this fiddle for an example: https://jsfiddle.net/nt5vjywu/
Hope that helps!
UPDATE:
Updated fiddle with hovering text on top. Note the reorder of the img and p tag.
https://jsfiddle.net/nt5vjywu/2/