Background resizes with page - html

(Please be kind I'm fairly new to all this).
I've tried using cover, absolute, auto and whatever else to try and get the background to resize along with the page. Whenever I make the resize the page smaller or bigger, I'm left with a white box at the bottom:
https://imgur.com/a/KauGhfD
The only way to get the white to go away is if I make the page full size again. Here's my CSS.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image:url("https://66.media.tumblr.com/6c5a2aeca064c07feb499ace6b3cd205/87a13546c57cc3af-65/s1280x1920/7f41aeae69f0fac081602c946f5aa9e5c5077c94.jpg");
background-repeat: no-repeat;
background-size: cover;
background-positon: absolute;
overflow: hidden;
width: 100%
top: 0;
left: 0;
}
</style>
<title>home</title>
<link rel="stylesheet" type="text/css" href="css/">
<link rel="icon" href="https://i.pinimg.com/originals/f9/8f/c3/f98fc32fb656fe36088b94f789019adb.png">
</head>
<body>
</body>
</html>

try fix this issues :
add ; after width: 100%
this property value absolute not correct background-positon: absolute;
check this link to know the correct value
https://www.w3schools.com/cssref/pr_background-position.asp
you have also a typo on positon should be background-position:

you can use this code for cover for background of page but you must keep your ratio aspect for picture
your code have two error
1- background-position:absolute is wrong
2-width:100% it is not correct because body have this properties
then you must change your code like this
<!DOCTYPE html>
<html>
<head>
<style>
html,body{
height:100%;
}
body {
background-image:url("https://66.media.tumblr.com/6c5a2aeca064c07feb499ace6b3cd205/87a13546c57cc3af-65/s1280x1920/7f41aeae69f0fac081602c946f5aa9e5c5077c94.jpg");
background-repeat: no-repeat;
background-size: 100% 100%;
background-attachment: fixed;
}
</style>
<title>home</title>
<link rel="stylesheet" type="text/css" href="css/">
<link rel="icon" href="https://i.pinimg.com/originals/f9/8f/c3/f98fc32fb656fe36088b94f789019adb.png">
</head>
<body>
</body>
</html>

Related

Background image is cut instead of zooming out

My website background image responsiveness works during md size -> when it turns in sm and xs it is cut - it means when I want to see the cat during xs I can see only a piece of cat. How to fix it to see all my background photo during smaller sizes?
HTML:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?familyans+SC:wght#300&display=swap" rel="stylesheet">
<div th:replace="fragments/front_head"></div>
</head>
<body>
<div class="bg-image" style="background-image: url('img/cattery/main-photo-cut.jpg'); background-size: cover; background-position: relative; height: 100vh;">
</div>
<nav th:replace="${#service.getLoggedCustomer()} ? 'fragments/cattery_logged_in_navbar' : 'fragments/cattery_navbar'"></nav>
<footer th:replace="fragments/cattery_footer"></footer>
</body>
</html>
CSS:
body {
padding-top: 120px;}
First, remove the background-size and background-position css from the style attribute of the .bg-image element. Then try this CSS.
.bg-image{
background-size: contain;
background-position: center;
}
#media screen and (min-width: 450px) {
.bg-image{
background-size: cover;
}
}
The reason it's cropping is the "cover" background size is displaying the entire image centered. Of course that leads to cropping since the smaller sizes are too small to show the whole image in its original size. Contain makes sure you can see all of the image.

How to let background image cover full viewport screen?

I am new to HTML/CSS and I am having trouble making the background image of my div cover the full screen. I have used background-size:cover but it still has large margins on the left and right of the screen.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta viewport="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
</div>
</body>
<html>
CSS
.container{
height:100vh;
width:100vw;
background-image:url("city.jpeg");
background-repeat:no-repeat;
background-size:cover;
background-position:center;
opacity: 0.8;
}
Please try using img: {width: 100% height:100%}. Your best approach would be to inspect the element and check if the div that contains the image is restricitng its size or not. You can use firefox to inspect (I just prefer it over chrome as it shows the size of any element better visually).
By default, the body has a margin around it. Try this:
body {
margin: 0;
}
Use following code:
.background-image {
width: 100vw;
height: 100vh;
}

Background Image full-screen fit without any cut

