Display background-image on page when hovering button Css - html

I've been trying to set the background image of my outer container by having the image transition into the background of my website. But nothing displays, is there something im missing in the css that would allow me to display the background image?
Pen: https://codepen.io/chriskaram/pen/BwVXGq
Page: https://mydietgoal.com/mydietgoal-features-and-plans/
<div class="outer-container" id="backgroundDiv" style="width: max-content; height: max-content;">
<div class="container container1">
<div class="w-table">
<div class="w-table-cell">
<div class="w-container">
<div class="w-card color-green">
<div class="card-header">
<div class="w-title" style="cursor:default">
<h2><font size="7px">Novice</font></h2>
</div>
<div class="w-price" style="cursor:default">
$4.99
<h3>/ Week</h3>
</div>
<div class="container-button">
<a class="w-button" id="btn1" href="/meal-planner" target="_blank">Sign up </a>
</div>
</div>
<div class="card-content" style="cursor:default">
<div class="w-item" style="cursor:default">
<span>Weekly </span>Meal Plans
</div>
<div class="w-item" style="cursor:default">
<span>Personal </span>Dietary Assessment and Advice
</div>
<div class="w-item" style="cursor:default">
<span>Full </span>Access to the Food Catalogue
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container container2">
<div class="w-table">
<div class="w-table-cell">
<div class="w-container">
<div class="w-card color-blue">
<div class="card-header">
<div class="w-title" style="cursor:default">
<h2><font size="7px">Novice</font></h2>
</div>
<div class="w-price" style="cursor:default">
$9.99
<h3>/ Week</h3>
</div>
<div class="container-button">
<a class="w-button" href="/meal-planner" target="_blank">Sign up </a>
</div>
</div>
<div class="card-content" style="cursor:default">
<div class="w-item" style="cursor:default">
<span>Weekly </span>Meal Plans
</div>
<div class="w-item" style="cursor:default">
<span>Personal </span>Dietary Assessment and Advice
</div>
<div class="w-item" style="cursor:default">
<span>Full </span>Access to the Food Catalogue
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container container3">
<div class="w-table">
<div class="w-table-cell">
<div class="w-container">
<div class="w-card color-orange">
<div class="card-header">
<div class="w-title" style="cursor:default">
<h2><font size="7px">Novice</font></h2>
</div>
<div class="w-price" style="cursor:default">
$4.99
<h3>/ Week</h3>
</div>
<div class="container-button">
<a class="w-button" href="/meal-planner" target="_blank">Sign up </a>
</div>
</div>
<div class="card-content" style="cursor:default">
<div class="w-item" style="cursor:default">
<span>Weekly </span>Meal Plans
</div>
<div class="w-item" style="cursor:default">
<span>Personal </span>Dietary Assessment and Advice
</div>
<div class="w-item" style="cursor:default">
<span>Full </span>Access to the Food Catalogue
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

