Header image with CSS in Bootstrap theme always changes back to default - html

I'm new to Bootstrap 3 (part of the problem), and I'm trying to set up a quick portfolio site for a class. I'm using the One Page Wonder starter template from here: http://startbootstrap.com/one-page-wonder. I've got a problem with the one-page-wonder.css stylesheet. I'm trying to change the header image from the placeholder, and I added a style for an essay, but neither change shows up when I drop it onto the server. I have deleted the entire bootstrap folder on my server and reuploaded it, but whenever I go to my page and check the code, it shows the same placeholder image and the same old style sheet. Here's the style I want to use:
.essay {
text-indent:50px;
}
.header-image {
background:url(/images/Fire.jpg) no-repeat center center cover;
background-position:top;
height:auto;
display:block;
width:100%;
text-align:center;
}
Here's a link to the page: http://jonathanalumbaugh.altervista.org/courserequests/photographyone.html
It's really annoying, I've looked through all the code, but it always reverts to this placehold.it thing. I've tried clearing out cookies, cached images, and files, but to no avail.

You're applying your CSS style incorrectly. You are passing an invalid value to background-image - that property expects only the URL to the image.
You are looking to set the background property, which is a shorthand property for multiple other properties. You can use it like this:
background: #000 url(/images/Fire.jpg) center center no-repeat;
ref: https://developer.mozilla.org/en-US/docs/Web/CSS/background
You should always ensure your CSS is valid:
http://jigsaw.w3.org/css-validator/
Note: Your image still can't be found. Where is it?
You can't include cover in the background shorthand, you need to do something like this:
html {
background: url(/get/the/right/url.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Related

how to make background-image on html

I am currently using a template and there some code I don't understand
<div class="item owl-bg-img" style="background-image:url('http://placehold.it/1920x1050');">
I don't want to mess up with CSS and I just want to change the code in HTML as you can see it is linked to online but I want to link to my local computer. i have html and all css and the picture but dont know how to link
You cans simply change this
background-image:url('http://placehold.it/1920x1050'); as per your requirements.
If you want to add image background then replace http://placehold.it/1920x1050 with your actual image path.
If you want to use color background then remove background-image:url('http://placehold.it/1920x1050'); and use background: red; Add your color or color code instead of red
Well first off, you need to download the image you want to link to your local machine and then reference that in your background-image inline CSS.
Have a look at this link hopefully, it helps.
https://www.w3schools.com/tags/tag_img.asp
To link to an image in your PC, you need to have the HTML file in your PC and to link the image location to the one on your PC. Example:
Let's say you have index.html and background.jpg in the same folder, then you use:
<div class="item owl-bg-img" style="background: url(/background.jpg);">
You can do the same by using CSS.
.item owl-bg-img {
background: url(/background.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: relative;
}
Assign the background to the entire HTML using CSS
html {
background: url(/background.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: relative;
}
Use the IMG tag. It is hard to set a background image to a DIV, it is also not recommended.
<img class="item owl-bg-img" src="/background.jpg">
Then you just add the CSS (width, height, etc) to the class "item owl-bg-img" like you would do to a DIV.
Another way if you really need that DIV,
<div class="item owl-bg-img"><img src="/background.jpg"></div>
This way the DIV will be the size of your image, otherwise resizing the DIV using CSS, will scale the IMG tag to fit the DIVs size.
Using CSS may be simpler than you think. Try adding this in the <head> and </head> tag of your HTML page:
<style>
.banner {background-image: url("http://placehold.it/1920x1050")}
</style>
And then put this where you want your image to show:
<div class="banner"></div>
Style as needed, add text, etc.
If you want to host the file on your own machine, simply replace "http://placehold.it/1920x1050" with something like "assets/pics/my_image.jpg".
Good luck!

Using ID on HTML or BODY to set page-specific background image in CSS

On a small currently unfinished bootstrap site (www.ehrenamt-ladenburg.de) I am trying to style the background image differently for each actual html file involved.
In my stylesheet for additional styling beyond bootstrap_3_3_1.css I am setting up the background image as a background url as in:
html {
background: url(../images/tb20150807_210648_0216_8_0217_8_0218_8_0219_9_0220hdr-pm_1200.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
This works for HTML as well as BODY elements - but not for DIVs or lower level elements (to cover the full background for a responsive page).
Initially I had thought of referencing an additional page-specific CSS file in each html file involved just to style the html background for each of the few pages of the site (which seem a reasonable way of getting things done).
A google search brought me to Stackoverflow and the "Page-specific css rules - where to put them?" thread (and caused me to sign up immediately because of the quality of the question and answer exchange I found).
Now the question for the experienced folks (I am still fairly new to serious bootstrap and css programming):
Couldn't I find a way to reference some sort of page ID in my css selectors to restrict a certain background image to a certain page?
So my question, I guess, is: how can I style BODY element (or HTML element for that matter) with an ID and reference it in a page-specific way? What is the syntax? Or what am I doing wrong?
With:
<body id="03_eal">
in the html file neither:
body#03_eal {
background: url(../images/tb20150614_081922_231.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
nor:
#03_eal body {
background: url(../images/tb20150614_081922_231.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
in the css file work for me.
Leaving out the ID portion in the css, it works fine using either BODY or HTML elements.
What would be the syntax? Or what am I doing wrong in trying to select HTML or BODY using an ID?
Since the body has an id already. There is no real reason to include the tag selector in your css. ID's should be unique and using that specific id can be called just like this
#some-id {
someKey: someValue
}
And no need for doubt. If you have access to your pages, you are more than allowed to add a class or id to that page to make it standout visually different than other pages.
You can also wrap your content in every page with a tag and pass your class or id that way as well.
Ok so the reason it does not work for you is that you are starting your css id with 0 which converts to a number. Try removing the 0. Never start any css selector with a number. Try adding the number as a suffix and your issue will be resolved
Include your image in body and that will work fine. No need of including id or class in body just add below code. But keep in mind that you are using background image for your website, so compress its size. It shouldn't be much heavy in size.
body{
margin : 0; //optional
padding : 0; //optional
background: url(../images/tb20150807_210648_0216_8_0217_8_0218_8_0219_9_0220hdr-pm_1200.jpg);
background-position:fixed;
background-repeat:no-repeat;
background-size:cover;
}

Background image with "buttons" made from other images

I'm making a pretty simple html page for Facebook, I want a big image as the background and little images as buttons all over the bg, I want to know how can I code the background and the "buttons" so these take you to a different page.
For buttons you just need to create the element, and then add in the link attribute.
So for creating a button that links to Google.com:
<button onclick="location.href='http://www.example.com'"> www.example.com</button>
Often people will have a div that contains that majority of their body of their html. So you can use:
background-image : url('image.jpg');
attached to your div or body tag.
A similar more thorough approach would be to just attach it to your html selector, like so:
html {
background: url(image.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
I've made a FIDDLE to give you an example of how to use background-image, and a button that links to Google.
You can of course style any of these elements.

Bootstrap clearing html selector (background image)

I'm just starting to understand enough HTML / CSS to drive myself crazy trying to implement new things.
I'm trying to create a landing page with a full width / height background image that resizes with the viewport. That's an easy enough proposition if you're not using any css framework but I'm trying to build bootstrap into the page.
With bootstrap any content that I add below the body selector clears my background image as if it were part of the normal box model. If I remove bootstrap the page functions as expected and overlays the content on top of the background image. I'm guessing something in bootstrap is clearing all page elements but I haven't been able to find it.
The code I'm using to apply the background image is:
html {
background: url(../img/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
z-index: -999;
}
There is an (indirect) example of a fullscreen background image using Twitter Bootstrap in this blog post.
The gist of it being:
body {
background: url(../img/bg.jpg);
}

CSS - using large images as background (performance)

I have question about site performance. I have 4 large images (1920*500px) that need to be show on the home page in some kind of slider - user need to click for the next image to show up, it is not slide show.
When home page is loaded, only first image is being seen, and rest are need to be seen only at user request.
My question is next. Is it smart to create one large image (sprite) and use this as background (this images have focus on centar, and users which have display that supports this resolution can see the hole image, users that don't have that kind of display will see as much as they can) or to go with standard img tag, or there is some better way to do this?
The advantage of using a sprite is that you are saving HTTP requests and preloading images (which is essential for responsive image rollovers, for instance).
In your case, I don't think sprites make any sense. First, you are only saving three http requests (the first image is presumably visible when you load the page) and you are forcing every visitor to download these large images even if they aren't going to see them.
Im not sure I understand what your asking, but if your always rendering one of the images,then it may be smart to just create a full screen background image like this. You can also change the background image with js when necessary
<style>
html
{
background: url("your image") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
opacity:1;
}
</style>
Change the class with jQuery.
.bg-1 { background: url("your image") no-repeat center center fixed; }
.bg-2 { background: url("your image 2") no-repeat center center fixed; }
.bg-3 { background: url("your image 3") no-repeat center center fixed; }