How to make an image hover outside the span container - html

.wrap {
position: relative;
width: 80vmin;
height: 80vmin;
margin: 0 auto;
background: inherit;
transform: scale(0.2) translatez(0px);
opacity: 0;
transition: transform .5s, opacity .5s;
}
a {
position: absolute;
left: 0;
top: 0;
width: 47.5%;
height: 47.5%;
overflow: hidden;
transform: scale(.5) translateZ(0px);
background: #242943;
}
a div {
height: 100%;
background-size: cover;
opacity: .5;
transition: opacity .5s;
border-radius: inherit;
}
a:nth-child(1) {
border-radius: 40vmin 0 0 0;
transform-origin: 110% 110%;
transition: transform .4s .15s;
background: #a23658;
}
a:nth-child(1) div {
background-image: url('p10.jpg');
}
a:nth-child(5) {
width: 55%;
height: 55%;
left: 22.5%;
top: 22.5%;
border-radius: 50vmin;
box-shadow: 0 0 0 5vmin #242943;
transform: scale(1);
}
a:nth-child(5) div {
background-image: url('groupphoto.jpg');
}
span {
position: relative;
display: block;
top: 45vmin;
width: 7vmin;
height: 7vmin;
background-image: url('squarelogo.png');
margin-left: auto;
margin-right: auto;
}
span span {
position: relative;
width: 60%;
height: 1px;
}
span span:after {
top: 1.5vmin;
}
span:hover+.wrap,
.wrap:hover {
transform: scale(.81) translateZ(0px);
opacity: 1;
}
span:hover+.wrap a,
.wrap:hover a {
transform: scale(1) translatez(0px);
}
a:hover div {
opacity: 1;
transform: translatez(0px);
}
<span><span></span></span>
<div class="wrap">
<a href="Architecture.html" title="Architecture">
<div>
<div></div>
</div>
</a>
<a href="3D & Animation.html" title="3D & Animation">
<div></div>
</a>
<a href="Graphics.html" title="Graphics">
<div></div>
</a>
<a href="Marketing.html" title="Marketing">
<div></div>
</a>
<a href="AboutUS.html" title="About Us">
<div></div>
</a>
</div>
Here is my code. I have 5 "a nth childs" in total. I'm trying to write a code that makes it if you hover over the nth childs, an image OUTSIDE of the span/span container appears. I've tried writing the html code for it in classes and everything. I don't think I'm doing it right and appear to be facing a brick wall. Can anyone help me?

1 - NO JAVASCRIPT
Assuming you don't want to use Javascript, using CSS selectors, you can achieve what you are looking for. In my example, I'm using divs instead of images, for clarity.
HTML:
<span class="span1"> SPAN 1 </span>
<div class="hide1">I am an image shown when span 1 is hovered</div>
<br>
<span class="span2"> SPAN 2 </span>
<div class="hide2">I am an image shown when span 2 is hovered</div>
CSS:
.hide1, .hide2{
display: none;
}
.span1:hover + .hide1 {
display: block;
color: blue;
}
.span2:hover + .hide2 {
display: block;
color: blue;
}
Here is the JSFiddle
2 - JAVASCRIPT SOLUTION
Now, if you're willing to use JavaScript, things are much simpler and flexible:
HTML:
<div>
<span onmouseover="image1()" onmouseout="imageout()" id="span1">1</span>
<span onmouseover="image2()" onmouseout="imageout()" id="span2">2</span>
<div id="image1">IMAGE 1</div>
<div id="image2">IMAGE 2</div>
</div>
CSS:
#span1, #span2{
cursor: default;
}
#image1, #image2{
display: none;
}
JavaScript:
var img1 = document.getElementById('image1');
var img2 = document.getElementById('image2');
function image1(){
img1.style.display = "inline-block";
}
function image2(){
img2.style.display = "inline-block";
}
function imageout(){
img1.style.display = "none";
img2.style.display = "none";
}
Here is the JSFiddle

Related

Why do my items go left when you hover more of them simultaneously?

