Hello! I have next problem. I want when image is in hover, some color appears. I did it, but what happened. This color is a little over image. You can see on image.
I want if image is 300×300, color also would be 300×300, not 320×300.
HTML
`<div class=”container-overlay”>
<img src=”kuhinja-portfolio.jpg” alt=”kitchen” class=”image”>
<div class=”overlay overlayLeft”>
<div class=”textt”>See more</div>
</div>
</div>
<div class=”container-overlay”>
<img src=”kupatilo portfolio.jpg” alt=”kitchen” class=”image”>
<div class=”overlay overlayFade”>
<div class=”textt”><a href=”kitchen.html” target=”_blank” class=”link”>See more</a></div>
</div>
</div>
<div class=”container-overlay”>
<img src=”livingroom portfolio.jpg” alt=”kitchen” class=”image”>
<div class=”overlay overlayFade”>
<div class=”textt”><a href=”kitchen.html” target=”_blank” class=”link”>See more</a></div>
</div>
</div>
<div class=”container-overlay”>
<img src=”bedroom porfolio.jpg” alt=”kitchen” class=”image”>
<div class=”overlay overlayFade”>
<div class=”textt”><a href=”kitchen.html” target=”_blank” class=”link”>See more</a></div>
</div>
</div>
</div>`
CSS
.images-gallery {
display: flex;
flex-wrap: wrap;
width: 90%;
margin: 4% auto ;
}
.images-gallery .container-overlay {
flex-basis: 25%;
}
.images-gallery .container-overlay img {
display: block;
margin: 0 auto;
}
.container-overlay {
position: relative;
width: 350px;
height: 240px;
display: inline-block;
}
.image {
display: block;
}
.overlay {
position: absolute;
transition: all 1s ease;
opacity: 0;
background-color: #eee;
}
.container-overlay:hover .overlay {
opacity: 1;
}
.textt {
color: white;
font-family: sans-serif;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
font-size: 20px;
}
.overlayLeft {
height: 100%;
width: 0;
top: 0;
left: 0;
background-color: #00b1ba;
}
.container-overlay:hover .overlayLeft {
width: 100%;
}
.overlayFade {
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: #f7a145b5;
}
I am pretty sure the problem is in this line .images-gallery .container-overlay {
flex-basis: 25%;
}
but I don’t have idea how to fix it. I tried on many ways, but it wasn’t successfull.
When I remove display:flex, my images are not responsive, so I don’t have idea how to fix it, and I really need it as soon as possible.
I hope somebody will know how to fix this problem. Thanks once more
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>
<style>
.images-gallery {
display: flex;
flex-wrap: wrap;
width: 90%;
margin: 4% auto;
}
<i> </i> .images-gallery .container-overlay img {
<i> </i> display: block;
<i> </i> margin: 0 auto;
<i> </i> }
<i> </i> .container-overlay {
<i> </i> position: relative;
<i> </i> /* width: 350px;
<i> </i> height: 240px; */
<i> </i> display: inline-block;
<i> </i> }
<i> </i> .image {
<i> </i> width: 100%;
<i> </i> display: block;
<i> </i> }
<i> </i> .overlay {
<i> </i> position: absolute;
<i> </i> transition: all 1s ease;
<i> </i> opacity: 0;
<i> </i> background-color: #eee;
<i> </i> }
<i> </i> .container-overlay:hover .overlay {
<i> </i> opacity: 1;
<i> </i> }
<i> </i> .textt {
<i> </i> color: white;
<i> </i> font-family: sans-serif;
<i> </i> position: absolute;
<i> </i> top: 50%;
<i> </i> left: 50%;
<i> </i> transform: translate(-50%, -50%);
<i> </i> font-size: 20px;
<i> </i> }
<i> </i> .overlayLeft {
<i> </i> height: 100%;
<i> </i> width: 0;
<i> </i> top: 0;
<i> </i> left: 0;
<i> </i> background-color: #00b1ba;
<i> </i> }
<i> </i> .container-overlay:hover .overlayLeft {
<i> </i> width: 100%;
<i> </i> }
<i> </i> .overlayFade {
<i> </i> width: 100%;
<i> </i> height: 100%;
<i> </i> top: 0;
<i> </i> left: 0;
<i> </i> background-color: #f7a145b5;
<i> </i> }
<i> </i> .images-gallery .container-overlay {
<i> </i> flex: 1;
<i> </i> margin-left: 0.5em;
<i> </i> margin-right: 0.5em;
<i> </i> }
<i> </i></style>
</head>
<body>
<div class="images-gallery">
<div class="container-overlay">
<i> </i> <img src="images/dia0.jpg" alt="kitchen" class="image">
<i> </i> <div class="overlay overlayLeft">
<i> </i> <div class="textt">See more</div>
<i> </i> </div>
<i> </i> </div>
<i> </i> <div class="container-overlay">
<i> </i> <img src="images/dia1.jpg" alt="kitchen" class="image">
<i> </i> <div class="overlay overlayFade">
<i> </i> <div class="textt"><a href="kitchen.html" target="_blank" class="link">See more</a></div>
<i> </i> </div>
<i> </i> </div>
<i> </i> <div class="container-overlay">
<i> </i> <img src="images/dia2.jpg" alt="kitchen" class="image">
<i> </i> <div class="overlay overlayFade">
<i> </i> <div class="textt"><a href="kitchen.html" target="_blank" class="link">See more</a></div>
<i> </i> </div>
<i> </i> </div>
<i> </i> <div class="container-overlay">
<i> </i> <img src="images/dia3.jpg" alt="kitchen" class="image">
<i> </i> <div class="overlay overlayFade">
<i> </i> <div class="textt"><a href="kitchen.html" target="_blank" class="link">See more</a></div>
<i> </i> </div>
<i> </i> </div>
<i> </i></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>
<style>
/* CSS for Ken Burns */
<i> </i> .cycle-slideshow {
<i> </i> max-width: 980px;
<i> </i> overflow: hidden;
<i> </i> }
<i> </i> .cycle-slideshow img {
<i> </i> width: 100%;
<i> </i> height: auto;
<i> </i> transition: transform 8s linear;
<i> </i> }
<i> </i> .cycle-slideshow .scale {
<i> </i> transform: scale(1.1);
<i> </i> }
<i> </i> .cycle-slideshow .fx1 {
<i> </i> transform-origin: bottom left;
<i> </i> }
<i> </i> .cycle-slideshow .fx2 {
<i> </i> transform-origin: top left;
<i> </i> }
<i> </i> .cycle-slideshow .fx3 {
<i> </i> transform-origin: top right;
<i> </i> }
<i> </i> .cycle-slideshow .fx4 {
<i> </i> transform-origin: bottom right;
<i> </i> }
<i> </i></style>
<i> </i><style>
<i> </i> /* CSS for captions */
<i> </i> .ovl-caption {
<i> </i> width: 100%;
<i> </i> text-align: center;
<i> </i> position: absolute;
<i> </i> z-index: 901;
<i> </i> left: 0;
<i> </i> transform: translateY(-50%);
<i> </i> overflow: hidden;
<i> </i> }
<i> </i> .ovl1 {
<i> </i> top: 30%;
<i> </i> }
<i> </i> .ovl2 {
<i> </i> top: 50%;
<i> </i> }
<i> </i> .caption {
<i> </i> display: inline-block;
<i> </i> padding: 0.2rem 0.5rem;
<i> </i> color: white;
<i> </i> font-size: 2rem;
<i> </i> transform: translateY(100%);
<i> </i> transition: transform 0.5s;
<i> </i> }
<i> </i> .ovl2 .caption {
<i> </i> transition-delay: 0.2s;
<i> </i> }
<i> </i> .caption.up {
<i> </i> transform: translateY(0);
<i> </i> }
<i> </i> .ovlbg {
<i> </i> width: 100%;
<i> </i> height: 100%;
<i> </i> text-align: center;
<i> </i> position: absolute;
<i> </i> z-index: 900;
<i> </i> left: 0;
<i> </i> top: 0;
<i> </i> background-color: black;
<i> </i> opacity: 0;
<i> </i> transition: opacity 0.5s;
<i> </i> }
<i> </i> .ovlbg.on {
<i> </i> opacity: 0.7;
<i> </i> }
<i> </i></style>
<i> </i><script src="https://code.jquery.com/jquery-3.4.1.min.js"
<i> </i> integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<i> </i><script src="js/jquery.cycle2.js"></script>
</head>
<body>
<div class="cycle-slideshow" data-cycle-timeout="8000">
<img src="images/01.png" data-caption1="Caption 1.1" data-caption2="Caption 2.1">
<img src="images/02.png" data-caption1="Caption 1.2" data-caption2="Caption 2.2">
<img src="images/03.png" data-caption1="Caption 1.3" data-caption2="Caption 2.3">
<img src="images/04.png" data-caption1="Caption 1.4" data-caption2="Caption 2.4">
<!-- Overlays for captions -->
<div class="ovlbg"></div> <!-- darkens the image -->
<div class="ovl-caption ovl1"><span class="caption"></span></div>
<div class="ovl-caption ovl2"><span class="caption"></span></div>
</div>
<script>
// Javascript for Ken Burns
<i> </i> var new_effect;
<i> </i> var old_effect;
<i> </i> function random_effect() {
<i> </i> return Math.floor(Math.random() * 4) + 1;
<i> </i> }
<i> </i> new_effect = random_effect();
<i> </i> $('.cycle-slideshow').on('cycle-initialized', function () {
<i> </i> $('.cycle-slideshow img:first-of-type').addClass('scale');
<i> </i> $('.cycle-slideshow img:first-of-type').addClass('fx' + new_effect);
<i> </i> $('.cycle-slideshow').on('cycle-before', function (event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
<i> </i> old_effect = new_effect;
<i> </i> new_effect = random_effect();
<i> </i> $(incomingSlideEl).addClass('scale');
<i> </i> $(incomingSlideEl).addClass('fx' + new_effect);
<i> </i> });
<i> </i> $('.cycle-slideshow').on('cycle-after', function (event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
<i> </i> $(outgoingSlideEl).removeClass('scale');
<i> </i> $(outgoingSlideEl).removeClass('fx' + old_effect);
<i> </i> });
<i> </i> });
<i> </i></script>
<i> </i><script>
<i> </i> // Javascript for captions
<i> </i> const delay = 3000; // delay after which the captions appear
<i> </i> const caption1 = $('.ovl1 .caption');
<i> </i> const caption2 = $('.ovl2 .caption');
<i> </i> const ovlbg = $('.ovlbg');
<i> </i> function captionUp(slide) {
<i> </i> setTimeout(function () {
<i> </i> caption1.text(slide.attr('data-caption1'));
<i> </i> caption1.addClass('up');
<i> </i> caption2.text(slide.attr('data-caption2'));
<i> </i> caption2.addClass('up');
<i> </i> ovlbg.addClass('on');
<i> </i> }, delay);
<i> </i> }
<i> </i> captionUp($('.cycle-slideshow img:first-child'));
<i> </i> $('.cycle-slideshow').on('cycle-before', function (event, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
<i> </i> caption1.removeClass('up');
<i> </i> caption2.removeClass('up');
<i> </i> ovlbg.removeClass('on');
<i> </i> captionUp($(incomingSlideEl));
<i> </i> });
<i> </i></script>
</body>
</html>
Check if it fits your needs. <div class="ovl-caption ovl1"><span class="caption"></span></div>
<div class="ovl-caption ovl2"><span class="caption"></span></div>
.ovlcaption.ovl1 span {
font-size: 50px;
}
.ovlcaption.ovl2 span {
font-size: 30px;
}
Alternatively you might assign individual classes to the spans, this would shorten the selectors a bit. .ovl-caption.ovl1 span {
font-size: 50px;
}
<i> </i> .ovl-caption.ovl2 span {
<i> </i> font-size: 30px;
<i> </i> }
<style>
/* CSS for buttons */
.ovl-caption.btn {
top: 70%;
transform: translateY(-50%);
}
<i> </i> .ovl-caption.btn button {
<i> </i> transition: transform 0.5s;
<i> </i> transition-delay: 0.4s;
<i> </i> transform: translateY(125%);
<i> </i> }
<i> </i> .ovl-caption.btn button.up {
<i> </i> transform: translateY(0);
<i> </i> }
<i> </i></style>
If it doesn't work for you, you can modify the value of 125%. <div class="ovl-caption btn"><button>Button</button></div>
` <style>
/* CSS for back/next buttons */
<i> </i> .cycle-prev,
<i> </i> .cycle-next {
<i> </i> width: 4rem;
<i> </i> height: 4rem;
<i> </i> /* border: 0.2rem solid lightgrey; */
<i> </i> border-radius: 50%;
<i> </i> background-color: rgba(127, 127, 127, 0.3);
<i> </i> position: absolute;
<i> </i> top: 50%;
<i> </i> transform: translateY(-50%);
<i> </i> display: flex;
<i> </i> justify-content: center;
<i> </i> align-items: center;
<i> </i> z-index: 999;
<i> </i> }
<i> </i> .cycle-prev::before,
<i> </i> .cycle-next::before {
<i> </i> width: 4rem;
<i> </i> height: 4rem;
<i> </i> color: white;
<i> </i> font-size: 2rem;
<i> </i> display: flex;
<i> </i> justify-content: center;
<i> </i> align-items: center;
<i> </i> }
<i> </i> .cycle-prev {
<i> </i> left: 0;
<i> </i> }
<i> </i> .cycle-prev::before {
<i> </i> content: "3008";
<i> </i> transform: translateX(-0.2rem);
<i> </i> }
<i> </i> .cycle-next {
<i> </i> right: 0;
<i> </i> }
<i> </i> .cycle-next::before {
<i> </i> content: "3009";
<i> </i> transform: translateX(0.2rem);
<i> </i> }
<i> </i></style>
0.1.9 — BETA 4.25