I'm trying to make this grid responsive but it's not working as it should. How do I make this grid responsive ? I want to make them a one column grid when decreasing the browser. I tried using media queries or some frameworks but it didn't look good to me. I would appreciate the help. Here's the code:
css:
.container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
gap: 5px 5px;
grid-auto-flow: row;
grid-template-areas:
"farmhouseburger quinoablack"
"chocolatemilkshake standardburger"
"checkout perfect";
}
.farmhouseburger {
grid-area: farmhouseburger;
background: url(imgs/farmhouse.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.quinoablack {
grid-area: quinoablack;
background: url(imgs/quinoa.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.chocolatemilkshake {
grid-area: chocolatemilkshake;
background: url(imgs/milkshakeback.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.standardburger {
grid-area: standardburger;
background: url(imgs/standard.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.checkout {
grid-area: checkout;
background: url(imgs/checkout.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.perfect {
grid-area: perfect;
background: url(imgs/barbecue.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
HTML:
<div class="container">
<div class="farmhouseburger">
<div>
<h3 class="h3grid">NEW</h3>
<h1>FARMHOUSE<br>BURGER</h1>
<p>This burger’s name explains itself. Of course, you can<br>also top it with crisp lettuce, tomatoes, ketchup,<br>barbecue sauce and anything else.</p>
<h1>$2.49</h1>
<button class="buttongrid">ORDER NOW</button>
</div>
</div>
<div class="quinoablack">
<div>
<h3 class="h3grid">NEW</h3>
<h1>QUINOA & BLACK<br>BEAN BURGER</h1>
<p>We can’t think of a better way to celebrate summer than<br>with these omg-worthy hamburgers. Plus, try our over-<br>the-top creative cheeseburgers.</p>
<h1>$3.99</h1>
<button class="buttongrid">ORDER NOW</button>
</div>
</div>
<div class="chocolatemilkshake">
<div>
<h3 class="h3grid">NEW</h3>
<h1>CHOCOLATE<br>MILKSHAKE</h1>
<p>Milkshakes always taste good if you are a chocolate lover.<br>You can throw one together with a cream or experiment<br>with all kinds of extra flavors.</p>
<h1>$2.49</h1>
<button class="buttongrid">ORDER NOW</button>
</div>
</div>
<div class="standardburger">
<div>
<h3 class="h3grid">NEW</h3>
<h1>STANDARD<br>BURGER<br>MEAL</h1>
<p>These incredible burger meal offer a unique twist to the<br>classic hamburger, incorporating ingredients like<br>pimento cheese and sesame.</p>
<h1>$4.99</h1>
<button class="buttongrid">ORDER NOW</button>
</div>
</div>
<div class="checkout">
<div>
<h3 class="h3grid">NEW</h3>
<h1>CHECKOUT OUR<br>CATERING MENU</h1>
<p>Throwing the party is never been easier. Order now and<br>let us spice up your party. Burger meals, french fries and<br>cheeseburgers will cheer up your friends.</p>
<h1>$13.99</h1>
<button class="buttongrid">ORDER NOW</button>
</div>
</div>
<div class="perfect">
<div>
<h3 class="h3grid">NEW</h3>
<h1>HOW TO MAKE A<br>PERFECT BURGER</h1>
<p>We will tell you a little secret. Mixing best quality steak<br>and pork and serves them on homemade herb-butter<br>rolls is the best version we know.</p>
<h1>$5.99</h1>
<button class="buttongrid">ORDER NOW</button>
</div>
</div>
</div>
I just use this line of code instance of grid area
/grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));/
I test the code on screen with small size like 390x844 and it work well
css code
.container {
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}
.farmhouseburger {
background: url(imgs/farmhouse.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.quinoablack {
background: url(imgs/quinoa.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.chocolatemilkshake {
background: url(imgs/milkshakeback.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.standardburger {
background: url(imgs/standard.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.checkout {
background: url(imgs/checkout.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
.perfect {
background: url(imgs/barbecue.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
Related
I'm trying to center and cover an image up the whole screen which is coming from the Unsplash Source API.
I think because the image actually gets fetched after the CSS is already applied it doesn't work just like that:
(If the demo might appear covered up run it in full-screen)
html, body {
margin: 0px;
width: 100%;
height: 100%;
}
.centered-image {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width: 100%;
height: 100%;
background: url(https://source.unsplash.com/collection/1228371) no-repeat center center fixed;
}
<div class="centered-image"></div>
Do you guys know a work-around?
.centered-image {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: center;
width: 100%;
background-repeat: no-repeat;
height: 100%;
background-image: url(https://source.unsplash.com/collection/1228371);
}
Made some CSS Changes. Give this a try.
I would like to build a website for an exhibition but i don't really know how to make multiple photos have the same dimension without losing the quality.
For example look at this guy's website: https://www.peterdraws.com/shop/. I want my photos to look like here.
Here is my html:
<div class="work">
<a href="#"><div class="boxx"><div class="box" style="background:
url('img.jpg') no-repeat center center ;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;">
</div></div></a>
<a href="#"><div class="boxx"><div class="box" style="background:
url('img1.jpg') no-repeat center center ;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;">
</div></div></a>
</div>
And here is the css:
.work {
width: 75%;
margin: 0 auto;
text-align: center;
padding: 40px 0 70px 0;
}
.work .boxx {
width: 350px;
height: 400px;
display: table-cell;
vertical-align: middle;
}
.work .boxx .box {
margin: 0 auto;
width: 300px;
height: 300px;
}
If you want to make images of different dimension look like they are the same dimension, try using cover for background-size instead of contain:
<div class="work">
<a href="#">
<div class="boxx">
<div class="box" style="background: url('img.jpg') no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;"></div>
</div>
</a>
<a href="#">
<div class="boxx">
<div class="box" style="background: url('img1.jpg') no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;"></div>
</div>
</a>
</div>
This of course means that parts of the images have to be cut off (just like on the example website you provided). To control which parts are visible, look into what values the background-position CSS property accepts.
For more information on background-size and background-position:
https://developer.mozilla.org/en-US/docs/Web/CSS/background-size
https://developer.mozilla.org/en-US/docs/Web/CSS/background-position
I'm trying to cover up a html body background image by another image. I used z-index but can't get it working. Am I missing something or just can't understand what I'm doing.
See sample code below:
body, html {
margin: 0;
/* The image used */
background-image: url('http://lorempixel.com/output/nature-q-c-1176-907-10.jpg');
/* Full height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
#main-content {
background-image: url('http://lorempixel.com/output/food-q-c-640-633-1.jpg');
z-index: 10;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
position: relative;
}
.content {
/*height: 700px;*/
height: 100vh;
background:rgba(255,255,255,0.5);
/*margin-top: 20%;*/
}
<div id="main-content">
<div class="content">something in here..</div>
<div class="content">something in here..</div>
<div class="content">something in here..</div>
</div>
Additionaly, inside the main-content are divs with 100vh and
background opacity
Main content images should be on top of everything including the content div with background opacity.
Use 100% width and height on #main-content, like:
#main-content {
width: 100%;
height: 100%;
}
Have a look at the snippet below:
body, html {
margin: 0;
/* The image used */
background-image: url('http://lorempixel.com/output/nature-q-c-1176-907-10.jpg');
/* Full height */
height: 100%;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
#main-content {
background-image: url('http://placehold.it/500x500');
z-index: 10;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
position: relative;
width: 100%;
height: 100%;
}
<div id="main-content"></div>
Hope this helps!
It will work if you define a height for the div with CSS. Or insert content so it will expand vertically.
A background image makes sense for an element that contains more content, otherwise you can insert the image with <img>
You mean something as below, if so then set #main-content height:auto and it works fine, if you set height:100% then it takes that as 100vh, which on scroll hides image placed at top, so try as below.
So now #main-content height:auto calculates and takes height assigned to child elements present inside it and the background image which is assigned to this div #main-content can be seen only till height of 100vh, after that the default image that is assigned to body get visible.
body, html {
margin: 0;
background-image: url('http://lorempixel.com/output/nature-q-c-1176-907-10.jpg');
height: 100%;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
#main-content {
background-image: url('http://placehold.it/500x500');
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
width:100%;
height:auto;
}
.content {
height: 100vh;
background:rgba(220,60,60,0.6);
color:#fff;
}
<div id="main-content">
<div id="main-content">
<div class="content">something in here..</div>
<div class="content">something in here..</div>
<div class="content">something in here..</div>
</div>
</div>
I'm trying to make a background image for mobile devices like:
body {
background: url("/resources/img/background2.jpg") no-repeat fixed;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100% 100%;
}
In Chrome developers' tools it looks nice, but on a real device (with a smaller screen size) it does not. Why is this, and how I can solve this problem?
Snapshots:
You want a responsive background image which can get scaled down on smartphones. Use this:
background-image:url('/resources/img/background2.jpg');
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
How about?
background-image: url("/resources/img/background2.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
Try use <meta name="viewport" content="width=device-width, initial-scale=1">
This is the best solution
body {
background: url(../images/background.jpg);
background-repeat: no-repeat;
background-position: 0px 0px;
background-attachment: fixed;
background-color: #fff;
-webkit-background-size: calc(100vw) calc(100vh);
-moz-background-size: calc(100vw) calc(100vh);
-o-background-size: calc(100vw) calc(100vh);
background-size: calc(100vw) calc(100vh);
}
I have a space at the page's top and I don't know how to remove it.
I have created background image (1,2) in my page example.
But I'm not able to find what the source of this white line. I have modified a lot of settings in css with no result.
Demo in Bootply
Here's my code:
<section id="first">
<h1>TEST!</h1> <br>
</section>
<section id="first1">
<h1>TEST2!</h1> <br>
</section>
#first {
background: url(http://placehold.it/1350x890/37FDFC/&text=photo1) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 800px;
/*height: 800px;*/
/*padding-bottom: 200px;*/
}
#first1 {
background: url(http://placehold.it/1350x890/FFFF00/&text=photo2) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 800px;
/*height: 800px;*/
/*padding-bottom: 200px;*/
}
Just to highlight what Christina said, this issue is being caused by the top-margin on your h1 element:
Here's a cleaned up version that replicates the problem
.background-photo {
background: no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 800px;
}
#first {
background-image: url(http://placehold.it/1350x890/37FDFC/&text=photo1);
}
#second {
background-image: url(http://placehold.it/1350x890/FFFF00/&text=photo2);
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet"/>
<section id="first" class="background-photo">
<h1>TEST!</h1>
</section>
<section id="second" class="background-photo">
<h1>TEST2!</h1>
</section>
You can fix it by doing either of the following:
1) Adding sufficient padding to the containing section:
.background-photo {
padding-top: 20px;
}
.background-photo {
background: no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 800px;
}
#first {
background-image: url(http://placehold.it/1350x890/37FDFC/&text=photo1);
}
#second {
background-image: url(http://placehold.it/1350x890/FFFF00/&text=photo2);
}
.background-photo {
padding-top: 20px;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet"/>
<section id="first" class="background-photo">
<h1>TEST!</h1>
</section>
<section id="second" class="background-photo">
<h1>TEST2!</h1>
</section>
2) Removing the Margin on the header:
.background-photo h1 {
margin-top: 0px;
}
.background-photo {
background: no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 800px;
}
#first {
background-image: url(http://placehold.it/1350x890/37FDFC/&text=photo1);
}
#second {
background-image: url(http://placehold.it/1350x890/FFFF00/&text=photo2);
}
.background-photo h1 {
margin-top: 0px;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" rel="stylesheet"/>
<section id="first" class="background-photo">
<h1>TEST!</h1>
</section>
<section id="second" class="background-photo">
<h1>TEST2!</h1>
</section>