I have a navigation on the right side of the page, and I made an animation where when you hover on a button it enlarges and shows the page name.
// This is the JavaScript code where I make the Buttons Wider:
document.querySelectorAll(".nav-button").forEach(elem => elem.addEventListener("mouseover",
() => {
elem.querySelector(".nav-hover").style.width = "300%";
}));
document.querySelectorAll(".nav-button").forEach(elem => elem.addEventListener("mouseout",
() => {
elem.querySelector(".nav-hover").style.width = "";
}));
.navigation {
z-index: 10;
position: absolute;
right: 0px;
}
.navigation .buttons {
position: absolute;
top: 50%;
transform: translate(-50%, -50%) !important;
}
.button-el {
height: 65px;
margin-bottom: 30px;
}
.button-el i {
color: var(--text-color);
font-size: 28px;
position: relative;
float: right;
margin-top: 15px;
margin-right: 15px;
}
.nav-hover {
z-index: -1;
transition: width .5s ease-out, opacity 0s, all 1s;
position: relative;
width: 65px;
height: 65px;
border-radius: 500px;
float: right;
background-color: var(--dark1);
border: var(--accent1) 3px solid;
}
<div class="buttons">
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-house"></i>
</div>
</div>
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-user-large"></i>
</div>
</div>
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-house"></i>
</div>
</div>
</div>
I think that the cause might be in the Javascript since the .buttons DIV moves when you activate very fast multiple addEventListener (mouseover and mouseout).
The problem is in the .navigation .buttons selector:
.navigation .buttons {
position: absolute;
top: 50%;
transform: translate(-50%, -50%) !important;
}
It seems like what did change it was the x in translate(x, -50%). Now it looks like this:
.navigation .buttons {
position: absolute;
top: 50%;
right: 67%;
transform: translate(0, -50%) !important;
}

Placing two different images on hover with two center images side by side

