Hover triggered after page load - html

I tried to build a website when you hover on the link the bg will change. Is there a way to trigger the hover effect of the link "a" after the page is loaded?
.bg {
background-image: url('https://images.unsplash.com/photo-1494249465471-5655b7878482?ixlib=rb-0.3.5&s=997116405ede44d63ddc54f16e2db8ce&dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb');
height: 100vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
transition: ease-in-out 0.5s;
}
.a:hover~.bg {
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Cyrillic_letter_A_-_uppercase_and_lowercase.svg/1200px-Cyrillic_letter_A_-_uppercase_and_lowercase.svg.png');
transition: ease-in-out 0.5s;
}
.b:hover~.bg {
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/LetterB.svg/1200px-LetterB.svg.png');
transition: ease-in-out 0.5s;
}
.c:hover~.bg {
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Letter_c.svg/1200px-Letter_c.svg.png');
transition: ease-in-out 0.5s;
}
.work>a:hover {
color: #d55d5d;
}
<div class="work">
<a class="a" href=""> a
</a>
<a class="b" href=""> b
</a>
<a class="c" href=""> c
</a>
<div class="bg"> </div>
</div>

Here is a solution using jQuery, which is a package that is built on top of JavaScript. The solution works by using a data attribute to dynamically set the background-image url for the element when an a tag is hovered over. When the you move your cursor away from the a tag, it will reset the background-image to the default address.
$(function() {
var defaultImageUrl = 'https://images.unsplash.com/photo-1494249465471-5655b7878482?ixlib=rb-0.3.5&s=997116405ede44d63ddc54f16e2db8ce&dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb';
$('.bg').css('background-image', "url('" + defaultImageUrl + "')");
$('a').on('mouseenter', function() {
$('.bg').css('background-image', "url('" + $(this).data('image-url') + "')");
});
$('a').on('mouseleave', function() {
$('.bg').css('background-image', "url('" + defaultImageUrl + "')");
});
});
.bg {
/*background-image: url('https://images.unsplash.com/photo-1494249465471-5655b7878482?ixlib=rb-0.3.5&s=997116405ede44d63ddc54f16e2db8ce&dpr=1&auto=format&fit=crop&w=1000&q=80&cs=tinysrgb');*/
height: 100vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
transition: ease-in-out 0.5s;
}
.a:hover~.bg {
/*background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Cyrillic_letter_A_-_uppercase_and_lowercase.svg/1200px-Cyrillic_letter_A_-_uppercase_and_lowercase.svg.png');*/
transition: ease-in-out 0.5s;
}
.b:hover~.bg {
/*background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/LetterB.svg/1200px-LetterB.svg.png');*/
transition: ease-in-out 0.5s;
}
.c:hover~.bg {
/*background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Letter_c.svg/1200px-Letter_c.svg.png');*/
transition: ease-in-out 0.5s;
}
.work>a:hover {
color: #d55d5d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="work">
<a class="a" href="" data-image-url="https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Cyrillic_letter_A_-_uppercase_and_lowercase.svg/1200px-Cyrillic_letter_A_-_uppercase_and_lowercase.svg.png"> a
</a>
<a class="b" href="" data-image-url="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/LetterB.svg/1200px-LetterB.svg.png"> b
</a>
<a class="c" href="" data-image-url="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Letter_c.svg/1200px-Letter_c.svg.png"> c
</a>
<div class="bg"> </div>
</div>

Related

Classic alignment difficulties between two row elements in the html vs css

Hello dear stack overflow citizens. I have a boring problem with two elements (watch code snippet below) but unfortunately, I ought to resolve it. I'll be grateful for any help or advice.
I need final result like this
In the circle with background: grey I positioned a relative social media links(.social__icon>img). I can’t load svg files from assets here. You can watch the screenshot with my embarrassing acts:
I don't have enough reputation to embed screenshots, I hope you can watch it somehow.
If not, it should look something like this:
social media link img margin left:12px socila media text-name also realative link img with hover and animation effects
They both needs to work like one in a row
Example
I'm facebook svg icon in the grey ellips 12px-left Facebook
Thats result with
.social__icon {
display: inline-flex; /* Changed */
align-items: center; /* Added */
enter image description here
Active mode:
enter image description here
ol,
ul,
li,
menu {
list-style: none;
}
a {
text-decoration: none;
}
.social__list {
display: flex;
flex-direction: column;
gap: 10px;
}
.social__icon {
display: inline-block;
text-align: center;
width: 26px;
height: 26px;
border-radius: 100%;
background: rgba(196, 196, 196, 0.5);
-webkit-transition: all 0.25s linear;
-moz-transition: all 0.25s linear;
-ms-transition: all 0.25s linear;
-o-transition: all 0.25s linear;
transition: all 0.25s linear;
}
.social__icon img {
vertical-align: middle;
}
.social__icon span {}
.social__icon:active {
background: #4B9200;
color: #4B9200;
}
.social__icon:hover {
animation: shake 500ms ease-in-out forwards;
}
#keyframes shake {
0% {
transform: rotate(2deg);
}
50% {
transform: rotate(-3deg);
}
70% {
transform: rotate(3deg);
}
100% {
transform: rotate(0deg);
}
}
<div class="social">
<ul class="social__list">
<li>
<a class="social__icon" href="https://en-gb.facebook.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/fb.svg" alt="">
<span>Facebook</span>
</a>
</li>
<li>
<a class="social__icon" href="https://twitter.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/twtr.svg" alt="">
<span>Twitter</span>
</a>
</li>
<li>
<a class="social__icon" href="https://www.instagram.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/inst.svg" alt="">
<span>Instagram</span>
</a>
</li>
<li>
<a class="social__icon" href="https://www.youtube.com" target="_blank" rel="noopener">
<img src="../../assets/icons/social/youtube.svg" alt="">
<span>Youtube</span>
</a>
</li>
</ul>
</div>
Some style issues in the image
ol,
ul,
li,
menu {
list-style: none;
}
a {
text-decoration: none;
}
.social__list {
display: flex;
flex-direction: column;
gap: 10px;
}
.social__icon {
display: inline-block;
text-align: center;
-webkit-transition: all 0.25s linear;
-moz-transition: all 0.25s linear;
-ms-transition: all 0.25s linear;
-o-transition: all 0.25s linear;
transition: all 0.25s linear;
}
.social__icon img {
width: 26px;
height: 26px;
vertical-align: middle;
border-radius: 100%;
background: rgba(196, 196, 196, 0.5);
}
.social__icon:active {
background: #4b9200;
color: #4b9200;
}
.social__icon:hover {
animation: shake 500ms ease-in-out forwards;
}
#keyframes shake {
0% {
transform: rotate(2deg);
}
50% {
transform: rotate(-3deg);
}
70% {
transform: rotate(3deg);
}
100% {
transform: rotate(0deg);
}
}
<div class="social">
<ul class="social__list">
<li>
<a
class="social__icon"
href="https://en-gb.facebook.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/facebook_circle_color-512.png"
alt=""
/>
<span>Facebook</span>
</a>
</li>
<li>
<a
class="social__icon"
href="https://twitter.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/twitter_circle-512.png"
alt=""
/>
<span>Twitter</span>
</a>
</li>
<li>
<a
class="social__icon"
href="https://www.instagram.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn2.iconfinder.com/data/icons/social-media-applications/64/social_media_applications_3-instagram-512.png"
alt=""
/>
<span>Instagram</span>
</a>
</li>
<li>
<a
class="social__icon"
href="https://www.youtube.com"
target="_blank"
rel="noopener"
>
<img
src="https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/395_Youtube_logo-512.png"
alt=""
/>
<span>Youtube</span>
</a>
</li>
</ul>
</div>

