Multiple photos with the same dimensions - html

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

Related

How do I make this grid responsive?

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;
}

Background not covering full page

My background image is not covering the full page when I type in my nav bar. I have set the background width and height to 100%, which I thought would solve the problem.
https://jsfiddle.net/oefu0rmk/
CSS
#intro {
background: #151515 url(../img/b1.jpg) no-repeat center bottom;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: 650px;
background-attachment: fixed;
width: 100%;
height: 100%;
min-height: 720px;
display: table;
position: relative;
text-align: center;
}
.intro-overlay{
position:absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: #111111;
opacity: .85
}
HTML
<nav>
about me
about my parents
My hobbies
</nav>
<body>
<section id="intro">
<div class="intro-overlay"></div>
<div class="intro-content">
<h5>Oh, hi there! My name is Tatsu</h5>
<h1> (Tah-T-Su)</h1>
<a class="button stroke smoothscroll" href="#about" title="about me button">find out more about me</a>
</div>
Your code doesn't match your fiddle. The problem is you are not adding the background to the whole page, rather to the #intro element. There is copy outside of this <section>.
Add this to your fiddle and it will extend to the full page:
body {
background: #151515 url(../img/b1.jpg) no-repeat center bottom;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: 650px;
background-attachment: fixed;
}
Try this
html {
background: url(xyz.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body
{
background:none;
}
This will definitely work.
This will work perfect in you global styling sheet.
html, body {
overflow: auto;
}

Cover a body background by another image

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>

HTML background image with 100% height preserving aspect ratio

I am trying to get an image to fill a page using a bootstrap css template and additional custom css.
html:
<head>
<link rel="stylesheet" href="bootstrap.min.css" />
<link rel="stylesheet" href="cover.css" />
</head>
<body>
<div class="my_banner">
<div class="col-lg-8">
<h3>Title</h3>
</div>
<div class="col-lg-4 ">
<a class="btn btn-success">Ok</a>
</div>
</div>
</body>
cover.css:
.my_banner {
padding-top: 50px;
text-align: left;
color: #f8f8f8;
background: url(image.png);
max-width: 100%;
height: auto;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
}
However the image only fills about 1/3 of height of page when browser width is small and about 1/10th of the page when browser width is made large. How can I get the entire height always filled?
Just need to set height to 100vh, that means you will fill all the height value of your browser
.my_banner{
height: 100vh;
background: url(image.png) center;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-repeat: no-repeat;
}
Working codepen example: http://codepen.io/anon/pen/rLNyvw
you can also use background-size property fir this like:
`
.my_banner {
padding-top: 50px;
text-align: left;
color: #f8f8f8;
background: url(image.png);
background-size: 100% 100%;
background-repeat: no-repeat;
}`

Space at the top of the page (Twitter Bootstrap 3)

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>