Background image in home page is not working? - html

The background image is not working while I set the option to 100%.
I'm using angular and bootstrap 4.
<!--html code-->
<div class="bg">
<div style="text-align:center">
<h1>
Welcome
</h1>
</div>
<router-outlet></router-outlet>
this is the .scss code
body, html {
height: 100%;
}
.bg {
/* The image used */
background-image: url("~/assets/jonatan-pie-226805-unsplash.jpg");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

I copied your code and added a picture and it works below.
Are you using anything that would implicitly keep the background small? Maybe a bootstrap?
body, html {
height: 100%;
}
.bg {
/* The image used */
background-image: url("https://www.placecage.com/g/1000/500");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<!--html code-->
<div class="bg">
<div style="text-align:center">
<h1>
Welcome
</h1>
</div>
<router-outlet></router-outlet>

Related

div Background Image Cutted

I defined with background image as following.Html:
<body onload="myFunction()">
<h4>Entities Presenter</h4>
<div class="bg">
<canvas id="my-canvas" class="canvas"></canvas>
</div>
</body>
CSS:
body,
html {
height: 100%;
margin: 0;
}
.bg {
/* The image used */
background-image: url("wp2753284.jpg");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
But the background image after definitions above displayed cutted ( from top and bottom), Is there something wrong in the definition ? Thanks in advance
instead of background-size: cover;
try background-size: contain;

How Can I cut img background and disable default responsive behavior?

How can I disable responsive background img behavior ?
My background img in larger screen is like this :
And I want this behavior when I resize screen (small screens). (I want that the img will be cut automatically) : does a css property exist for this ?
My code is :
.bg {
background-image: url(assets/images/bg.png,
background-repeat: no-repeat;
}
<div class="container-full bg">
<div class="container">
<div>My content....</div>
</div>
I am in bootstrap project , and my background img is responsive, how can I disable this please ?
here is a quick cutout. You can position the image left, center or right. The image will be trimmed automatically.
You can define the height for yourself.
body {
margin: 0;
}
.bg {
background-image: url("https://i.stack.imgur.com/jtaEI.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
height: 400px;
}
<div class="bg">
<div>My content....</div>
</div>
edit
Please be aware that you need semicolons in .css after each declaration
your code:
.bg {
background-image: url(assets/images/bg.png,
background-repeat: no-repeat;
}
need to look like this:
.bg {
background-image: url("assets/images/bg.png");
background-repeat: no-repeat;
}

Make footer under cover sized image

I am making a website and I stumbled upon a little problem.
I have the image set to be to height: 100% and width; and background-size: cover;
Is there any way I can make the footer appear so that you scroll UNDER the image?
.bg {
/* The image used */
background-image: url("./Resources/home_bg.jpg");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
HTML code looks like:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="bg"></div>
</body>
</html>
It sounds like you only need to add a z-index to your divs.
The footer would have the smaller number z-index, while .bg is the larger one.
Also, I added a container and gave the footer a background color to just show the effect that I think you're going for.
.bg {
/* The image used */
background-image: url("http://placehold.it/400x400");
/* Full height */
height: 100vh;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
z-index: 10;
}
footer {
background: #ff0000;
position: fixed;
bottom: 0;
width: 100%;
z-index: 8;
}
.container {
height: 105vh;
}
<div class="container">
<div class="bg">BG</div>
<footer>footer</footer>
</div>

Bootstrap 3 - Jumbotron background image

I am having trouble setting a background image for bootstrap jumbotrons. My main.css comes after the bootstrap css and I am selecting the jumbotron using a class called "banner" which is in the same div as the jumbotron, but it still doesn't work. Here is my code...
HTML:
<!-- Banner -->
<div class="jumbotron banner">
<div class="container">
<hgroup>
<h1>
Bits king
</h1>
<h2>
Web Design & Development
</h2>
</hgroup>
</div>
</div>
CSS:
.banner {
height: 400px;
width: 100%;
max-height: 50%;
max-width: 100%;
min-height: 20%;
min-width: 30%;
background-image: url("../assets/images/banner.jpeg");
background-size: cover;
}
You can add a background-image property to the .jumbotron class in your custom css file (Make sure you reference your custom css file after Bootstrap. Here's an example:
.jumbotron {
background-image: url("/img/your-image.jpg");
background-color: #17234E;
margin-bottom: 0;`enter code here`
min-height: 50%;
background-repeat: no-repeat;
background-position: center;
-webkit-background-size: cover;
background-size: cover;
}
add "jumbotron-custom" to class attribute and apply this after "bootstrap" css :
.jumdotron-custom
{
background: url('/*background url*/') no-repeat !important;
}
..or just add !important to your 'background-image' of css.
Good Morning. Try this:
background-image: url("../assets/images/banner.jpg");
Let me know if it works or not?

Making changing background images as you scroll compatible with IE7/8

I have a webpage that changes the background image as you scroll to new sections of the page. It can be viewed here. I am having trouble getting the changing background images to show up on IE7/8. I tried using css3pie, but it doesn't seem to be working. Here is a sample of my html right now:
<!-- background image section w/ text on top -->
<section id="anvil" class="bg">
<div class="center text">
<p class="imageCopy">Stunningly beautiful colors...</p>
</div>
</section>
<section class="divider">
<!-- this is the divider section -->
</section>
<!-- new background image section -->
<section id="office" class="bg">
<div class="center text">
<p class="imageCopy">at a price you can afford.</p>
</div>
</section>
and the css:
#anvil {
background-image: url(/images/anvil.jpg);
-pie-background: url(/images/anvil.jpg) no-repeat;
behavior: url(/PIE-1.0.0/PIE.htc);
}
#office {
background-image: url(/images/office.jpg);
-pie-background: url(/images/office.jpg) no-repeat;
behavior: url(/PIE-1.0.0/PIE.htc);
}
.bg {
background-repeat: no-repeat;
background-attachment: fixed;
-webkit-background-size: cover;
background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-position: 0 -80px; /* IE 8 fix */
background-position: 0 -5rem;
height: 47rem;
height: 750px; /* IE 8 fix */
}
.divider {
background-color: #000000;
height: 29rem;
height: 464px; /* IE 8 fix */
}
It's difficult for me to determine what exactly is causing the issues with IE as well, so I might be on the wrong track with the background properties (e.g., sections are not supported by IE 7/8, but I think I fixed that). Any advice would be greatly appreciated! Thanks!