Hover effect on div when hovering over anchor link outside div parent [duplicate]

This question already has answers here:
Is there a "previous sibling" selector?
(30 answers)
Is there a CSS parent selector?
(33 answers)
Closed 1 year ago.
I'm trying to scale a div which contains a background image when an anchor link is hovered upon.
I have seen similar questions before, namely this one. The solution here however, isn't ideal for me as my hover effect triggers when the anchor link is hovered upon (therefore cannot use pointer-events).
Essentially, when someone hovers over .card__link, I want to scale .card__image.
How do I go about this?
.card__overflow {
overflow: hidden;
}
.card__image {
background-image: url("https://cdn.pixabay.com/photo/2017/05/01/13/01/vehicle-2275456_1280.jpg");
transition: all 0.5s ease;
height: 300px;
width: 300px;
background-size: cover;
background-repeat: no-repeat;
}
.card__link:hover {
color: orange;
text-decoration: underline;
}
.card__link:hover ~ .card__image {
transform: scale(1.2);
}
<div class="card">
<div class="card__overflow">
<div class="card__image"></div>
</div>
<div class="card__body">
<div class="card__action">
<a class="card__link" href="#">Learn more</a>
</div>
</div>
</div>
The actual code for hover should be like this in the css please check for the css changes that has been made it works like that.
.card__overflow {
overflow: hidden;
}
.card__image {
background-image: url("https://cdn.pixabay.com/photo/2017/05/01/13/01/vehicle-2275456_1280.jpg");
transition: all 0.5s ease;
height: 300px;
width: 300px;
background-size: cover;
background-repeat: no-repeat;
}
.card__link:hover {
color: orange;
text-decoration: underline;
}
.card__body:hover~.card__overflow {
transform: scale(1.2);
}
<div class="card">
<div class="card__body">
<div class="card__action">
<a class="card__link" href="#">Learn more</a>
</div>
</div>
<div class="card__overflow">
<div class="card__image"></div>
</div>
</div>
It can be easily done with JS.
const link = document.querySelector(".card__link");
const image = document.querySelector(".card__image");
link.addEventListener("mouseenter", () => {
image.classList.add("scale-up")
image.classList.remove("scale-down")
})
link.addEventListener("mouseleave", () => {
image.classList.remove("scale-up")
image.classList.add("scale-down")
})
.card__overflow {
overflow: hidden;
}
.card__image {
background-image: url("https://cdn.pixabay.com/photo/2017/05/01/13/01/vehicle-2275456_1280.jpg");
transition: all 0.5s ease;
height: 300px;
width: 300px;
background-size: cover;
background-repeat: no-repeat;
}
.card__link:hover {
color: orange;
text-decoration: underline;
}
.scale-up {
transform: scale(1.2);
}
.scale-down {
transform: scale(1);
}
<div class="card">
<div class="card__overflow">
<div class="card__image"></div>
</div>
<div class="card__body">
<div class="card__action">
<a class="card__link" href="#">Learn more</a>
</div>
</div>
</div>

