The desktop version looks good, but the mobile version is clipping the background. What I mean by this is that when I scroll it has the effect of two backgrounds.
I don't know if the problem is in the css or the html file.
body, html{
height: 1080px;
margin: 0;
padding: 0;
background: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<!-- Required meta tags -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://use.fontawesome.com/releases/v5.0.6/js/all.js">
</script>
<link href="https://fonts.googleapis.com/css family=Montserrat:300,600,700i" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
Because you set background-image for two element (html and body). A simple webpage layout like this:
<html>
<head>
</head>
<body>
</body>
</html>
You can change the height value for the body, but not the html! The height value of HTML is always automatic. Therefore, after scrolling down 1080px, the body background ends and the html background is displayed. To solve the problem, just add the background to the body and remove height value.
body{
margin: 0;
padding: 0;
background-image: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
add this media code
#media screen and (max-width:500px){
body, html {
background-size:100% 100%;
}
}
You don't need to set bckgound for html and body. Only set the background for body.
body{ /* Remove html from this lie */
height: 1080px;
margin: 0;
padding: 0;
background: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
Related
I've been trying to create a landing page for my website. I'm stuck in putting the background since it doesn't cover the whole page even if I set the width to 100%.
It looks like this, even if it's not zoomed out or in.
Notice the huge white part on the right side
So far, this is the only code that I have
CSS
*{
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
.container {
width: 100%;
height: 100vh;
background: linear-
gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)),url(../../assets/images/background.png);
background-position: center;
background-size: cover;
}
HTML
<HTML>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SEQR</title>
<link rel="stylesheet" href="dashboard.component.css">
</head>
<div class="container">
</div>
</html>
width: 100%;
height: 23vw;
background: url('srcimgs/topsvg.svg') no-repeat;
this may help you adjust the height
Try this solution that i have used for my Homepage
.heroImage{
background-image: url('./assets/wallpaper.jpg');
background-attachment: fixed;
background-size: cover;
}
use these CSS properties in your background img tag. I hope this helps.
So I tried everything that I know of and don't know why this isnt working please send help.
max-width/height didnt work there is always a small gap between html and border. And if I want to style the background with a linear gardient fo example there is always a small line wether it is right or at the bottom, I only can style it with th background-color. Here is the code:
html{
[![width: 100%;
height: 100%;
min-height: 100%;
min-width: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
overflow-x: hidden;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background: linear-gradient(to left, black, gray);][1]][1]
}
[1]: https://i.stack.imgur.com/N04VV.png
Try this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
body {
background: linear-gradient(to left,black, gray );
}
</style>
<body>
</body>
</html>
So I'm trying to create a 'parallax' effect. However, the only way I've seen is to use a div and set it to fixed and not repeat. The only problem is that the image has a 'border' around it, on top and the sides. I'm thinking this is because of the div, any clever solutions?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo parallax effect</title>
<style>
.parallax {
/* The image used */
background-image: url("macbook.jpeg");
/* Set a specific height */
min-height: 410px;
/* max-width: 100%;*/
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
padding: 0px 0px 0px 0px;
}
</style>
</head>
<body>
<div class="parallax"></div>
<div style="height:1000px;background-color: aliceblue;font-size:36px">
Scroll Up and Down this page to see the parallax scrolling effect.
This div is just here to enable scrolling.
Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>
</body>
</html>
Remove the margins from the body:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo parallax effect</title>
<style>
.parallax {
/* The image used */
background-image: url("http://placekitten.com/410");
/* Set a specific height */
min-height: 410px;
/* max-width: 100%;*/
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
padding: 0px 0px 0px 0px;
}
body {
margin: 0;
}
</style>
</head>
<body>
<div class="parallax"></div>
<div style="height:1000px;background-color: aliceblue;font-size:36px">
Scroll Up and Down this page to see the parallax scrolling effect. This div is just here to enable scrolling. Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>
</body>
</html>
Try removing the margins from the body tag in your CSS.
Here's a working example:
body {
margin: 0;
}
.parallax {
background-image: url("macbook.jpeg");
min-height: 410px;
background-attachment: fixed;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
}
just remove the margin of body hope it will work please check the following code snippet
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo parallax effect</title>
<style>
body {
margin: 0 !important;
}
.parallax {
/* The image used */
background-image: url("macbook.jpeg");
/* Set a specific height */
min-height: 410px;
/* max-width: 100%; */
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
padding: 0px;
}
</style>
</head>
<body>
<div class="parallax"></div>
<div style="height:1000px;background-color: aliceblue;font-size:36px">
Scroll Up and Down this page to see the parallax scrolling effect.
This div is just here to enable scrolling.
Tip: Try to remove the background-attachment property to remove the scrolling effect.
</div>
</body>
</html>
pardon me if my question is stupid, I'm quick new to all these technologies. my objective is to add image-background in it default size while it doesn't zoom since it is a big size picture, the problem is when I add some styles, the image doesn't show up and background getting blank.
by the way, IM using particle.js on top of this background image.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Infinite Space !</title>
<link rel="stylesheet" href="style.css">
</head>
<body >
<div id="particles-js"></div>
//particle-js configues
<script src="https://cdn.jsdelivr.net/npm/particles.js#2.0.0/particles.min.js">
</script>
<script>
particlesJS.load('particles-js', 'particles.json', function() {
console.log('callback - particles.js config loaded');
});
</script>
</div>
</body>
</html>
#particles-js{
background: url("https://d14xs1qewsqjcd.cloudfront.net/assets/bg-header-star.jpg")
width: 100%;
min-height: 800px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
/* background-attachment: fixed;
}
You didnt add a semicolon after the background property:
#particles-js{
background: url("https://d14xs1qewsqjcd.cloudfront.net/assets/bg-header-star.jpg") /* <---- Semicolon goes here*/
width: 100%;
min-height: 800px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
/* background-attachment: fixed; /* Also you didnt close this comment */
}
I want to make a page,which by scroll down ,the content div ,cover the back ground image.so I put a background image for body and create 2 divs, it works in big window size, but when I change the size of window, and make it smaller (to test the responsive), there is a white gap between image and content div.
Would you please help me to remove it?
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>first</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link href="css/first.css" rel="stylesheet">
<style>
body{
background: url("https://kalamarie123.files.wordpress.com/2012/03/img_7815-2.jpg") no-repeat top center fixed;
background-size:100%;
}
</style>
</head>
<body>
<div class="cover"></div>
<div class="content">Lorem Ipsum is simply dummy text of </div>
</body>
</html>
.cover{
height: 1232px;
width: 100%;
margin: 0;
padding: 0;
color: white;
text-align: center;
}
.content{
width: 100%;
height: 100%;
background: gray;
margin: 0;
padding: 0;
}
You need to make the body and the html go to the bottom of the page:
body, html {
min-height: 100%;
}
and then set the background to background-size: cover;: https://css-tricks.com/perfect-full-page-background-image/
You could do something like this:
<div id="yourdiv"></div>
#yourdiv {
width: 100%; height: 100%; top: 0; left: 0;
background: url(images/bg.jpg) no-repeat center top; position: fixed; z-index: -1;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Hope it helps!
Sounds like it's probably due to your background image not filling the full space available.
Try adding this to the body (the element with the BG image);
background-size:cover;
Note that this will not work well on old browsers