I'm trying to set a full-screen background image (1366x854) with css. I've tried in many ways peeking online but I can't set my image as it is. It is possible to have it full-screen without get cut parts? The img below is just a prototype and code is really basic. Thanks in advance.
<!DOCTYPE html>
<html>
<head>
<title> LIVE </title>
<link href="css/Live.css" rel="stylesheet">
</head>
<body>
</body>
</html>
body {
background: url(Live.png) no-repeat center center fixed;
background-size: contain 100% 100%;
}

How to put PNG image with transparent background using HTML?

I have these two PNG images (Image 1: eyemasktrans , Image 2:dialogue_ughhh) which I already edited in Photoshop to make them transparent. But the problem is when I try to view on Chrome, the supposed transparent images appeared to have white backgrounds. Is they any way to fix this using just HTML? Thanks in advance! Below is my current code:
Other image I use: girl_sleeping
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.parallax {
/* The image used */
background-image: url("girl_sleeping.jpg");
/* Set a specific height */
min-height: 200px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<center> <img src="eyemasktrans.png" /> </center>
<center> <img src="dialogue_ughhh.png" /> </center>
<div class="parallax"></div>
</body>
</html>
Your eyemasktrans.png and your dialogue_ughhh.png images are fine. They have a proper alpha channel in the PNG.
I think the issue you're having is that the .parallax div is not sized corectly, and also has some weird background configurations with fixed and center, which cause it to appear like something is covering it while you scroll around the page.
I don't know what the desired effect is here, but if you size things correctly and set z-index as appropriate, you won't have a problem.
Additionally, I would suggest considering SVG for this task, since all your art is vector anyway. You'll have a much faster load time.
(Issue is reproduced here: http://jsfiddle.net/vr1qms9h/1/)
You can use the opacity attribute.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.parallax {
/* The image used */
background-image: url("http://thepotatoplace.ga/images/background.png");
/* Set a specific height */
min-height: 200px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
opacity: 0.65;
}
</style>
</head>
<body>
<center> <img src="eyemasktrans.png" /> </center>
<center> <img src="dialogue_ughhh.png" /> </center>
<div class="parallax"></div>
</body>
</html>

Bootstrap Background Image

Okay so basically it will not display my background image. I have looked at all the other posts and none of them work. Here is the code.
Here is the Html. Note that the app.css and app.js are just bootstrap files renamed.
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width-device-width, initial-scale=1" />
<!-- Above is Important -->
<meta name="description" content="HTML, CSS, BOOTSTRAP" />
<meta name="author" content="James Mehltretter" />
<title>Download Free HTML Templates</title>
<link rel="stylsheet" href="app.css" type="text/css" />
<script src="app.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
Here is the part of the CSS that I edited.
body {
margin: 0;
background-image: url(background.png);
}
The JavaScript file is just generic bootstrap. Here is the link to the file I am actually using though.
The Bootstrap JS
Thank you.
Your Body has no height and there's nothing in it to put a background on.
Make sure your body has some height to it.
body {
margin: 0;
background-image: url(https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png);
background-size: 1440px 800px;
height: 300px;
}
Check that the image background.jpg exists within the parent directory of the directory that contains the css you've provided.
Are you getting a 404 error on the file path in your javascript console? Also ditch the quotes. Don't think that's right. I think w3Schools is wrong. Here is Mozilla docs showing no quotes on URL:
https://developer.mozilla.org/en-US/docs/Web/CSS/background-image
Check again with this code:
body {
margin: 0;
background-image: url(../background.jpg);
background-size: 1440px 800px;
}
If you're trying to make the image cover the entire screen all the time use HTML or HTML and BODY together.
See working Snippet at Full page.
html,
body {
height: 100%;
width: 100%;
background-image: url(https://upload.wikimedia.org/wikipedia/commons/d/d4/Tokyo_by_night_2011.jpg);
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
As long as you have given the height, the image will show.
In this example, height: 100vh, which means it covers the whole screen.
body{
background-image: url('https://image.freepik.com/fotos-kostenlos/gruene-wiese-hintergrund_1252-1098.jpg');
height: 100vh;
}
The best practice however is to set it to cover and no-repeat, so that the background image is shown only once despite the screen size.
body{
background-image: url('https://image.freepik.com/fotos-kostenlos/gruene-wiese-hintergrund_1252-1098.jpg');
background-size: cover;
background-repeat: no-repeat;
height: 100vh;
}