CSS Hover target other element

When hover on the .calltoaction, the background image supposed to scale to 105%. How can I target by CSS? I'm using foundation.css for my html. A codepen has been created as well: http://codepen.io/rezasan/pen/dpyoYO
HTML:
<div id="tiles">
<div class="row">
<div class="medium-6 columns nopadleftright tile-img" style="background-image:url('http://placehold.it/300x300');"></div>
<div class="medium-6 columns nopadleftright text-center">
<div class="v-align">
<h1 class="preheader text-center">EXPERIENCES</h1>
<h1>A Magical Location</h1>
<p>Text</p>
<div class="calltoaction">ABOUT</div>
</div>
</div>
<div class="row">
<div class="medium-6 columns nopadleftright text-center">
<div class="v-align">
<h1 class="preheader text-center">EXPERIENCES</h1>
<h1>A Magical Location</h1>
<p>Text</p>
<div class="calltoaction">ABOUT</div>
</div>
</div>
<div class="medium-6 columns nopadleftright tile-img" style="background-image:url('http://placehold.it/300x300');"></div>
CSS:
#tiles .row .medium-6 {
width:45%;
float:left;
height: 185px;
background-color: #fff;
padding:0 10px;
}
#tiles .row .tile-img{
background-repeat: no-repeat;
background-position: center center;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
transition: background-size .3s ease-in-out;
-moz-transition: background-size .3s ease-in-out;
-ms-transition: background-size .3s ease-in-out;
-o-transition: background-size .3s ease-in-out;
-webkit-transition: background-size .3s ease-in-out;
}
#tiles .calltoaction a:hover + .tile-img {
background-size: 105%;
}
You can't do that by pure CSS, because it doesn't work that way (you can't target a parent in your case). However you could achieve this by a little jQuery function:
$('.calltoaction a').hover(function(){
$('.tile-img').css('background-size', '105%');
});
https://jsfiddle.net/wx38rz5L/2777/
Use background-size:105% on hover
#tiles .row .tile-img:hover {
background-size:105%;
}

percent width doesn't work with 3 columns

