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

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!

Related

Background image in home page is not working?

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>

How would I make this image background come out for only half of the section?

I'm working on a website and in a particular section, I want a blue background image to appear for half the section but no matter what I do in terms of CSS, absolutely nothing works.
I've made so many attempts that it's too many to list. What am I doing wrong and how can I fix it?
Here's my html code:
<div class="row secOne secT">
<div class="myImage col-md-6"></div>
</div>
Here's my css code:
.row.secOne.secT {
padding-top: 20px;
}
.myImage {
background-image: url("https://images.pexels.com/photos/281260/pexels-photo-281260.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
I've tried creating a simple html file using your code and by applying
background-size: 50% 100%;
background-repeat: no-repeat;
on the item having the desired image background I got something that seems your desired result.
Full code sample
<html>
<head>
<style>
.col-md-6 { /* Added this definition in order to get a visible div */
width: 800px;
height: 100px;
border: 1px solid black;
}
.row.secOne.secT {
padding-top: 20px;
}
.myImage {
background-image: url("https://images.pexels.com/photos/281260/pexels-photo-281260.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500");
-webkit-background-size: 50% 100%;
-moz-background-size: 50% 100%;
-o-background-size: 50% 100%;;
background-size: 50% 100%; /* Force background size to only fill half the div */
background-repeat: no-repeat; /* Avoid background repetitions */
}
</style>
</head>
<body>
<div class="row secOne secT">
<div class="myImage col-md-6">
AAAAA
</div>
</div>
</body>
I think you can try this : https://i.stack.imgur.com/fdk00.png
Try this too - https://i.stack.imgur.com/meURR.png
I hope it helps you - sorry if it does not.
You can make appear the blue background of your URL, setting the height CSS property
.row.secOne.secT {
padding-top: 20px;
}
.myImage {
background-image: url("https://images.pexels.com/photos/281260/pexels-photo-281260.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 22em;
}
<div class="row secOne secT">
<div class="myImage col-md-6"></div>
</div>
Hope it helps!

fixed background-image for specific section on mobile chrome browser isn't working

I know, this has been discussed over and over again. but it still seems to be a specific understanding issue on my side. after implementing several bug fixes from here and elsewhere my site is still not working as wished.
I got a fixed background-image in the header section of my page. this is working perfectly fine on normal chrome browser. however i cannot get it running on mobile chrome browser
i've got following lines of html:
<body id="page-top">
<!-- Header -->
<header class="masthead bg-head text-white text-center">
<div class="container">
<h1 class="text-uppercase mb-0">My Name</h1>
<img id="header-star" class="img-fluid" src="img/star-light.png" alt="">
</div>
</header>
aligned with the following lines of css:
body {
font-family: 'Lato';
max-width: 1280px;
margin-left: auto;
margin-right: auto;
background-color: #fff;
}
header{
background-color: #4a4a4a;
background-image: url("../img/background-bern-4.jpg");
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center top;
padding-top: 6rem;
height:500px;
}
for example i wrote a media query with height of 100% with browser specific commands and so on:
#media (max-width: 576px){
header{
height:100%;
background: url(bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
}
and then i tried to put y-overflow: scroll; to body and hidden to header enter link description here
Furthermore I tried to put the image into a div like this enter link description here
html:
<!-- Header -->
<header class="masthead bg-head text-white text-center">
<div class="container header">
<h1 class="text-uppercase mb-0">My Name</h1>
<img id="header-star" class="img-fluid" src="img/star-light.png" alt="">
</div>
</header>
css:
.header{
position: fixed;
z-index: -1;
background-color: #4a4a4a;
background-image: url("../img/background-bern-4.jpg");
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center top;
padding-top: 6rem;
height:500px;
}
whit this technique the picture is gone completely after all
somewhere I must missing something, don't I?
You just need to fix path of background image
#media (max-width: 576px){
header{
background-image: url("../img/background-bern-4.jpg");
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center top;
height:auto;
max-height: 100%;
}
}
I hope this will help!

Bootstrap: Background is covering div container, not just the screen

On my website, I want that the background does not move at all, while the content scrolls in the foreground normally over the background. This effect is working perfectly on my macbook. I have tested it with Safari, Chrome and Firefox. Now when I open the website on my iPhone, the background images are covering the whole div container, not just the screen, which means that the image is way too big and not sharp anymore.
HTML:
<div id="tf-home" class="text-center">
<div class="overlay">
<div class="content">
<h1>EURE <strong><span class="color">FLUCHT</span></strong> beginnt an diesem Ort</h1>
</div>
</div>
</div>
CSS:
#tf-home {
background: url(../img/header.jpg);
background-size: cover;
background-position: center;
background-attachment: fixed;
background-repeat: no-repeat;
min-height: 100%
color: #cfcfcf;
}
I hope that someone can help me.
Thank you in advance :)
here you have a jsfiddle
#tf-home {
background: url(https://www.google.com/work/images/logo/google-for-work-social-icon.png);
background-size: cover;
background-position: center;
background-attachment: fixed;
background-repeat: no-repeat;
min-height: 100vh;
color: #cfcfcf;
}

how to set the background image fit to browser using html

I have made a simple login page and set an image as background but it is not fitting to browser screen.I am using html for this purpose what should I do fit the image to browser screen.Kindly please describe in detail.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01Transitional
//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Page</title>
</head>
<body>
<h1>Login Page</h1>
<center>
<h2>SignUp Details</h2>
<body background="Indian_wallpapers_205.jpg">
<form action="LoginCheck.jsp"method="post">
</br>Username:<input type="text" name="username">
</br>Password:<input type="password" name="password">
</br>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
You can achieved what you want by creating a .css file and link to your <head> tag just after the </title> (closing title tag).
Hi-Resolution image will be good to use, around 2112x1584 pixels but consider the file size because it will matter for the page load time.
On the opening of your <body> tag, just delete the background property as it will be declared through the .css file.
When your image is ready, put this code to your .css file
body {
background-image: url(imagePAth/Indian_wallpapers_205.jpg); /*You will specify your image path here.*/
-moz-background-size: cover;
-webkit-background-size: cover;
background-size: cover;
background-position: top center !important;
background-repeat: no-repeat !important;
background-attachment: fixed;
}
When your .css file is done, you can link it to the <head> tag. It will look something like this: <link rel="stylesheet" type="text/css" href="yourCSSpath/yourCSSname.css" />
That's how i make a background image to fit the browser screen.
use background size: cover property . it will be full screen .
body{
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
here is fiddle link
Found an easier way to set it. Here's the html and css:
<style>
#body {
*background: url(../Images/abcd.jpg) no-repeat center center fixed; /* For IE 6 and 7 */
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
<body id="body">
<nav class="navbar navbar-default" id="navColour">
<div class="container-fluid">
<div class="navbar-header">
<a id="clr" class="navbar-brand" href="#">Summer Haze Festival</a>
</div>
<div>
<ul class="nav navbar-nav" >
<li id="clr" class="active">Home</li>
<li id="clr">Page 1</li>
<li id="clr">Page 2</li>
<li id="clr">Page 3</li>
</ul>
</div>
</div>
</nav>
</body>
url(../Images/abcd.jpg) being the image stored in your solution in a folder called Images. Hope it helps. Note: I used the id "body" because the navigation bar was somehow overriding my background image.
add this css in your stylesheet
body
{
background:url(Desert.jpg) no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
margin: 0;
padding: 0;
}
FIDDLE
HTML
<img src="images/bg.jpg" id="bg" alt="">
CSS
#bg {
position: fixed;
top: 0;
left: 0;
/* Preserve aspet ratio */
min-width: 100%;
min-height: 100%;
}
Some answers already pointed out background-size: cover is useful in the case, but none points out the browser support details. Here it is:
Add this CSS into your stylesheet:
body {
background: url(background.jpg) no-repeat center center fixed;
background-size: cover; /* for IE9+, Safari 4.1+, Chrome 3.0+, Firefox 3.6+ */
-webkit-background-size: cover; /* for Safari 3.0 - 4.0 , Chrome 1.0 - 3.0 */
-moz-background-size: cover; /* optional for Firefox 3.6 */
-o-background-size: cover; /* for Opera 9.5 */
margin: 0; /* to remove the default white margin of body */
padding: 0; /* to remove the default white margin of body */
}
-moz-background-size: cover; is optional for Firefox, as Firefox starts supporting the value cover since version 3.6. If you need to support Konqueror 3.5.4+ as well, add -khtml-background-size: cover;.
As you're using CSS3, it's suggested to change your DOCTYPE to HTML5. Also, HTML5 CSS Reset stylesheet is suggested to be added BEFORE your our stylesheet to provide a consistent look & feel for modern browsers.
Reference: background-size at MDN
If you ever need to support old browsers like IE 8 or below, you can still go for Javascript way (scroll down to jQuery section)
Last, if you predict your users will use mobile phones to browse your website, do not use the same background image for mobile web, as your desktop image is probably large in file size, which will be a burden to mobile network usage. Use media query to branch CSS.
Try This Code:
It may help you
<html>
<head>
<style>
body
{
background:url('images/top-left.jpg') no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<form action="LoginCheck.jsp"method="post">
</br>Username:<input type="text" name="username">
</br>Password:<input type="password" name="password">
</br>
<input type="submit" value="Submit">
</form>
</center>
</body>
</html>
I encounter same trouble as you, this is my solution.
body {
background-image: url(image/background.jpg);
background-size: 100% 100%;
}
body
{
position: fixed; /*fixes the image in background*/
top: 0; /*fixes the image at top*/
left: 0; /*fixes the image at left*/
min-width: 100%; /*fixes the image width to 100% of screen*/
min-height: 100%; /*fixes the image height to 100% of screen*/
}