I'm trying to make an image inside a slider to keep its aspect ratio. With Chrome, it works like a charm. But unfortunately Safari is driving me crazy and I can't figure out why this is happening.
Screenshot from Chrome:
and here the screenshot from Safari:
I have no idea why, but Safari keeps "inserting" these gray spacings around the image.
Here is the HTML:
<div class="slideshow-wrapper">
<button
type="button"
class="visually-hidden slideshow__pause"
data-id="ee8tnv"
aria-live="polite"
>
<span class="slideshow__pause-stop">
<svg
aria-hidden="true"
focusable="false"
role="presentation"
class="m-icon m-icon--pause"
viewBox="0 0 24 24"
>
<path d="M14,19H18V5H14M6,19H10V5H6V19Z"></path>
</svg>
<span class="m-icon__fallback-text">Diashow pausieren</span>
</span>
<span class="slideshow__pause-play">
<svg
aria-hidden="true"
focusable="false"
role="presentation"
class="m-icon m-icon--play"
viewBox="0 0 24 24"
>
<path d="M8,5.14V19.14L19,12.14L8,5.14Z"></path>
</svg>
<span class="m-icon__fallback-text">Diashow abspielen</span>
</span>
</button>
<div
class="
keep-ar
slideshow slideshow--small
box
slick-initialized slick-slider slick-dotted
"
id="Slideshow-ee8tnv"
data-autoplay="false"
data-speed="5000"
>
<div class="slick-list draggable">
<div class="slick-track" style="opacity: 1; width: 750px">
<div
class="
slideshow__slide slideshow__slide--image-mgx38u
slick-slide slick-current slick-active
"
data-slick-index="0"
aria-hidden="false"
role="tabpanel"
id="slickSlide00"
aria-labelledby="slickDot00"
tabindex="-1"
style="
width: 375px;
position: relative;
left: 0px;
top: 0px;
z-index: 999;
opacity: 1;
"
>
<div class="keep-ar slideshow__image">
<picture>
<source
srcset="
//img-2.versacommerce.de/resize=master/gravity=center/++/vc-unsplash-proxy.s3.eu-central-1.amazonaws.com/UWkCguB75-E.jpg
"
/>
<img
data-src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
alt=""
/>
</picture>
</div>
<div class="slideshow__text-wrap slideshow__overlay">
<div class="keep-ar slideshow__text-content">
<div class="page-width">
<h2 class="h1 mega-title slideshow__title">Foto-Slide</h2>
<span class="mega-subtitle slideshow__subtitle">
Erzähle deine Geschichte mit Videos und Fotos
</span>
</div>
</div>
</div>
</div>
<div
class="slideshow__slide slideshow__slide--image-gy5hav slick-slide"
data-slick-index="1"
aria-hidden="true"
role="tabpanel"
id="slickSlide01"
aria-labelledby="slickDot01"
tabindex="-1"
style="
width: 375px;
position: relative;
left: -375px;
top: 0px;
z-index: 998;
opacity: 0;
"
>
<div class="keep-ar slideshow__image">
<picture>
<source
srcset="
//img-3.versacommerce.de/resize=master/gravity=center/++/vc-unsplash-proxy.s3.eu-central-1.amazonaws.com/c9FQyqIECds.jpg
"
/>
<img
data-src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
alt=""
/>
</picture>
</div>
<div class="slideshow__text-wrap slideshow__overlay">
<div class="keep-ar slideshow__text-content">
<div class="page-width">
<h2 class="h1 mega-title slideshow__title">Foto-Slide</h2>
<span class="mega-subtitle slideshow__subtitle">
Erzähle deine Geschichte mit Videos und Fotos
</span>
</div>
</div>
</div>
</div>
</div>
</div>
<ul class="slick-dots" style="display: block" role="tablist">
<li
class="slick-active"
aria-hidden="false"
role="tab"
aria-selected="true"
aria-controls="slickSlide00"
id="slickDot00"
>
<button type="button" data-role="none" role="button" tabindex="0">
Slide 1
</button>
</li>
<li
role="tab"
aria-selected="false"
aria-controls="slickSlide01"
id="slickDot01"
>
<button type="button" data-role="none" role="button" tabindex="0">
Slide 2
</button>
</li>
</ul>
</div>
</div>
and the SCSS:
slideshow-height-small: 475px;
$slideshow-height-medium: 650px;
$slideshow-height-large: 775px;
$slideshow-loader: #fff;
$z-index-slideshow-image: 1;
$z-index-slideshow-video: 2;
$z-index-slideshow-text: 3;
$z-index-slideshow-controls: 4;
$color-slideshow-close-bg: #fff;
$color-slideshow-close-text: #000;
.slideshow-wrapper {
position: relative;
}
.keep-ar.slideshow {
height: fit-content; //$slider-small--medium;
height: -moz-fit-content; //$slider-small--medium;
&--medium {
height: fit-content; //$slider-small--medium;
height: -moz-fit-content; //$slider-medium--medium;
}
&--large {
height: fit-content; //$slider-large--medium;
height: -moz-fit-content; //$slider-large--medium;
}
// Make sure slides fill full height
.slideshow__slide,
.slick-list,
.slick-track {
height: fit-content; //100%;
height: -moz-fit-content;
}
.slick-prev,
.slick-next {
height: fit-content; //100%;
height: -moz-fit-content;
}
.slick-dots {
bottom: 0.5em; //$gutter-site-mobile;
}
#include respond('medium') {
height: fit-content; //$slider-small--medium;
height: -moz-fit-content;
&--medium {
height: fit-content; //$slider-medium--medium;
height: -moz-fit-content;
}
&--large {
height: fit-content; //$slider-large--medium;
height: -moz-fit-content;
}
}
#include respond('large') {
height: fit-content; //$slider-small--large;
height: -moz-fit-content;
&--medium {
height: fit-content; //$slider-medium--large;
height: -moz-fit-content;
}
&--large {
height: fit-content; //$slider-large--large;
height: -moz-fit-content;
}
}
}
.slideshow {
overflow: hidden;
height: $slider-small--medium;
margin-bottom: 0;
&--medium {
height: $slider-medium--medium;
}
&--large {
height: $slider-large--medium;
}
// Make sure slides fill full height
.slideshow__slide,
.slick-list,
.slick-track {
height: 100%;
}
.slick-prev,
.slick-next {
top: 0;
height: 100%;
margin-top: 0;
width: 40px;
}
.slick-prev {
left: 0;
}
.slick-next {
right: 0;
}
.slick-dots {
bottom: $gutter-site-mobile;
text-align: center;
left: 50%;
transform: translateX(-50%);
// sass-lint:disable SelectorDepth
li button::before {
color: $color-slideshow-dots;
}
}
#include respond('medium') {
height: $slider-small--medium;
&--medium {
height: $slider-medium--medium;
}
&--large {
height: $slider-large--medium;
}
}
#include respond('large') {
height: $slider-small--large;
&--medium {
height: $slider-medium--large;
}
&--large {
height: $slider-large--large;
}
}
}
.video-is-playing .slick-dots {
// sass-lint:disable no-important
display: none !important;
}
// Pause button (focusable by keyboard only)
.slideshow__pause:focus {
clip: auto;
width: auto;
height: auto;
margin: 0;
color: $color-btn-primary-text;
background-color: $color-btn-primary;
padding: $gutter-site / 2;
z-index: $z-index-skip-to-content;
transition: none;
.video-is-playing & {
display: none;
}
}
.slideshow__pause-stop {
display: block;
.is-paused & {
display: none;
}
}
.slideshow__pause-play {
display: none;
.is-paused & {
display: block;
}
}
/*================ General slide styles ================*/
.slideshow__slide {
position: relative;
overflow: hidden;
}
.slideshow__link {
display: block;
position: relative;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
&:active,
&:focus {
opacity: 1;
}
}
.slideshow__overlay {
#include overlay($z-index-slideshow-text);
}
/*================ Slide images ================*/
.keep-ar.slideshow__image {
img {
object-fit: contain; //cover;
}
}
.slideshow__image {
transition: $transition-image-slideshow;
opacity: 0;
height: 100%;
picture {
display: flex;
height: 100%;
}
img {
display: block;
min-width: 100%;
width: 100%;
height: auto;
object-fit: cover;
}
.slick-initialized &,
.no-js & {
opacity: 1;
}
.slideshow__slide--background-video & {
opacity: 0;
}
.no-autoplay & {
opacity: 1;
}
}
// z-index stacking issues in oldIE
.ie9 {
.slideshow__slide {
// sass-lint:disable no-important
z-index: 1 !important;
}
.slick-dots {
z-index: 2;
}
}
/*================ Slide text ================*/
.slideshow__text-wrap {
height: 100%;
.slideshow__link & {
cursor: inherit;
}
.slideshow__slide--has-background-video & {
padding-top: $gutter-site * 3;
}
.video-is-playing & {
display: none;
}
.slideshow__slide.video-is-paused & {
display: none;
}
}
.slideshow__text-content {
text-align: center;
position: absolute;
width: 100%;
top: 50%;
#include transform(translateY(-40%));
opacity: 0;
transition: $transition-text-slideshow;
transition-delay: 0.3s;
z-index: $z-index-slideshow-text;
.slick-active &,
.no-js & {
#include transform(translateY(-50%));
opacity: 1;
}
&::after {
content: '';
#include spinner(40px, $slideshow-loader);
#include animation(spin 0.65s infinite linear);
opacity: 1;
transition: all 1s cubic-bezier(0.29, 0.63, 0.44, 1);
bottom: -$gutter-site;
left: 50%;
}
.slick-initialized &,
.no-js & {
&::after {
opacity: 0;
visibility: hidden;
content: none;
}
}
}
#media only screen and (max-width: 500px) {
.keep-ar.slideshow__text-content {
font-size: 70%;
}
}
#media only screen and (max-width: 350px) {
.keep-ar.slideshow__text-content {
font-size: 60%;
}
}
.slideshow__title {
color: $color-overlay-title-text;
}
.slideshow__subtitle {
display: block;
color: $color-overlay-title-text;
}
I was able to fix it by just setting the height of the img to 100%.
img {
display: block;
min-width: 100%;
width: 100%;
**height: 100%;**
object-fit: cover;
}
Related
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>
There should be a simple solution, but I can't work one out. I need div with class of geltona to slide onto div with class of zydra. I must use only css, but I can't. It might be obvious, but I can't find a solution as I am only using floats and % in width and height, so I can't really set a location where it should go by keyframes.
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
p {
margin: 10px;
}
.header {
height: 5%;
width: 100%;
}
.geltona {
height: 15%;
width: 50%;
background-color: yellow;
float: left;
}
.zydra {
height: 15%;
width: 50%;
background-color: lightblue;
float: right;
}
.balta {
height: 30%;
width: 70%;
background-color: white;
float: left;
}
.juoda {
height: 75%;
width: 30%;
background-color: black;
float: right;
}
.oranzine {
height: 20%;
width: 35%;
background-color: orange;
display: inline;
float: left;
}
.melyna {
position: relative;
height: 45%;
width: 35%;
background-color: blue;
float: right;
}
.zalia {
height: 25%;
width: 35%;
background-color: green;
float: left;
}
.ruda {
height: 5%;
width: 100%;
background-color: brown;
float: left;
}
/* ANIMACIJOS */
/* 3. Blokas animuotai nukeliauja ant gretimo bloko, pilnai uždengęs gretimą bloką – išnyksta */
/* 20. Pasisuka nuo 45 laipsnių iki 0 laipsnių ir padidėja 30%; */
.zalia:hover {
animation: sukasi 3s;
}
#keyframes sukasi {
0%{transform: rotate(45deg)}
100%{transform: rotate(0deg) scale(1.3)};
}
/* 21. Nuotrauka atslenka iš viršaus ir mažėja (trukmė 5 sec); */
.header img {
position: absolute;
top: -145px;
max-width: 145px;
max-height: 145px;
background: transparent;
transition: 5s;
}
.header:hover img {
transition: 5s;
top: 0;
max-width: 45px;
max-height: 45px;
}
/* MEDIA QUERIES */
#media only screen and (max-width: 768px) and (max-height: 1024px){
.geltona {
height: 25%;
width: 100%;
}
.zydra {
display: none;
}
.balta {
height: 20%;
width: 70%;
}
.juoda {
height: 65%;
width: 30%;
}
.oranzine {
display: none;
}
.melyna {
height: 45%;
width: 40%;
}
.zalia {
height: 45%;
width: 30%;
}
}
<!DOCTYPE html>
<html>
<head>
<title>IPP Kursinis</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" content="initial-scale=1">
<link rel="stylesheet" type="text/css" href="src/css/main.css">
</head>
<body>
<div class="header">
<img src="img/foto.jpg">
</div>
<div class="geltona"></div>
<div class="zydra"
id="keiciamaSpalva"
onmouseover="changeBackground(this.id, 'red', 'yellow');"
onmouseout="changeBackground(this.id, 'lightblue', 'black');">
<p>Lorem ipsum</p>
</div>
<div class="balta"
id="balta"
onmouseover="showClass();"
onmouseout="removeClass();">
</div>
<div class="juoda"></div>
<div class="oranzine"></div>
<div class="melyna">
<p id="demo"></p>
</div>
<div class="zalia"></div>
<div class="ruda"></div>
<!-- JAVASCRIPT prasideda nuo čia -->
<script type="text/javascript">
/* Keičiama teksto ir fono spalva pagal nurodymus. */
function changeBackground(id, color, textColor) {
document.getElementById(id).style.background = color;
document.getElementById(id).style.color = textColor;
};
/* Parodome bloko klasę ir ją ištriname, kad nesipildytų visas blokas*/
function showClass() {
var element = document.getElementById('balta');
element.innerHTML = element.innerHTML + "<p> Šio bloko klasė: "+element.className+"</p>";
};
function removeClass() {
document.getElementById('balta').innerHTML = "";
};
/* Rodoma lango, ekrano ir slankiklių informacija, tik tuomet, kai keičiame ekrano dydį. */
window.onresize = displayWindowSize;
function displayWindowSize(){
document.getElementById("demo").innerHTML =
"Ekrano plotis: " + screen.width + "<br>" +
"Ekrano aukštis: " + screen.height + "<br>" +
"Lango plotis: " + window.innerWidth + "<br>" +
"Lango aukštis: " + window.innerHeight + "<br>" +
"Slankiklio horizontali padėtis: " + window.scrollX + "<br>" +
"Slankiklio vertikali padėtis: " + window.scrollY;
};
</script>
</body>
</html>
With the least amount of changes for this code, I came up with this.
Wrap your two neighbouring containers (geltona and zydra) in another container (gelzy here) and give it the position:relative and the two child containers the position:absolute with left:0 and right:0 instead of the floats.
Make use of the transition on hover to move the geltona (with higher z-index)to 50% of the left to overlap on the blue container
.gelzy{
position:relative;
height:15%;
width:100%;
}
.geltona {
height: 100%;
width: 50%;
background-color: yellow;
left:0;
position: absolute;
z-index:2;
transition:left 1s ease-in-out;
}
.zydra {
height: 100%;
width: 50%;
background-color: lightblue;
right:0;
position: absolute;
}
.geltona:hover {
left:50%;
}
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
p {
margin: 10px;
}
.header {
height: 5%;
width: 100%;
}
.gelzy{
position:relative;
height:15%;
width:100%;
}
.geltona {
height: 100%;
width: 50%;
background-color: yellow;
left:0;
position: absolute;
z-index:2;
transition:left 1s ease-in-out;
}
.zydra {
height: 100%;
width: 50%;
background-color: lightblue;
right:0;
position: absolute;
}
.geltona:hover {
left:50%;
}
.balta {
height: 30%;
width: 70%;
background-color: white;
float: left;
}
.juoda {
height: 75%;
width: 30%;
background-color: black;
float: right;
}
.oranzine {
height: 20%;
width: 35%;
background-color: orange;
display: inline;
float: left;
}
.melyna {
position: relative;
height: 45%;
width: 35%;
background-color: blue;
float: right;
}
.zalia {
height: 25%;
width: 35%;
background-color: green;
float: left;
}
.ruda {
height: 5%;
width: 100%;
background-color: brown;
float: left;
}
/* ANIMACIJOS */
/* 3. Blokas animuotai nukeliauja ant gretimo bloko, pilnai uždengęs gretimą bloką – išnyksta */
/* 20. Pasisuka nuo 45 laipsnių iki 0 laipsnių ir padidėja 30%; */
.zalia:hover {
animation: sukasi 3s;
}
#keyframes sukasi {
0% {
transform: rotate(45deg)
}
100% {
transform: rotate(0deg) scale(1.3)
}
;
}
/* 21. Nuotrauka atslenka iš viršaus ir mažėja (trukmė 5 sec); */
.header img {
position: absolute;
top: -145px;
max-width: 145px;
max-height: 145px;
background: transparent;
transition: 5s;
}
.header:hover img {
transition: 5s;
top: 0;
max-width: 45px;
max-height: 45px;
}
/* MEDIA QUERIES */
#media only screen and (max-width: 768px) and (max-height: 1024px) {
.geltona {
height: 25%;
width: 100%;
}
.zydra {
display: none;
}
.balta {
height: 20%;
width: 70%;
}
.juoda {
height: 65%;
width: 30%;
}
.oranzine {
display: none;
}
.melyna {
height: 45%;
width: 40%;
}
.zalia {
height: 45%;
width: 30%;
}
}
<!DOCTYPE html>
<html>
<head>
<title>IPP Kursinis</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" content="initial-scale=1">
<link rel="stylesheet" type="text/css" href="src/css/main.css">
</head>
<body>
<div class="header">
<img src="img/foto.jpg">
</div>
<div class="gelzy">
<div class="geltona"></div>
<div class="zydra" id="keiciamaSpalva" onmouseover="changeBackground(this.id, 'red', 'yellow');" onmouseout="changeBackground(this.id, 'lightblue', 'black');">
<p>Lorem ipsum</p>
</div>
</div>
<div class="balta" id="balta" onmouseover="showClass();" onmouseout="removeClass();">
</div>
<div class="juoda"></div>
<div class="oranzine"></div>
<div class="melyna">
<p id="demo"></p>
</div>
<div class="zalia"></div>
<div class="ruda"></div>
<!-- JAVASCRIPT prasideda nuo čia -->
<script type="text/javascript">
/* Keičiama teksto ir fono spalva pagal nurodymus. */
function changeBackground(id, color, textColor) {
document.getElementById(id).style.background = color;
document.getElementById(id).style.color = textColor;
};
/* Parodome bloko klasę ir ją ištriname, kad nesipildytų visas blokas*/
function showClass() {
var element = document.getElementById('balta');
element.innerHTML = element.innerHTML + "<p> Šio bloko klasė: " + element.className + "</p>";
};
function removeClass() {
document.getElementById('balta').innerHTML = "";
};
/* Rodoma lango, ekrano ir slankiklių informacija, tik tuomet, kai keičiame ekrano dydį. */
window.onresize = displayWindowSize;
function displayWindowSize() {
document.getElementById("demo").innerHTML =
"Ekrano plotis: " + screen.width + "<br>" +
"Ekrano aukštis: " + screen.height + "<br>" +
"Lango plotis: " + window.innerWidth + "<br>" +
"Lango aukštis: " + window.innerHeight + "<br>" +
"Slankiklio horizontali padėtis: " + window.scrollX + "<br>" +
"Slankiklio vertikali padėtis: " + window.scrollY;
};
</script>
</body>
</html>
I have two horizontally aligned responsive divs that are set to be the same height.
The left holds an embedded youtube video, the right a fixed image.
Tested in Chrome there are no issues, but if tested in Safari the youtube video is not filling the full height of the div.
html markup is:
<div id="IndexBanners">
<div class="indexbannerimages effect first">
<div id="player"></div>
<script src="https://www.youtube.com/player_api"></script>
<script>
// create youtube player
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
videoId: 'GfaiXgY114U',
autoplay: '0',
controls: '0',
width: '100%',
height: '100%',
playerVars: {
rel: 0,
showinfo: 0
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// autoplay video
function onPlayerReady(event) {
// event.target.playVideo();
}
// change mask opacity depending on player state
function onPlayerStateChange(event) {
if (event.data === -1) {
document.getElementById("mask1").setAttribute("style", "opacity:1; -moz-opacity:1; filter:alpha(opacity=100)");
}
if (event.data === 0) {
document.getElementById("mask1").setAttribute("style", "opacity:1; -moz-opacity:1; filter:alpha(opacity=100)");
}
if (event.data === 1) {
document.getElementById("mask1").setAttribute("style", "opacity:0; -moz-opacity:0; filter:alpha(opacity=0)");
}
if (event.data === 2) {
document.getElementById("mask1").setAttribute("style", "opacity:1; -moz-opacity:1; filter:alpha(opacity=100)");
}
}
</script>
<div id="mask1">
<div class="watchText">Watch The Video</div>
<div class="watch"></div>
</div>
</div>
<div class="indexbannerimages effect">
<img src="https://placehold.it/795x436">
<div id="mask2">
<div class="newsText">Latest News</div>
<div class="news"></div>
</div>
</div>
</div>
css:
#IndexBanners {
display: flex;
margin-top: 20px;
}
.indexbannerimages {
flex: 1 0 0;
position: relative;
}
img {
max-width: 100%;
height: auto;
vertical-align: top;
}
.indexbannerimages .watch {
background: url(../images/play-icon.png) no-repeat scroll 0% 25% / 14px auto;
}
.indexbannerimages .news {
background: url(../images/news-icon.png) no-repeat scroll 0% 25% / 14px auto;
}
.watchText {
color: #fff;
text-transform: uppercase;
padding-top: 23%;
margin: 0;
}
.newsText {
color: #fff;
text-transform: uppercase;
padding-top: 23%;
margin: 0;
}
.effect #mask1,
.effect #mask2 {
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00, 00, 00, 0.8);
opacity: 0.75;
transition: all 0.5s ease-in-out;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
cursor: pointer;
}
.effect:hover #mask1,
.effect:hover #mask2 {
visibility: hidden;
opacity: 0.0;
transition: all 0.5s ease-in-out;
}
#media (max-width:600px) {
#IndexBanners {
display: block;
}
.first {
position: relative;
padding-bottom: 56.25%;
height: 0;
}
.first iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
I've set up a fiddle here to demonstrate the issue. https://jsfiddle.net/bgaqfvxm/3/
Any suggestions on a fix for this size issue in Safari?
Issue resolved by adding the following to the css
.first iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Thanks to #Michael Coker for the original css that was used in #media query below 600px
This question already has answers here:
How can i overlay an 10x10px image on top of another image? [duplicate]
(2 answers)
How do I position one image on top of another in HTML?
(13 answers)
Closed 5 years ago.
The aim is to have the grey images overlayed by the blue when hovered over (so that the grey image becomes the blue image).
At the moment the blue images are off centre and therefore not directly on top of the grey.
Here's how the menu currently looks when I hover over the first icon.
HTML
<div class="footerContainer">
<div class="iconContainer">
<img class="homeIcon" src="images/Home Icon.png"/> <!--grey image-->
<img class="homeIconHover" src="images/Home Icon blue.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="magIcon" src="images/Magazine Icon.png"/>
<img class="magIconHover" src="images/Magazine Icon blue.png"/>
</div>
<div class="iconContainer">
<img class="newsIcon" src="images/News Icon.png"/>
<img class="newsIconHover" src="images/News Icon blue.png"/>
</div>
<div class="iconContainer">
<img class="eventIcon" src="images/Event Icon.png"/>
<img class="eventIconHover" src="images/Event Icon blue.png"/>
</div>
<div class="iconContainer">
<img class="socialIcon" src="images/Social Icon.png"/>
<img class="socialIconHover" src="images/Social Icon blue.png"/>
</div>
</div>
CSS
.footerContainer{
border-top: rgba(0,0,0,0.8) 2px solid;
height: 5rem;
display: flex;
background-color: #e5e5e5;
background-size: cover;
margin: 0;
padding: 0;
text-align: center;
position: relative;
}
.iconContainer{
width: 20%;
margin: auto;
}
/* grey images */
.homeIcon{
text-align: center;
height: 71px;
margin: auto;
position: relative;
}
.magIcon{
text-align: center;
height: 58px;
margin: auto;
position: relative;
}
.newsIcon{
text-align: center;
height: 64px;
margin: auto;
position: relative;
}
.eventIcon{
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
.socialIcon{
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
/* HOVER */
/* blue images */
.homeIconHover{
text-align: center;
height: 71px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .homeIconHover{
opacity: 1;
}
.iconContainer:hover .homeIcon{
opacity: 0;
}
.magIconHover{
text-align: center;
height: 58px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .magIconHover{
opacity: 1;
}
.iconContainer:hover .magIcon{
opacity: 0;
}
.newsIconHover{
text-align: center;
height: 64px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .newsIconHover{
opacity: 1;
}
.iconContainer:hover .newsIcon{
opacity: 0;
}
.eventIconHover{
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .eventIconHover{
opacity: 1;
}
.iconContainer:hover .eventIcon{
opacity: 0;
}
.socialIconHover{
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .socialIconHover{
opacity: 1;
}
.iconContainer:hover .socialIcon{
opacity: 0;
}
Cheers in advance
Add position: relative to .iconContainer so that the absolute positioning on the overlay image will be relative to it's parent. Then use top: 0; left: 50%; transform: translateX(-50%); on the overlay image to position it in the center of the container like the other image.
.footerContainer {
border-top: rgba(0, 0, 0, 0.8) 2px solid;
height: 5rem;
display: flex;
background-color: #e5e5e5;
background-size: cover;
margin: 0;
padding: 0;
text-align: center;
position: relative;
}
.iconContainer {
width: 20%;
margin: auto;
position: relative;
}
/* grey images */
.homeIcon {
text-align: center;
height: 71px;
margin: auto;
position: relative;
}
.magIcon {
text-align: center;
height: 58px;
margin: auto;
position: relative;
}
.newsIcon {
text-align: center;
height: 64px;
margin: auto;
position: relative;
}
.eventIcon {
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
.socialIcon {
text-align: center;
height: 80px;
margin: auto;
position: relative;
}
/* HOVER */
/* blue images */
.homeIconHover {
text-align: center;
height: 71px;
margin: auto;
opacity: 0;
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
}
.iconContainer:hover .homeIconHover {
opacity: 1;
}
.iconContainer:hover .homeIcon {
opacity: 0;
}
.magIconHover {
text-align: center;
height: 58px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .magIconHover {
opacity: 1;
}
.iconContainer:hover .magIcon {
opacity: 0;
}
.newsIconHover {
text-align: center;
height: 64px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .newsIconHover {
opacity: 1;
}
.iconContainer:hover .newsIcon {
opacity: 0;
}
.eventIconHover {
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .eventIconHover {
opacity: 1;
}
.iconContainer:hover .eventIcon {
opacity: 0;
}
.socialIconHover {
text-align: center;
height: 80px;
margin: auto;
opacity: 0;
position: absolute;
}
.iconContainer:hover .socialIconHover {
opacity: 1;
}
.iconContainer:hover .socialIcon {
opacity: 0;
}
<div class="footerContainer">
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
<div class="iconContainer">
<img class="homeIcon" src="http://kenwheeler.github.io/slick/img/lazyfonz2.png"/> <!--grey image-->
<img class="homeIconHover" src="http://kenwheeler.github.io/slick/img/lazyfonz3.png"/> <!--blue image-->
</div>
</div>
instead you can use css to change the color of all images to black and white. https://jsfiddle.net/z57s6quj/
img {
transition: all 200ms;
filter: grayscale(100%);
}
img:hover {
filter: none
}
take a look on compatibility
http://caniuse.com/#search=filter
Another alternative would be to use SVGs for your icons and style the fill on hover. SVGs are Scalable Vector Graphics so stay sharp at any device resolution or scale.
Here's a simple example:
svg {width:20%}
svg path {
fill: grey;
}
svg:hover path {
fill: blue;
}
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<title>home</title>
<path d="M32 18.451l-16-12.42-16 12.42v-5.064l16-12.42 16 12.42zM28 18v12h-8v-8h-8v8h-8v-12l12-9z"></path>
</svg>
<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<title>book</title>
<path d="M28 4v26h-21c-1.657 0-3-1.343-3-3s1.343-3 3-3h19v-24h-20c-2.2 0-4 1.8-4 4v24c0 2.2 1.8 4 4 4h24v-28h-2z"></path>
<path d="M7.002 26v0c-0.001 0-0.001 0-0.002 0-0.552 0-1 0.448-1 1s0.448 1 1 1c0.001 0 0.001-0 0.002-0v0h18.997v-2h-18.997z"></path>
</svg>
Just an "outside-the-box" answer. You don't need second images in the first place, but rather can use filters to achieve the same effekt.
Below are two different approaches. filter has really good support and uses a regular image and background-blend-mode is not there yet supportwise (thanks, Microsoft!) but uses background-images.
#one{
background-image: url('http://lorempixel.com/200/100/sports/1');
background-color: blue;
background-blend-mode: screen;
width:200px;height:100px;
margin-right:10px;
float:left;
}
#one:hover{
background-color: transparent;
}
#two{
background-color: red;
height:100px; width:200px;
float:left;
}
#two img{
filter:grayscale(100%);
opacity:.5;
}
#two img:hover{
filter:grayscale(0%);
opacity:1;
}
<h3>Hover the images:</h3>
<div id="one">
</div>
<div id="two">
<img src="http://lorempixel.com/200/100/sports/1" />
</div>
I have a small bug that I can't seem to locate. In my snippet you can see how whenever you hover over the image, opactiy and an image scale takes place, as well as a box comes over the image. That is perfect, but my issue is whenever you hover over the text below it, the hover effect takes place over the image.
I can't seem to figure out how for the hover effect to only take place when the mouse is hovering over the image.
Any suggestions would be appreciated.
$('.home-img-block img').addClass(function() {
return (this.width / this.height > 1) ? 'wide' : 'tall';
});
#home-img-block-section {
width: 100%;
height: 900px;
}
#home-img-blocks {
width: 100%;
height: 750px;
}
.home-img-block {
width: 33.33%;
float: left;
display: block;
overflow: hidden;
position: relative;
}
.home-img-container {
position: relative;
overflow: hidden;
cursor: pointer;
}
.home-img-block:hover .overlay {
background: rgba(0, 0, 0, 0.6);
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.home-img-container:after {
content: attr(data-content);
color: #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
transition: all 0.5s;
border: 1px solid #fff;
padding: 20px 25px;
text-align: center;
}
.home-img-container:hover:after {
opacity: 1;
}
.home-img-block img {
display: block;
transition: all 1s ease;
}
.home-img-block:hover img {
transform: scale(1.25);
background: rgba(0, 0, 0, 0.3);
width: 33.33%;
max-height: 100%;
overflow: hidden;
}
.home-img-block img.wide {
max-width: 100%;
max-height: 100%;
height: auto;
width: 100%;
}
.home-img-block img.tall {
max-width: 100%;
max-height: 100%;
width: auto;
}
#home-img-block-wording-container {
width: 100%;
height: 300px;
}
.home-img-wording-blocks {
width: 100%;
height: 100%;
text-align: center;
display: inline-block;
vertical-align: top;
}
.home-img-wording-block-title {
padding-top: 30px;
font-size: 1.7em;
}
.home-img-wording-block-description {
padding: 25px 50px 0 50px;
font-size: 1.1em;
color: #5d5d5d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="home-img-block-section">
<div id="home-img-blocks">
<div class="home-img-block fadeBlock1">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test1.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">WEB DESIGN</div>
<div class="home-img-wording-block-description">The OD team can see your web design visions brought
to life, creating a site that promotes your uniqueness through specific functionalities and features.</div>
</div>
</div>
<div class="home-img-block fadeBlock2">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test2new.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">ECOMMERCE</div>
<div class="home-img-wording-block-description">Custom built solutions catered towards you end goal.
gfdgfdsg greg reg regrfesg fdsg gretswtgy tgreswt treswt trgegfd gsvbd fbgre greasgv drfdg greaag gredr</div>
</div>
</div>
<div class="home-img-block fadeBlock3">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test3new.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">MARKETING STRATEGIES</div>
<div class="home-img-wording-block-description">MARKETING STRATEGIES gfdgf fdggs gfsg gfsg gf sgf g
gfdsg sdfggfs gfdsgssdfg fdggfds gfdsg gfds gfdgs gf dsgfdsgfgs gfdgfs gtrg resg reg rgesgresrgrg</div>
</div>
</div>
</div>
</div>
.home-img-block:hover .overlay
and
.home-img-block:hover img
replace them with
.home-img-container:hover .overlay
.home-img-container:hover img
otherwise you're triggering when you hover over the whole container instead of only wheen hovering the img one.