How do I add a background image to the home page only? - css

I'm finding it difficult to insert my background image only on the home page. I have 6 pages but I only want the background image to be on the home page. Annoyingly the background image is on all of my 6 pages. Any help would be appreciated , thank you.
header {
background-image: url(img/markus-spiske-PIJwPMtzBI0-unsplash.jpg);
background-size: cover;
background-position: center;
margin-top: 200px;
height: 100vh;
background-attachment: fixed;
}

That is because your header tag in the CSS file will always get called on the no matter the page it is.
To solve this, you need to give your header an extra "name" so to speak. In this case giving it an "id" is enough.
#homepage-header{
background-image: url('path/to/image')
}
//As you can see here, instead of calling the <header> im now calling the #homepage-header
<header id="homepage-header">
</header>
//I added a unique ID to <header> tag allowing me to target this header specificly on the homepage.

For sake of completeness, I will add this alternative solution.
If this is just for one or two exceptions, you could also inline the CSS code on the specific page where you want this image to display. Like this:
<div></div> <!-- this is the image div -->
<style>
header {
background-image: url(img/markus-spiske-PIJwPMtzBI0-unsplash.jpg);
background-size: cover;
background-position: center;
margin-top: 200px;
height: 100vh;
background-attachment: fixed;
}
</style>
This way, you can keep using the header selector for whatever you want, and only on that specific page, the header will use the above CSS code.

Related

Cover entire div with image

for my joomla 3.x website i'm using a template based on the EF4 framework. I assigned width "5" to position top2-1 and "7" to position top2-2.
I wanted to create a custom html module for the homepage (http://francescaleso.com/it/) in position top2-1 to show a background image completely filling it.
I have tried as suggested on this site doing like this:
.homeimg {
overflow: hidden;
background-size: cover;
background-position: center;
background-image: url(/images/headers/home-image.jpg);
}
And the module only has
<div class="homeimg"></div>
The path of the image is correct, because if i try "open in new tab" it gets displayed correctly, however it won't show on my homepage.
Make these modifications in the CSS.
.homeimg {
background-size: cover;
background-position: center;
background-image: url(/images/headers/home-image.jpg);
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
----edit--- if i play a bit with absolute and relative positions, i get this:
the problem is that the image isn't the full height of the unscrolled space, and also has an unwanted padding or something on the left...

Adding parallax effect to Wordpress page

I have a Wordpress website with an existing theme and content.
In one page I have a div with a video background and a text in the foreground.
I want to add a parallax effect by some jQuery code.
I can use Id's or classes to both of them if needed.
Can someone advice by a reference to code or to a relevant tutorial?
This is available in w3schools.com
<style>
.parallax {
/* The image used */
background-image: url("img_parallax.jpg");
/* Set a specific height */
height: 500px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
<!-- Container element -->
<div class="parallax"></div>
This website is your answer :
http://scrollmagic.io/examples/advanced/parallax_sections.html
Try checking their examples and implement them in your website. Make sure you are using the related IDs and Classes properly.

Background needs to be different on sub-pages and product details page than index

I'm trying to manipulate the sub pages and prduct details page to only have a very small image across the top. The look of the main "index" page is how I want that one to look.
Basically I want the image on the secondary pages to only show the top 300px of the image and the rest goes to the gray so you can see the products and wording against the solid gray color
current theme is Home iQ
thanks so much in advance
I've edited the theme css to get where i am now with the following code:
html {
background-color: #ebe9dc; 50% 0;
background-size: cover;
}
body {
width: 100%;
height: 750px;
background: url(http://www.sharkdigitalthinktank.com/images_pete/weed_background3.jpg) no-repeat center;
background-size: cover;
}
Try adding a class on the body tag of the secondary pages, like so:
<body class="secondary">
//HTML
</body>
Then in your CSS add the following class after the other body class:
body.secondary {
background-position: top;
background-size: 100% 300px;
}
Is this what you are trying to do?

Windows 8 - Use image for background

I'm creating my first Windows 8 app and I have a problem with CSS!
I have a folder images and background texture bg.png inside it. Also, stylesheet is in css folder.
CSS:
#contenthost {
height: 100%;
width: 100%;
background: url("../images/bg.png") repeat;
}
But nothing happen! I tried background: #999 which works. What should I do?
I tried your example with path to the image relative to the app root and it worked without any issues:
#contenthost {
height: 100%;
width: 100%;
background-image: url('/images/logo.png');
background-repeat: repeat;
}
In terms of your code this would be:
#contenthost {
height: 100%;
width: 100%;
background: url('/images/bg.png') repeat;
}
You can also save the image in your project folder.
And load it in the html page like this:
<img id="mainImg2" src="ms-appdata:///Local//bckgrnd.jpg" />
If it is not the path (using absolute vs. relative as above would fix that) you also need to make sure you have an element with an id = contenthost.
CSS let's you do both id and classes so if you start getting into styling page controls you will see a heavy use of classes like (.mypage .subsection).
Finally, you can always set the background in any individual html file directly on the body tag like:
<body style="background-image: url('/images/bg.png');">

CSS - Print: repeat background through all the page

I have the following problem:
When I print a certain page from my website, and the content of this page doesn't fill all the paper, the background image cuts there. But what I need is to have the background image repeated through all the paper, no matter how much of the paper is taken by the contents.
I'm so sorry, I know it's a little odd this question, so I had a lot of trouble trying to explain it.
Thanks a lot to anyone who can help me.
Use this..:
body
{
background-color:#454545;
background-image:url("background.jpg");
background-repeat:no-repeat;
background-attachment: fixed;
background-size: contain;
zoom: 100%;
}
paste this in your css, it is "attachment fixed" that you are looking for...the background image will never scroll with rest of the page and also you can apply "fixed" to other elements to make them scroll-free.
If the background is attached to the BODY element and it is set to background-repeat: norepeat in your CSS, try
#page {
margin: 1cm; /* or any other small value, maybe even 0 */
}
#media print {
body {
background-repeat: repeat;
}
}
Let's say your image is right in the body tag, your only chance is setting
html, body {
width: 100%;
height: 100%;
background: url(../bg.png) repeat 0 0;
}
But you will never be able to have the background stretch all over the paper as the browser sets a margin on every border. This can be set to 0 by the user in the printing dialog, but can't be controlled by the css / you.

Resources