Windows 8 - Use image for background - css

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');">

Related

CSS: background-image not loading?

Heyya,
I've just started writing a website (I'm still pretty new to learning web dev) and I'm having issues with getting a background image to load on a website despite looking around and trying a bunch of different things.
.nav {
width: 100%;
background-image: url("../images/Shadex1.png");
background-repeat : repeat-x;
position : absolute ;
height: 50px;
left : 0;
top : 0;
}
The idea is to get the image to repeat and cover the nav bar and I've tried using both a png and svg files, but I just can't get it to work. I can load the images in the html file and that works fine so I know the file path is correct but CSS just isn't liking it so need a second pair of eyes to take a look.
Thank you for reading and any answers you might come up with.
Try to set width to 100vw and is the uri correct?
Make sure you are able to load the image background-image: url("../images/Shadex1.png"); property. I think there might be chances that url is wrong. if you are getting an image correctly than just see below example.
.nav {
width: 100%;
background-image: url("https://images.unsplash.com/photo-1657037031161-d126c02cce8c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw2fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60");
background-repeat: repeat-x;
position: absolute;
height: 100vh; /*I have added extra height for viewing image*/
left: 0;
top: 0;
}
<div class="nav"></div>

Add background image to each PDF page generated using html-pdf

I am using html-pdf (https://www.npmjs.com/package/html-pdf) to generate PDFs based on HTML files.
I am now trying to add background images to these PDFs. One special/additional requirement is that the first page should have another background image than pages 2...n.
My attempt was to make use of the header feature, but the background images are never shown.
I added a header to the template, which is shown correctly, and tried to add a background image using the following CSS:
#pageHeader:after,
#pageHeader-first:after {
content: "";
display: block;
position: fixed;
bottom: 0;
right: 0;
top: 0;
left: 0;
height: 297mm;
width: 210mm;
background-image: url('/background-default.jpg');
background-repeat: no-repeat;
background-size: contain;
}
Just for reference, this is how I am adding the headers within the HTML file:
<div id="pageHeader">Test1</div>
<div id="pageHeader-first">Test2</div>
Any idea what I am doing wrong here?
Or is there a better way to achieve what I am looking for?
I found the solution for the problem:
Due to PhantomJS limitation, apparently I have to also add the images to the body and hide them using display: none;
Once that's done, the images will also show in the header/footer sections of html-pdf.
More detailed information can be found here: https://github.com/marcbachmann/node-html-pdf/issues/12

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

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.

nodejs, background-image css doesn't work

quick and simple question, I'm trying to add a div with a background-image in *.ejs page file.
<style>
.signPage{
background-image: url("//back.jpg");
width: 98%;
height: 98vh;
top: 1%;
right: 1%;
position: fixed;
border-radius: 20px;
}
the image and the ejs are in the same directory.
thanks
you need to first provide a static path in app.js and then put background image at public/images
to use it just
background-image: url("images/back.jpg");
app.use(express.static(__dirname+'/public'));
You have to provide the path from the css file in which you have
specified the rule. For example: if the image is in folder
public/images and the css file is in folder public/css, then you
should provide like this
-- ../images/image-name.image-extension
In short - You have to provide a path relative to css to image

HTML5 boilerplate background-image doesn't show

I'm making a website with HTML5Boilerplate, but every time I use the css background or background-image property, the image doesn't show up.
Folders:
root/css/style.css
root/img_files/logo.png
My css code looks like this:
#logo {
position: absolute;
left: 20px;
top: 10px;
width: 164px;
height: 42px;
background: url(../img_files/logo.png);
background-repeat: none;
}
My stylesheet is properly added to the page:
I can't add a single background image to the objects on the page. HTML5Boilerplate has been installed, so maybe that't the problem, I'm not sure. Do you know why correct CSS and HTML doesn't display the images?
Change
background-repeat: none;
to
background-repeat: no-repeat;
Or just use
background: url(../img_files/logo.png) no-repeat;
I've just come to the same problem and discovered that in case you'll change ID from #logo to anything else (in HTML and CSS of course), then the same code will start to work. Can't say what has been "blocking" #logo to be used, but for now I don't have enough time to discover where the problem is.
Solution for now is to use anything else than #logo, eg. #logoTop or #siteLogo
Hope that helps.
EDIT: It was a selector typo problem which caused browser had ignored that. Weird was it had not happened when selector was changed to some other name than #logo. Please note that #logo:visible typo (instead of visited)
#logo, #logo:link, #logo:visited,
#logo:active, #logo:focus, #logo:hover
{
display: block;
width: 340px;
height: 150px;
background: url(../images/design-elements.png) 0 -300px no-repeat;
}
I had the same problem & found out that if without the width & height property, image will not display.

Resources