This block of code
#btn1:hover + .outer-container {
background-image: url(https://static1.squarespace.com/static/59a7820e2994ca11766093d3/t/59dbd720f5e2317170edb5bf/1507579681913/vegetables-fresh-healthy-food-my-diet-goal-hd.jpg);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
means when #btn is :hover, the next direct sibling with .outer-container gets background-image.
However, according to your code, .outer-container is the grand grand grand grand grand grand grand grandparent of #btn. So it will not work.
Bad news is, CSS has no way to select ancestors.
So I suggest you use JavaScript to do it.
Working Example

CSS only allows descendant and sibling selectors, it does not support applying styles to a parent. https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_selectors
To achieve this effect, you would want a div at the same level as the button with the hover trigger that is positioned, fixed or absolute (you will need to change your markup to support absolute)
Here is an example:
.bg,
.bg2 {
position: fixed;
width: 100%;
top: 0;
left: 0;
height: 100%;
z-index: -1;
}
#btn1:hover + .bg,
.bg2 {
background-image: url(https://static1.squarespace.com/static/59a7820e2994ca11766093d3/t/59dbd720f5e2317170edb5bf/1507579681913/vegetables-fresh-healthy-food-my-diet-goal-hd.jpg);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
transition: opacity 0.5s;
}
.bg2 {
opacity: 0;
}
#btn2:hover ~ .bg2 {
opacity: 1;
}
I also added an opacity transform for the second button as I feel it is less jarring.
https://codepen.io/jaylandro/pen/qPypmb

Related

Materialize parallax scrolling resize in mobile view?

I am having issues with my .parallax CSS class that is done default by the framework it's not resizing like my main image when it comes to mobile view. It works well with a desktop view. They move more to the left the last two images is there a possibility to move them more center? I tried to center them using position: no-repeat fixed center; in CSS or using frameworks default parameters.
https://i.imgur.com/itVR3No.jpg
The image goes off to the left and does not center.
$(document).ready(function() {
$('.parallax').parallax();
});
.ha-bg-parallax {
background: url(https://i.imgur.com/YqK1Oeu.jpg) no-repeat fixed center;
-moz-background-size: cover;
-o-background-size: cover;
-webkit-background-size: cover;
background-size: cover;
height: 100vh;
margin: 0 auto;
width: 100%;
display: table;
vertical-align: middle;
}
.parallax{
position: no-repeat fixed center;
max-width:100%;
}
.ha-bg-parallax .ha-parallax-body {
display: table-cell;
vertical-align: middle;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
<div class="navbar-fixed">
<nav class="blue darken-1">
</nav>
</div>
<div class="ha-bg-parallax text-center block-marginb-none" data-speed="20" data-type="background">
<div class="ha-parallax-body">
<div class="section scrollspy row title" id="home">
</div>
</div>
</div>
<div class="section light-blue lighten-5">
<div class="row container">
<div class="section scrollspy" id="info">
</div>
</div>
</div>
<div class="parallax-container">
<div class="parallax"><img alt="header1" src="https://i.imgur.com/QFPutVs.jpg"></div>
</div>
<div class="section light-blue lighten-5">
<div class="section scrollspy" id="portfolio">
</div>
<!--row for parallax-->
</div>
<div class="parallax-container">
<div class="parallax"><img alt="header2" src="https://i.imgur.com/gyYRcBK.jpg"></div>
</div>
<!--Floating Action Button custumize-->
<footer class="page-footer blue darken-1">
<div class="col l4 offset-l2 s12 container center">
<div class="section scrollspy" id="links">
</div>
</div>

transform image in a bootstrap card

here is my problem, I have successfully encoded my bootstrap cards as I wish, but a small details grieves me.
I would like to make sure that the buttons 'infos' and 'mods' are not taken into account by "transform scale"
Only I can scratch my head and try all sorts of things I can not get out of this pass.
Here is the CSS & HTML code.
<div class="card-deck row">
<div class="col-3"><!--event serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse event serv">
<h5>Special event</h5><p class="lead">PVP / PVE</p>
Infos
Mods
</div>
</div>
</div>
</div><!--/event serv-->
<div class="col-6"><!--island serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse island serv">
<h5>The island</h5><p class="lead">PVE x 3</p>
Infos
Mods
</div>
</div>
</div>
</div><!--/island serv-->
<div class="col-3"><!--scorched serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse scorched serv">
<h5>Scorched earth</h5><p class="lead">PVE x 3</p>
Infos
Mods
</div>
</div>
</div>
</div><!--/scorched serv-->
</div>
CSS:
.event{background-image: url(https://images2.alphacoders.com/819/819763.jpg);background-size:cover;background-position: center;}
.island{
background-image: url(https://s-media-cache-ak0.pinimg.com/originals/3b/91/6b/3b916b8b33b7aa08bf8fb920be2aa536.jpg);
background-size:cover;
background-position: center;
}
.scorched{
background-image: url(https://images4.alphacoders.com/819/819770.jpg);
background-size:cover;
background-position: center;}
.card{overflow:hidden;}
.serv{position:relative;}
.serv:hover{transform:scale(1.1);transition:all 0.7s;}
Someone know where my problem comes from? thank you very much !
If you just want the image to scale, move the background to an ::after pseudo element of .serv, give the pseudo element a negative z-index so it's behind the text, position the pseudo element absolutely, move the transition to .serv::after instead of only on the :hover pseudo class of .serv, and fire transform: scale() on .serv::after instead of .serv.
.event::after {
background-image: url(https://images2.alphacoders.com/819/819763.jpg);
background-size: cover;
background-position: center;
}
.island::after {
background-image: url(https://s-media-cache-ak0.pinimg.com/originals/3b/91/6b/3b916b8b33b7aa08bf8fb920be2aa536.jpg);
background-size: cover;
background-position: center;
}
.scorched::after {
background-image: url(https://images4.alphacoders.com/819/819770.jpg);
background-size: cover;
background-position: center;
}
.card {
overflow: hidden;
}
.serv {
position: relative;
}
.serv::after {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
z-index: -1;
transition: transform 0.7s;
}
.serv:hover::after {
transform: scale(1.1);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="card-deck row">
<div class="col-3">
<!--event serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse event serv">
<h5>Special event</h5>
<p class="lead">PVP / PVE</p>
Infos
Mods
</div>
</div>
</div>
</div>
<!--/event serv-->
<div class="col-6">
<!--island serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse island serv">
<h5>The island</h5>
<p class="lead">PVE x 3</p>
Infos
Mods
</div>
</div>
</div>
</div>
<!--/island serv-->
<div class="col-3">
<!--scorched serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse scorched serv">
<h5>Scorched earth</h5>
<p class="lead">PVE x 3</p>
Infos
Mods
</div>
</div>
</div>
</div>
<!--/scorched serv-->
</div>
</div>
Or if you're using bootstrap 4, give .serv a z-index so it's above .card.bg-inverse since that will assign a dark background color and cover the .serv::after background image.
.event::after {
background-image: url(https://images2.alphacoders.com/819/819763.jpg);
background-size: cover;
background-position: center;
}
.island::after {
background-image: url(https://s-media-cache-ak0.pinimg.com/originals/3b/91/6b/3b916b8b33b7aa08bf8fb920be2aa536.jpg);
background-size: cover;
background-position: center;
}
.scorched::after {
background-image: url(https://images4.alphacoders.com/819/819770.jpg);
background-size: cover;
background-position: center;
}
.card {
overflow: hidden;
}
.serv {
position: relative;
z-index: 1;
}
.serv::after {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
z-index: -1;
transition: transform 0.7s;
}
.serv:hover::after {
transform: scale(1.1);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="card-deck row">
<div class="col-3">
<!--event serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse event serv">
<h5>Special event</h5>
<p class="lead">PVP / PVE</p>
Infos
Mods
</div>
</div>
</div>
</div>
<!--/event serv-->
<div class="col-6">
<!--island serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse island serv">
<h5>The island</h5>
<p class="lead">PVE x 3</p>
Infos
Mods
</div>
</div>
</div>
</div>
<!--/island serv-->
<div class="col-3">
<!--scorched serv-->
<div class="card">
<div class="card bg-inverse">
<div class="card-block card-inverse scorched serv">
<h5>Scorched earth</h5>
<p class="lead">PVE x 3</p>
Infos
Mods
</div>
</div>
</div>
</div>
<!--/scorched serv-->
</div>
</div>
https://www.w3schools.com/css/css_pseudo_classes.asp
Use :not(a) in .serv for translation. That should work.

How to make image responsive while calling

I have a below HTML code in which the images are purely responsive.
<div class="flexslider js-fullheight">
<ul class="slides">
<li style="background-image: url(images/slide_1.jpg); width:100%;" border="0" alt="Null">
<div class="overlay-gradient"></div>
<div class="container">
<div class="col-md-10 col-md-offset-1 text-center js-fullheight slider-text">
<div class="slider-text-inner">
<h2>Start Your Startup With This Template</h2>
<p>Get started</p>
</div>
</div>
</div>
</li>
<li style="background-image: url(images/slide_3.jpg);">
<div class="container">
<div class="col-md-10 col-md-offset-1 text-center js-fullheight slider-text">
<div class="slider-text-inner">
<h2>Take Your Business To The Next Level</h2>
<p>Get started</p>
</div>
</div>
</div>
</li>
<li style="background-image: url(images/slide_2.jpg);">
<div class="container">
<div class="col-md-10 col-md-offset-1 text-center js-fullheight slider-text">
<div class="slider-text-inner">
<h2>We Think Different That Others Can't</h2>
<p>Get started</p>
</div>
</div>
</div>
</li>
</ul>
</div>
In this, the slide_1.jpg image is responsive. What I want is, I want to replace this image with my actual Image.
I tried changing the image by giving width:100% but the Image was still getting stretched. Any idea, how to make that image responsive.
Update
and the css is below
#fh5co-hero .flexslider .slider-text > .slider-text-inner {
display: table-cell;
vertical-align: middle;
min-height: 700px;
}
#fh5co-hero .flexslider .slider-text > .slider-text-inner h2 {
font-size: 70px;
font-weight: 400;
color: #fff;
}
#media screen and (max-width: 768px) {
#fh5co-hero .flexslider .slider-text > .slider-text-inner h2 {
font-size: 40px;
}
}
#fh5co-hero .flexslider .slider-text > .slider-text-inner .fh5co-lead {
font-size: 20px;
color: #fff;
}
<div class="flexslider js-fullheight">
<ul class="slides">
<li style="background-image: url(/images/slide_1.jpg);">
<div class="overlay-gradient"></div>
<div class="container">
<div class="col-md-10 col-md-offset-1 text-center js-fullheight slider-text">
<div class="slider-text-inner">
<h2>Start Your Startup With This Template</h2>
<!--<p>Get started</p>-->
</div>
</div>
</div>
</li>
<li style="background-image: url(images/slide_3.jpg);">
<div class="container">
<div class="col-md-10 col-md-offset-1 text-center js-fullheight slider-text">
<div class="slider-text-inner">
<h2>Take Your Business To The Next Level</h2>
<!--<p>Get started</p>-->
</div>
</div>
</div>
</li>
<li style="background-image: url(images/slide_2.jpg);">
<div class="container">
<div class="col-md-10 col-md-offset-1 text-center js-fullheight slider-text">
<div class="slider-text-inner">
<h2>We Think Different That Others Can't</h2>
<!--<p>Get started</p>-->
</div>
</div>
</div>
</li>
</ul>
</div>
If you change only the width to 100% it will stretch the image inside of it. Try adding height:auto; to the inline CSS in order for the image to scale correctly.
If that doesn't work, try replacing your background-image property with:
background: url(images/slide_1.jpg) no-repeat center center;
background-size: cover;

How to make <li> scrolling like parallax?

What is the best way to make 'li' tags also scroll like parallax?
<div class="wrapper bg-4">
<div class="container">
<div class="row">
<div class="col-sm-7 invest">
<h3>Invest in Azerbaijan</h3>
<ul>
<li>Total Area: 86,600 km2</li>
<li>Water (%): 1.6</li>
<li>GDP (PPP): $168.4 billion</li>
<li>Time zone: AZT (UTC+04)</li>
<li>Population: 9,754,830</li>
</ul>
</div>
<div class="col-sm-5 flames">
<img src="img/flames.svg" alt="" class="img-responsive">
</div>
</div>
</div>
</div>
Try this
First put this:
.parallax {
background-image: *image URL*;
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
And then put your div down at HTML but make sure you added this code before and after the div
<div class="parallax"></div>
Should look like:
<div class="parallax"></div>
<div>
Whatever
</div>
<div class="parallax"></div>

Image slider with stacked cells

I am writing a web application which has a design that requires an scrolling div with stacked images (see image)
I have written the following HTML
<div class="row">
<div class="col-md-12">
<div class="item-image-craousel-left"></div>
<div class="item-image-carousel">
<div style="background-image: url('http://img2.timeinc.net/people/i/2014/stylewatch/blog/140915/blake-lively-600x450.jpg')" class="main-image"></div>
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o1_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o2_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o3_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o4_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ncdgtvSlUc1rjtt9yo2_1280.jpg')" class="sub-image"></div>
</div>
<div class="item-image-craousel-right"></div>
</div>
</div>
And CSS:
.item-image-carousel {
width: 100%;
display: inline-block;
overflow-x: auto;
}
.item-image-craousel-left {
height: 399px;
width: 20px;
background-color: #40d1b0;
position: absolute;
text-align: center;
vertical-align: middle;
padding-top: 166px;
display: none;
}
And currently I am getting this which is not overflowing and when I increase the width the images stack inline rather than in blocks of two as in the image above
Can someone tell me how I can achieve the layout as in the first picture. I am using Bootstrap 3 for its grid.
From my comment I meant something like this...(not knowing the correct 'col-md-xx' to use)
<div class="row">
<div class="col-md-12">
<div class="item-image-craousel-left"></div>
<div class="item-image-carousel row">
<div class="col-md-8 main-image" style="background-image: url('http://img2.timeinc.net/people/i/2014/stylewatch/blog/140915/blake-lively-600x450.jpg')"></div>
<div class="col-md-4">
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o1_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o2_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o3_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ma7gmzwfAq1r780z3o4_250.jpg')" class="sub-image"></div>
<div style="background-image: url('assets/images/tumblr_ncdgtvSlUc1rjtt9yo2_1280.jpg')" class="sub-image"></div>
</div>
</div>
<div class="item-image-craousel-right"></div>
</div>
</div>