I try to make 3 column responsive menu with images ,but when I change the #teams .teams width to percents ,div disappears. Any solutions, please!?
There is my code
#teams .team_select {
display: table;
margin: 0 auto 20px auto;
}
#teams #choose {
display: inline-block;
/*width: 32.4%;*/
width: calc(98% / 3);
}
#teams #choose:nth-child(1) {
margin-right: 1%;
}
#teams #choose:nth-child(2) {
margin-right: 1%;
}
#teams .teams {
display: table-cell;
background-size: cover;
background-position: center;
/*width: 360px;
height: 370px;*/
width: calc(98% / 3);
height: auto;
transition: background-image 1s ease-in-out;
-webkit-transition: background-image 1s ease-in-out;
-moz-transition: background-image 1s ease-in-out;
-o-transition: background-image 1s ease-in-out;
-pre-transition: background-image 1s ease-in-out;
}
#teams .back {
background-image: url("https://f4.bcbits.com/img/a3503173982_16.jpg");
}
<div class="team_select">
<div id="choose">
<a href="">
<div class="teams back"></div>
</a>
</div>
<div id="choose">
<a href="">
<div class="teams back"></div>
</a>
</div>
<div id="choose">
<a href="">
<div class="teams back"></div>
</a>
</div>
</div>
I made a JSFiddle too
I find the solution with this and made the short code ,but it works nice. Only problem is that ,with min-height he leave blank space after divs, and I dont know how to remove that.
HTML
<div id="teams">
<ul>
<li class="back"></li>
<li class="back"></li>
<li class="back"></li>
</ul>
</div>
CSS
#teams{
width:100%;
}
#teams ul{
overflow:auto;
}
#teams li{
list-style:none;
display:inline-block;
width: 31%;
min-height: 700px;
height: auto;
background-size: 100%;
background-repeat: no-repeat;
}
li.back{background-image:url("https://f4.bcbits.com/img/a3503173982_16.jpg");}
li.back:hover{background-image:url("https://designschool.canva.com/wp-content/uploads/sites/2/2015/10/How-To-Use-Blurred-Images-In-Your-Designs-To-Great-Effect_Thumbnail_01.png");}
There is new JSFiddle

Issue with hover opacity and headers

I want my website to have the same effect this website has: Trask Industries
When the upper right image is hovered the text appears and yellow covers the image.
This is the effect I am failing to recreate in CSS and Html, using headers and hover opacity. In my attempts the headers become opaque rather than standing out like on that site. I also don't know how to make the headers appear and disappear on hover.
Here is the jsfiddle of my attempt.
.content1:hover, .content2:hover, .content3:hover, .content4:hover, .content5:hover, .content6:hover {
color: black;
opacity: 0.30;
transition: .2s;
webkit-transition: .2s;
-webkit-transition: all 500ms ease;
}
You must wrap the h1 and h2 in a div, and you would animate that div in css.
I also added a same class for the contents.
Here is an updated fiddle:
http://jsfiddle.net/bzm6T/2/
Basically, this is the updated code:
Code:
.contents:hover > div {
color: black;
opacity: 1;
}
.contents div {
opacity: 0;
display: block;
width: 100%; height: 100%;
background: rgba(255,255,255,0.3);
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}
<div class="container">
<a href="articleF.html" class="contents content1">
<div>
<h1>The Low Stakes of Modern life</h1>
<h2>Default 1Default 1Default 1Default 1Default 1Default 1</h2>
</div>
</a>
<a href="articleA1.html" class="contents content2">
<div>
<h1>AARON SWARTZ</h1>
<h2>Cats Can Puuuuur</h2>
</div>
</a>
<a href="articleA2.html" class="contents content3">
<div>
<h1>JOBILLY BOOP</h1>
<h2>Cats Can Puuuuur</h2>
</div>
</a>
<a href="articleD.html" class="contents content4">
<div>
<h1>Content4</h1>
<h2>Cats Can Puuuuur</h2>
</div>
</a>
<a href="articleK1.html" class="contents content5">
<div>
<h1>Content5</h1>
<h2>Cats Can Puuuuur</h2>
</div>
</a>
<a href="articleK1.html" class="contents Content6">
<div>
<h1>Content6</h1>
<h2>Cats Can Puuuuur</h2>
</div>
</a>
</div>
A slightly different approach, but basically the same with CSS transition: FIDDLE
.holder {
width: auto;
margin: 10px auto;
border: 1px solid black;
overflow: hidden;
}
.leftdiv {
float: left;
background-color: blue;
height: 100%;
color: white;
}
.picdiv {
float: right;
background-color: orange;
}
.picdiv img {
opacity: 1;
transition: opacity 1s ease-in-out;
}
.picdiv img:hover {
opacity: 0;
}