I am attempting to create a front end screen, where there are images labeled step 1-4 next to each other the idea is that if the user hovers over one of these step that on the div below them the the relevant and corresponding image should fade in, and when they remove their cursor or move it to another step the image should fade out or be replaced by another image respectively. thus far I have been able to add in coding as to have the step 1 - 4 images being replaced by their correct images, but i am dumbfounded on how to get the transition effects happen on a completely different div. The code (HTML and CSS) I am using is included below.
HTML:
<div class="col-md-3">
<div class="swap-1" id="step1">
<a>
<img src="~/images/step1-cover.png" />
</a>
</div>
</div>
<div class="col-md-3">
<div class="swap-2" id="step2">
<a>
<img src="~/images/step2-cover.png" />
</a>
</div>
</div>
<div class="col-md-3">
<div class="swap-3" id="step3">
<a>
<img src="~/images/step3-cover.png" />
</a>
</div>
</div>
<div class="col-md-3">
<div class="swap-4" id="step4">
<a>
<img src="~/images/step4-cover.png" />
</a>
</div>
</div>
#*the div below is where the corresponding images should appear*#
<div id="steps" class="steps" style="height:300px; width:1000px;
margin-bottom:30px; margin-top:100px"></div>
CSS:
.swap-1 {
background-image: url(../images/step1.png);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
width: 300px;
}
.swap-1 a {
display: block;
}
.swap-1 a img {
opacity: 1;
width: 300px;
height: auto;
display: block;
transition: all .6s ease-in;
}
.swap-1 a:hover img {
opacity: 0;
transition: all .6s ease-in;
}
.swap-2 {
background-image: url(../images/step2.png);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
width: 300px;
}
.swap-2 a {
display: block;
}
.swap-2 a img {
opacity: 1;
width: 300px;
height: auto;
display: block;
transition: all .6s ease-in;
}
.swap-2 a:hover img {
opacity: 0;
transition: all .6s ease-in;
}
.swap-3 {
background-image: url(../images/step3.png);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
width: 300px;
}
.swap-3 a {
display: block;
}
.swap-3 a img {
opacity: 1;
width: 300px;
height: auto;
display: block;
transition: all .6s ease-in;
}
.swap-3 a:hover img {
opacity: 0;
transition: all .6s ease-in;
}
.swap-4 {
background-image: url(../images/step4.png);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
width: 300px;
}
.swap-4 a {
display: block;
}
.swap-4 a img {
opacity: 1;
width: 300px;
height: auto;
display: block;
transition: all .6s ease-in;
}
.swap-4 a:hover
img {
opacity: 0;
transition: all .6s ease-in;
}
If you are not limited to that specific HTML, you can do it way simpler...
simply put each 'slide' (.image) next to its 'tab' (.step) and you can access it with CSS using the '+' (next element) selector, like:
.step:hover + .image{ /* active slide css here */ }
Please check the code in the fiddle: https://jsfiddle.net/ck0bqy1h/
Related
I am working on an angular application and implemented spinner using CSS.
Now the spinner working as expected.
I have added a background image inside the CSS using background-image:url()
Here, the problem is image also rotate with the spinner.
Here is my CSS
#spinner {
-webkit-animation: frames 1s infinite linear;
animation: frames 1s infinite linear;
background: transparent;
border: .3vw solid #FFF;
border-radius: 100%;
border-top-color: #250463;
background-image:url("../../../../assets/images/svg/img.svg") ;
width: 5vw;
height: 5vw;
opacity: .6;
padding: 0;
position: absolute;
z-index: 999;
justify-content: center;
align-items: center;
}
#keyframes frames {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
.spinner-wrapper {
position: fixed;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.3);
z-index: 998;
}
html code
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
</div>
Experiment 1
added another style img
img {
max-width: 5vw;
position: absolute;
max-height: 5vw;
top: 0;
height: 5vw;
width: 5vw;
clip-path: circle(45% at 50% 49%);
}
i have updated my html code as well
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
<img src="">
</div>
Experiment 2
added background-attachment: fixed; inside spinner.Still the image is rotating
**Experiment 3 **
I made below changes.now its working
added new css
z-index: 8;
justify-content: center;
top:230px;
left: 575px;
.img {
position: absolute;
top: 0;
width: 42px;
height: 48px;
}
html changes
<div *ngIf="isLoading" class="spinner-wrapper">
<div fxLayoutAlign="center center" id="spinner">
</div>
<img src="../../../../assets/images/svg/img.svg">
</div>
One draw back is here.if i change the screen size,spinner and image appears different position
how can i solve this
Now the image showing some where else in the UI.
how can i include image inside the spinner.
How can i stop spinning my image?
Can we set image size
This is my first experience on CSS.If anything wrong please correct me.
This is my first time posting sorry in advance, this is my first time trying to make a website for uni.
Im trying to make 2 things happen to my image on hover, I want it to:
blur
make text appear
Ive managed to make it blur but cant seem to make any text appear on top of the blur.
CSS:
'''.container {
display: flex;
flex-wrap: nowrap;
width: 100vw;
height: 100vh;
justify-content: space-evenly;
}
.fern {
max-width: 50vw;
max-height: 100vh;
}
img {
max-width:100%;
max-height: 80vh;
}
.venus {
max-width: 50vw;
}
.venus:hover {
-webkit-filter:blur(10px);
transition: .5s ease;
cursor: pointer;
}
.fern:hover {
-webkit-filter:blur(10px);
transition: .5s ease;
cursor: pointer;
}
'''
HTML:
<body>
<h1 class="guide">
a guide to wellness and growth
</h1>
<div class="container">
<div class="fern">
<img src="./assets/images/fern_nobg.png" alt="fern_nobg">
</div>
<div class="venus">
<img src="./assets/images/venus_nobg.png" alt="venus_nobg">
</div>
</div>
</div>
</body>
I have tried this
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_display_element_hover
and
https://www.youtube.com/watch?v=W0ubfqwd4G4
and neither of them worked.
This is what im trying to make:
You can apply filter to img instead of applying to entire div. I have added text in span elements, and set display: none; as default. On hover, you could change it to display: block;.
If you want to animate it as well, you can use opacity.
.container {
display: flex;
flex-wrap: nowrap;
width: 100vw;
height: 100vh;
justify-content: space-evenly;
}
.fern {
max-width: 50vw;
max-height: 100vh;
}
img {
max-width: 100%;
max-height: 80vh;
transition: .5s ease;
}
.venus {
max-width: 50vw;
transition: .5s ease;
}
.text{
display: none;
}
.venus:hover img {
-webkit-filter: blur(10px);
cursor: pointer;
}
.fern:hover img {
-webkit-filter: blur(10px);
transition: .5s ease;
cursor: pointer;
}
.fern:hover .text, .venus:hover .text{
display: block;
}
<body>
<h1 class="guide">
a guide to wellness and growth
</h1>
<div class="container">
<div class="fern">
<img src="https://www.pngjoy.com/pngm/48/1094382_ferns-ostrich-fern-transparent-png.png" alt="fern_nobg">
<span class="text">Fern</span>
</div>
<div class="venus">
<img src="https://assets.stickpng.com/images/580b585b2edbce24c47b2712.png" alt="venus_nobg">
<span class="text">Venus</span>
</div>
</div>
</body>
So I have a piece of code that shows several pictures in a div that worked previously. here is the html file
<div>
<div class="info-wrap">
<div class="info-container left-info"></div>
</div>
<div class="info-wrap">
<div class="info-container middle-info"></div>
</div>
<div class="info-wrap">
<div class="info-container right-info"></div>
</div>
</div>
CSS
body{
margin:0;
background-color:white;
}
.info-wrap{
position: relative;
height: 50%;
width: 33.3333%;
overflow: hidden;
float:left;
background-color: black;
}
.info-wrap p{
position:absolute;
bottom:20%;
font-family:'Roboto';
text-align: center;
font-size: 1.15em;
color: white;
display:hidden;
}
.info-container{
height: 100%;
width: 100%;
background-size: cover;
-moz-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
-moz-transform: scale(1,1);
-webkit-transform: scale(1,1);
transform: scale(1,1);
-moz-background-size: cover;
-webkit-background-size: cover;
z-index: 2;
}
.info-wrap:hover > div {
transform: scale(1.2);
-moz-transform: scale(1.2);
-webkit-transform: scale(1.2);
opacity:0.5;
}
.left-info{
background-image: url("../image/info-1.jpg");
}
.right-info{
background-image: url("../image/info-3.jpg");
}
.middle-info{
background-image: url("../image/info-7.jpg");
}
But since I want to make my html responsive, I ported to html 5 and the background-image stop showing my picture. My folder structure is
-Project
-Views
-index.html
-CSS
-main.css
-image
-info-1.jpg
-info-2.jpg
-info-7.jpg
Can someone suggest some suggestion for this fix please? Thank you
i think you need to try this :
.info-wrap{
/* your code ... */
position: relative;
z-index: 1;
}
and add this line
.info-container{
/* your code ... */
position : relative; /* you forgot this line */
z-index: 2;
}
and try to open your image with the url that you have writed, maybe a syntax error :/
If you have modified the image and the browser continues to display the old image then you can force the full reload with CTRL + F5
Your .info-wrap element has height: 50%;. But its container - the body element doesn't have a height definition at all. Therefore the 50% height doesn't have a reference height and results in a height of 0, so the .info-wrap element won't be shown at all if it doesn't have any text content.
To change this, apply heigth: 100% to body and html, or give .info-wrap a fixed pixel-value height.
It's because you are using percentage units without defining them on their parent elements. Define percentage dimensions on your parent elements as well, in this case html, body and parent div elements (which I added the class .container to avoid impacting all generic divs):
(Note placehold.it images were used as demo)
html,
body {
width: 100%;
height: 100%;
}
body {
margin: 0;
background-color: white;
}
.container {
width: 100%;
height: 100%;
}
.info-wrap {
position: relative;
height: 50%;
width: 33.3333%;
overflow: hidden;
float: left;
background-color: black;
}
.info-container {
height: 100%;
width: 100%;
background-size: cover;
-moz-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
-moz-transform: scale(1, 1);
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
-moz-background-size: cover;
-webkit-background-size: cover;
z-index: 2;
}
.info-wrap:hover>div {
transform: scale(1.2);
-moz-transform: scale(1.2);
-webkit-transform: scale(1.2);
opacity: 0.5;
}
.left-info {
background-image: url("https://placehold.it/300x300");
}
.right-info {
background-image: url("https://placehold.it/300x300");
}
.middle-info {
background-image: url("https://placehold.it/300x300");
}
<div class="container">
<div class="info-wrap">
<div class="info-container left-info"></div>
</div>
<div class="info-wrap">
<div class="info-container middle-info"></div>
</div>
<div class="info-wrap">
<div class="info-container right-info"></div>
</div>
</div>
The problem is that .info-wrap is using percentages and the container "the div without class", not have dimensions, you have to add a class to this div and give dimensions to it.
like this
https://jsfiddle.net/77bu3hjz/
.container {
width: 300px;
height: 100px;
}
<div class="container">
<div class="info-wrap">
<div class="info-container left-info"></div>
</div>
<div class="info-wrap">
<div class="info-container middle-info"></div>
</div>
<div class="info-wrap">
<div class="info-container right-info"></div>
</div>
</div>
I have next code: JSFiddle
<div class="wrap">
<div class="item">
<div class="image" style="background-image: url(http://loremflickr.com/800/800)"></div>
</div>
</div>
<style>
.wrap {
width: 500px;
}
.item {
overflow: hidden;
padding-bottom: 100%;
position: relative;
}
.image {
backround-size: cover;
background-position: center center;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
transition: all .4s ease;
}
.item:hover .image {
transform: scale(1.1)
}
</style>
If you will put mouse on photo, then leave, then put, then leave once again not very fast (waiting while transition finished), sometimes image is twitches. Looks like trnasition sometimes not working.
Does anybody knows, what is the problem of it?
You have a syntax in your code error:
backround-size: cover;
----^
this causes a positioning twitches
so I have a div which will include an image http://www.reversl.net/hovers/ and I'd like for the image to reveal two links when hovered like in layout shown here http://www.reversl.net/demo/ Is it possible to achieve this using only css?
you can create the div with links and in css:
div.myimage div.links { display:none;}
div.myimage:hover div.links { display:block;}
sample html:
<div class="myimage">
<div class="links"> we are the links</div>
<img src="animage.png" />
</div>
obviously you have to setup yourself div positioning
Another way you could do it with display:none/block
div.container { width: 200px; height: 200px; position: relative; }
div.container img { width: 100%; height: 100%; position: absolute; top: 0; }
div.container div { width: 100%; position: absolute; top: 0; display: none; }
div.container img:hover + div { display: block; }
div.container div:hover { display: block; }
<div class="container">
<img src="an_img.jpg">
<div> A link should be here </div>
</div>
You could always use 'opacity'.
Your markup would be something like this:
<div class="wrapper">
<img src="example.png" alt="example" />
<ul class="links">
<li>Example Link</li>
<li>Example Link</li>
</ul>
</div>
Then in CSS:
.wrapper {
position: relative; /*so the absolute positioning works */
}
.links {
position: absolute;
top: 0;
left: 0;
opacity: 0; /*hidden by default */
width: 100%;
height: 25px; /*making this up */
}
.wrapper:hover .links, .wrapper:focus .links {
opacity: 1; /*visible on hover */
}
A couple caveats to this technique:
You will need to use an opacity filter for IE8 and below, as they don't understand the opacity CSS property
I would NOT recommend this technique for navigation, as you seem to be intending. Users on touch devices (smartphones and tablets) don't really have the "hover" state to rely on.
If you want some bonus points, though, for users with modern browsers, add this:
.links {
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
transition: all .3s ease;
}
And the links will 'fade' in - all with CSS.
if you want to hover over the image only:
div.container { width: 200px; height: 200px; position: relative; }
div.container img { width: 100%; height: 100%; position: absolute; top: 0; }
div.container img:hover { z-index: -1; }
div.container div { width: 100%; position: absolute; top: 0; }
div.container div:hover { z-index: 1; }
(the last one is needed to eliminate flicker when hovering over the links)
<div class="container">
<div> A link should be here </div>
<img src="an_img.jpg">
</div>