I am fairly new to HTML in the past month. I cannot for the life of me, figure out how to change the second image on hover to be a different image when the mouse hovers over it. I know some of the code probably looks dumb with how I tried to guess how I could possibly alter the second hover image. But I am quite confused. If anyone could help that would be great. The only progress I made so far is finally getting them perfectly aligned the way I would want them in the center and also the smooth transition to the hover. All that is left is being stumped on how to change the image to a different one when you hover over the second image. I do not want both hover images to be the same.
* {
background-color: coral;
}
.container {
position: relative;
width: 50%;
overflow: hidden;
display: table-cell;
border: 1px solid transparent;
/* a way to add a space around */
}
#media screen and (max-width:480px) {
.container {
/* make them full-width and one-a-row */
width: 100%;
display: block;
}
}
.image {
display: table-cell;
width: 100%;
height: auto;
transition: all .4s ease-in;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: .5s ease;
background-image: url("sketchcollage.JPG");
color: white;
text-align: center;
padding-top: 40%;
}
.overlay .overlay2 {
background-image: url("digitalartcollage.JPG");
}
a {
color: white;
}
.container:hover .overlay {
opacity: 1;
}
.container:hover .image {
transform: scale(1.2);
-webkit-transform: scale(1.2);
}
h1 {
text-align: center;
font-size: 72px;
background: -webkit-linear-gradient(rgb(12, 215, 230), rgb(170, 9, 130));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<h1> Who is Rosalyn? </h1>
<div class="container">
<a href="https://trezoro.co">
<img src="https://via.placeholder.com/500" alt="Le Tricolore Smartwatch" class="image">
<div class="overlay">
<p>Entire element is the link here</p>
</div>
</a>
</div>
<div class="container">
<img src="https://via.placeholder.com/500" alt="Le Tricolore Smartwatch" class="image">
<div class="overlay">
<a href="https://trezoro.co">
</a>
</div>
<div class="overlay2">
<p>Only the text is a link </p>
</div>
</div>
I don't know what is p tags are for, so I removed those. Also, I used a div with background-image instead img tag. when you hover on the container, the image changes.
* {
background-color: coral;
}
.flex{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
height: 50vh;
}
.container {
position: relative;
width: 48%;
overflow: hidden;
}
#media screen and (max-width:480px) {
.container {
width: 100%;
margin-top: 20px;
}
.flex{
height: 100vh;
}
}
.img{
background-size: 100% 100%;
transition: all .4s ease-in;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 1;
}
.img1{
background-image: url('https://s4.uupload.ir/files/5c29cf910a706_8m.jpg');
}
.img2{
background-image: url('https://s4.uupload.ir/files/717195_346_g0du.jpg');
}
a {
color: white;
}
.container:hover .img {
transform: scale(1.2);
-webkit-transform: scale(1.2);
opacity: 0.5;
}
.container:hover .img1{
background-image: url('https://s4.uupload.ir/files/0.270967001322580170_jazzaab_ir_ajvv.jpg');
}
.container:hover .img2{
background-image: url('https://s4.uupload.ir/files/7560b48482bfae5c-02b97ffc647f-3822363654_tji3.jpg');
}
h1 {
text-align: center;
font-size: 72px;
background: -webkit-linear-gradient(rgb(12, 215, 230), rgb(170, 9, 130));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<h1> Who is Rosalyn? </h1>
<div class="flex">
<div class="container">
<a href="https://trezoro.co">
<div class="img img1"></div>
</a>
</div>
<div class="container">
<div class="img img2"></div>
</div>
</div>
QUESTION
How to change the second image on hover to be a different image when the mouse hovers over it?
ANSWER
The approach of this question is to change an image when the user hovering the mouse over it. This task can be simply done by using the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.
.changeImg:hover {
background-image:
url("https://images.app.goo.gl/gfRnCCBPH6r4v3kp6");
}

CSS Image not scaling on hover

I've made a responsive image grid and am trying to add a hover effect to it so that the image gets a dark overlay and some text fades in on it. However, I've been having a tough time implementing it.
Here's my HTML structure.
<div class="tile">
<img src="some_image" class="animate">
<div class="overlay">
<p>Mahatma Gandhi</p>
</div>
And here's my CSS
.gallery .row .tile:hover ~ .tile img {
transform: scale(1.2);
}
However upon hovering over the image, it does not have the expected behaviour.
What's wrong?
EDIT
I got the hover effect to work and I can now fade in text.
Here's my code for that:
<div class="tile">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Tagore_Gandhi.jpg/220px-Tagore_Gandhi.jpg" class="animate">
<div class="overlay">
<div class="text">Mahatma Gandhi</div>
</div>
</div>
CSS
.tile {
position: relative;
width: 100%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: rgba(0, 0, 0, 0.8);
}
.tile:hover .overlay {
opacity: 1;
}
This seems to work but I think it doesnt have a certain "feel" to it. So I need to add a scale effect to the image. How can I do that
Here is a jsFiddle that i think will help you to resolve your issue: https://jsfiddle.net/mcs3yn1x/
HTML
<div class="tile">
<img src="https://picsum.photos/200/300" class="animate">
<div class="overlay">
<p>Mahatma Gandhi</p>
</div>
CSS
.tile {
border: 2px solid black;
}
.tile:hover img {
transform: scale(1.2);
}
Edit
After hearing alittle more about your issue I have created the following jsFiddle: https://jsfiddle.net/f1gzonjr/4/
HTML
<div class="tile">
<div class="container">
<img src="https://picsum.photos/200/300" class="animate">
<div class="overlay">
<p>Mahatma Gandhi</p>
</div>
</div>
CSS
.tile {
position: relative;
top: 0px;
left: 0px;
height: 300px;
width: 200px;
overflow: hidden;
border: 2px solid black;
}
.container:hover img{
transform: scale(1.2);
}
.overlay{
position: absolute;
display: none;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
background-color: rgba(0,0,0,0.5);
}
.overlay p {
position: relative;
text-align: center;
color: #fff;
}
.tile:hover .overlay{
display: block;
}
Here is an alternate solution. Not sure if its what you wanted.
.tile:hover img, .tile.hover img {transform: scale(1.2);}
Here is the original answer that I adapted: Change background color of child div on hover of parent div?
-----EDIT-----
To stop it scaling and breaking responsiveness you will need to add a container around the image and then set overflow to none.
HTML:
<div class="tile">
<div class="img-container"><img src="https://ichef.bbci.co.uk/news/660/cpsprodpb/16C0E/production/_109089139_928b0174-4b3f-48ff-8366-d118afa1ed56.jpg" class="animate"></div>
<div class="overlay">
<p>Mahatma Gandhi</p>
CSS:
.img-container{
width: 500px;
height: 500px;
overflow: hidden;
}
.tile:hover img, .tile.hover img {
transform: scale(1.2);
}
See the codepen below for an example
https://codepen.io/jamesCyrius/pen/pooqwwv
Here is a code
.zoom {
padding: 50px;
background-color: green;
transition: transform .2s; /* Animation */
width: 15px;
height: 15px;
margin: 0 auto;
}
.zoom:hover {
transform: scale(1.5); /* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
}
<div class="zoom"></div>

HTML and CSS irregular triangle image gallery

I need to create an image gallery, in which the individual images are irregular triangles (emphasis on irregular).
I found limited examples on how to achieve triangle images via html and css, without modifying the images themselves. One example I found in this CodePen https://codepen.io/thebabydino/pen/liDCz was a step in the right direction, but looking at it, I can't find a way to make the images irregular triangles.
The result I am trying to achieve is this:
<div class='pageOption'>
<a href='#' class='option'>
<img src='~/images/team/pic_paggas/A.png'>
</a>
<a href='#' class='option'>
<img src='~/images/team/pic_paggas/D.png'>
</a>
</div>
This is the basic HTML I will be using and the CSS is:
.pageOption {
overflow: hidden;
position: relative;
margin: 0 auto;
width: 40em;
height: 27em;
}
.option, .option img {
width: 100%;
height: 100%;
}
.option {
overflow: hidden;
position: absolute;
transform: skewX(-55.98deg);
}
.option:first-child {
left: -.25em;
transform-origin: 100% 0;
}
.option:last-child {
right: -.25em;
transform-origin: 0 100%;
}
.option img {
opacity: .75;
transition: .5s;
}
.option img:hover {
opacity: 1;
}
.option img, .option:after {
transform: skewX(55.98deg);
transform-origin: inherit;
}
Mind that the HTML and CSS I have may not be the optimal for my problem. I think the shape of the images I am using (rectangular) have something to do with this.
Would be better if the solution is better supported across browsers.
You can do it with skew like below if you cannot use clip-path:
.box {
overflow: hidden;
width: 200px;
height: 200px;
display:inline-block;
}
.triangle {
width: 100%;
height: 100%;
transform: skewX(-20deg) skewY(45deg); /* 27deg instead of 20deg to have a regular triangle */
transform-origin: bottom left;
overflow: hidden;
background-size:0 0;
}
.triangle.bottom {
transform-origin: top right;
}
.triangle:before {
content: "";
display: block;
width: inherit;
height: inherit;
background-image: inherit;
background-size:cover;
background-position:center;
transform: skewY(-45deg) skewX(20deg); /* We invert order AND signs*/
transform-origin: inherit;
}
.triangle:hover {
filter:grayscale(100%);
}
.adjust {
margin-left:-120px;
}
body {
background:#f2f2f2;
}
<div class="box">
<div class="triangle" style="background-image:url(https://picsum.photos/id/155/1000/800)"></div>
</div>
<div class="box adjust">
<div class="triangle bottom" style="background-image:url(https://picsum.photos/id/159/1000/800)"></div>
</div>

Using nth child to select one particular sibling

I am hosting three images from Google on my codepen demo.
I have built image overlays which add a semi-transparent overlay when a user hovers over them.
They're working fine, but due to the colour of the last one, it looks much darker when hovered over than the other two.
I wondered whether there was a way to select the last image using the nth child (or similar) selector so that I could style that with a lower opacity irrespective of the other two, which I want to keep the same.
Here's the codepen link - http://codepen.io/skoster7/pen/ozgjmP?editors=1100
Like I said, I would like the last image to have a lower opacity then the other two, ideally using the nth-child selector or something similar.
I know I could just use a separate overlay with a different class name, but wanted to know if this was possible before doing that.
.flexcontainer {
display: flex;
}
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
}
.overlay {
transition: .5s;
position: absolute;
margin: 12.5px 0 0 5px;
top: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
}
.overlay:hover {
transition-delay: .2s;
transition-duration: 1s;
opacity: .6;
}
.overlay p {
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
}
.photocontainer:last-child .overlay:hover {
rgba(20, 5, 5, 0.35);
text-
}
<div class="flexcontainer">
<div class="photocontainer">
<img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay">
<p>Spring is here</p>
</div>
</div>
<div class="photocontainer">
<img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay">
<p>Winter is here</p>
</div>
</div>
<div class="photocontainer">
<img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay">
<p>Autumn is here</p>
</div>
</div>
</div>
This is how you could target each one of them using nth-child, we are targeting parent element i.e. .photocontainer as they are of same class name in all three images.
.photocontainer:nth-child(1) > .overlay:hover {
opacity: 0.4;
}
.photocontainer:nth-child(2) > .overlay:hover {
opacity: 0.6;
}
.photocontainer:nth-child(3) > .overlay:hover {
opacity: 1;
}
.flexcontainer {
display: flex;
}
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
}
.overlay {
transition: .5s;
position: absolute;
margin: 12.5px 0 0 5px;
top: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
}
.overlay:hover {
transition-delay: .2s;
transition-duration: 1s;
}
.overlay p {
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
}
.photocontainer:nth-child(1) > .overlay:hover {
opacity: 0.4;
}
.photocontainer:nth-child(2) > .overlay:hover {
opacity: 0.6;
}
.photocontainer:nth-child(3) > .overlay:hover {
opacity: 1;
}
<div class="flexcontainer">
<div class="photocontainer"> <img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay"><p>Spring is here</p>
</div>
</div>
<div class="photocontainer"> <img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay"> <p>Winter is here</p>
</div>
</div>
<div class="photocontainer"><img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay"><p>Autumn is here</p>
</div>
</div>
</div>
UPDATED
The issue of text opacity lowering and last child opacity control both has been fixed
Working example at CODEPEN
HTML:
<div class="flexcontainer">
<div class="photocontainer"> <img class="spr" src="http://www.thehealthyveggie.com/wp-content/uploads/2016/03/spring-daffodils_2845661b.jpg">
<div class="overlay"></div>
<p>Spring is here</p>
</div>
<div class="photocontainer"> <img class="wint" src="http://www.outsideonline.com/sites/default/files/styles/full-page/public/winter-bucket-list-2015-igloos_h.jpg?itok=RbGFkDiq">
<div class="overlay"></div>
<p>Winter is here</p>
</div>
<div class="photocontainer"><img class="aut" src="http://www.idealmagazine.co.uk/wp-content/uploads/2013/10/Autumn-10.jpg">
<div class="overlay"></div>
<p>Autumn is here</p>
</div>
</div>
CSS:
.flexcontainer {
display: flex;
}
.photocontainer,
.spr,
.wint,
.aut {
width: 300px;
height: 200px;
margin: 5px;
position: relative;
}
.overlay {
transition: .5s;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 300px;
height: 200px;
background: black;
opacity: 0;
margin: 5px;
}
.photocontainer p {
position: absolute;
font-size: 2em;
color: white;
font-family: verdana;
text-align: center;
top: 20px;
left: 0;
right: 0;
bottom: 0;
margin: 5px;
z-index: 1;
transition: .5s;
opacity: 0;
}
.photocontainer:hover .overlay {
transition-delay: .2s;
transition-duration: 1s;
opacity: 0.6;
}
.photocontainer:hover p {
transition-delay: .2s;
transition-duration: 1s;
opacity: 1;
}
.photocontainer:hover:last-child .overlay {
opacity: 0.3;
}
Old:
.photocontainer:last-child .overlay:hover {
opacity: 0.4;
}
I hope now your both issue has been resolved.
Enjoy :)
Here's how you target it. The opacity value is just for example.
.photocontainer:last-child .overlay:hover {
opacity: .3;
}
revised codepen
The :last-child pseudo-class targets the last sibling of the same parent.
In your HTML, the third image is contained in the last .photocontainer div.
Once the focus is on the third container, you can use a descendant selector to target the image.
Also, keep in mind that the opacity property applies not only to the targeted element, but to all of the element's descendants, as well.
So when you reduce the opacity of .overlay, the text inside will also fade away.
The solution is to use the rgba() color method. The a stands for alpha channel, and allows you to apply transparency only to the color.
Add this to your code:
.photocontainer:last-child .overlay:hover {
background-color: rgba(0, 0, 0, 0.5);
}
revised codepen illustrating both methods
(If you're applying opacity to an image, that's another ball game. You can find lots of posts on this site on that topic.)
References:
https://www.w3.org/TR/css3-selectors/#selectors
https://developer.mozilla.org/en-US/docs/Web/CSS/opacity