Background image won't display in header? - html

I am new to css and the image for my header is not displaying. Whenever I try to add it to my header the nav gets a slightly darker tint of red? You and your genius minds figure it out!
css:
header {
background: url("http://www.charlottecentercity.org/wp-content/uploads/2013/09/Imaginon-pic.jpg");
background-size: cover;
image-repeat: no-repeat;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
vertical-align: middle;
line-height: 70px;
display: inline;
}
li {
display: inline;
}
nav {
background: rgba(255,0,0,0.5);
}
nav img {
height: 60px;
margin: 5px;
float: left;
}
html:
<header>
<nav>
<img src="https://dl.dropboxusercontent.com/u/105222237/RGBjpeg.png" />
<ul>
<li>About Imaginon</li>
<li>General Info</li>
<li>Programs and Events</li>
<li>Plan Your Visit</li>
<li>Just for Fun</li>
</ul>
</nav>
</header>

The background image is showing on the header, but:
it is set to background-size: cover, which means that you only see the very top, blue part. Presumably, when you have more content, you'll see more of the header, but in the mean time you could add a min-height: 600px; for example.
the nav has a reddish, semi-transparent background color that sits on top of the header background color. Just remove that red color if you don't want it.

Try and give the header (min/max) width / height

Add css overflow:hidden to your header.. and do the same
in future to all your wrapper elements.

Do give the header a defined size, as it will not be able to fill something that does not have a defined size to it.
header {
margin: 0;
padding: 0;
width: 100%;
height: 100px;
background: url(../wp-content/uploads/2013/09/Imaginon-pic.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
If your style sheet is in a subfolder like I usually have, make sure to add ".." to your image location to tell css to step back one directory. Using a direct path will require another http request, not a huge deal but slows your site down in the long run.
I included the webkit background code because I believe it to be easier to use. As well as creating browser compatibility.

Related

How to have both background effect and position fixed [duplicate]

This question already has an answer here:
How to have both position fixed and background-attachment fixed?
(1 answer)
Closed 2 years ago.
I have a parent div which is holding links called #linkHolder. I have its position:fixed. The links have a background which have a background-attachment: fixed to give it that nice background effect. Those two things seem to cancel each other out. Is there a way around this issue?
#linkHolder {
display: block;
position: fixed;
top: 0;
width: 100%;
}
ul {
list-style-type: none;
overflow: hidden;
background-color: #1b242f;
text-align: right;
font-size: 22px;
width: 100%;
font-family: "Sansita Swashed";
}
ul li {
display: inline-block;
padding-right: 6%;
}
#homeLink {
background-image: url("/static/portfolioBackground/linkBackA.png");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
<div id="linkHolder">
<ul>
<li><a id="homeLink" href="/">Home</a></li>
<li><a id="aboutLink" href="/about">About</a></li>
<li><a id="serviceLink" href="service">Services</a></li>
</ul>
</div>
Here's the issue on codepen I am having.
https://codepen.io/webdev154676/pen/VwjNoRN
Here's what I would like to have with the background image, but with the #linkHolder as position fixed, it will not work. Please help, and thank you for your time.
https://codepen.io/webdev154676/pen/rNLgBVv
From your question I'm understanding that the issue is that the background image is a little more blurred than what you would like to have.
For that i sudjest you to try using the background-size attribute and play around with it giving some sizes in % like
#homeLink{
background-size:90% 100%;
}

Bootstrap autosizing background images

I'm trying to make a background image on the header section autosize but it won't keep to aspect ratios. Here is an example, the image gets the bottom of it cut off: http://i.imgur.com/sxedPHI.png or if I make it this size, space appears between it and the divs below header: http://i.imgur.com/xX1e4GZ.png I can almost seem to get it working but then it scales the picture to an odd aspect ratio and the image gets distorted: http://i.imgur.com/jtxDNr0.png
I would like the header section to be the EXACT same size as the image, then have the image always showing all of the image (not cutting off a portion) and no space between header and the next divs.
This is the code I have for the HTML part:
<header>
T
</header>
I believe this is the relevant CSS:
header {
position: relative;
width: 100%;
height: 100%;
text-align: center;
color: #fff;
background-image: url("ball.png");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-repeat: no-repeat;
background-size: 100% auto;
}
The site in question is here:
http://www.stoppiefail.com/boot/sites3/index.php
You are using background-size: 100% auto; at the end which will be overwriting your previous code.
https://jsfiddle.net/26ejdss6/1/
div{
width:400px;
height:187px;
background:url('http://ajgdirect.co.uk/wp-content/uploads/2015/04/football.jpg');
background-size:cover;
background-position:center;
}
Also, check out a neat plugin named backstretch.js. It's pretty nice for this kind of thing, especially when auto-sizing user added images in a CMS
http://srobbin.com/jquery-plugins/backstretch/
Instead of using Background Image why not use an IMG tag with an absolute div on top of it.
HTML:
<header>
<img src="your/background/image.jpg" class="bg">
<div class="headerContent">Your Header Content Goes Here</div>
</header>
CSS:
header {
width: 100%;
position: relative;
}
header img.bg {
width: 100%;
height: auto;
position: relative;
z-index: 0;
}
header .headerContent {
width: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 100;
}
I havn't tested this but it is just another way to do this outside of css, that would allow the height of the header never to be cut off.

How do I get rid of whitespace between sections CSS/HTML

I'm new to web design and ran into this problem; I have two sections, each section with its won background image. However, the first background image doesn't end right after the previous background image. Instead, there's a whitespace between the two images that looks hideous.
This is the jsfiddle: http://jsfiddle.net/M26Ge/
CSS:
#slide-1 .bcg {
background-image:url('http://upload.wikimedia.org/wikipedia/commons/1/15/Hopwas_Woods_Sun.jpg');
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
height: 800px;
width: 100%;
}
#slide-2 .bcg{
background-image:url('http://i953.photobucket.com/albums/ae11/Kronstadt/Shabby-Princess-Kristie_SF_StripedP.jpg');
background-position: center center;
background-repeat: repeat;
background-attachment: fixed;
background-size: cover;
height: 100%;
width: 100%;
}
I am not sure, but maybe are you looking for CSS Reset?
Just write * { margin: 0; padding: 0; } at top of css code. Else, if you are having other whitespace issues with inline elements, you can fix them using font-size: 0; on the container of the affected elements.
You can as well hold the margin of hx and p elements within the section by
setting a border to the first child div . Borders
section>div {
border:1px solid transparent
}
or padding will do:
section div {
padding:1px;
}
To understand what is going on , you can read this article.
Add this to your CSS:
*{
padding: 0;
margin: 0;
}
This sets the margin and padding of all elements equal to zero.
Using Sublime Text you have to place your elements right beside the other one.
<section>
<div></div>
</section>
<section>
<div></div>
</section>
should become :
<section>
<div></div>
</section><section>
<div></div>
</section>

100% width Background Image

I'm trying to do a background image of 100% and have an image as the background. When I upload the image it goes to 100% but it cuts off have the picture. It makes the image wider than my screen. How do I fix it where the picture width is 100% but the image width fits the screen without getting cut off. Here is my tumblr to let you see what I mean (http://ophelialogy.tumblr.com/) and here is the full image to show you the full image and give you an idea for where it's cutting off (http://imageshack.us/a/img7/7103/khb3.png).
Here is my code:
CSS PART
/* --- HEADER --- */
#header {
top: 0;
left: 0;
width: 100%;
{block:IfAdjustableHeader}height:{text:Header Height};{/block:IfAdjustableHeader}
{block:IfNotAdjustableHeader}height:100%;{/block:IfNotAdjustableHeader}
position: fixed;
z-index: 10;
background-image: url('{image:header}');
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* --- PAGE CONTENT --- */
#page {
{block:IfAdjustableHeader}top:{text:Header Height};{/block:IfAdjustableHeader}
{block:IfNotAdjustableHeader}top:100%;{/block:IfNotAdjustableHeader}
left: 0;
width: 100%;
min-height: 100%;
position: absolute;
background: {color:Background};
z-index: 99;
}
.container {
margin: 50px auto 0px;
{block:If400Posts}width: 800px;{/block:If400Posts}
{block:If500Posts}width: 900px;{/block:If500Posts}
}
/* --- POSTS --- */
.postcol {
width: 540px;
margin-left: 240px;
}
.posts {
margin-bottom: 20px;
background-color: #fff;
padding: 20px;
}
.posts img, .posts li, .posts blockquote {
max-width: 100%;
}
HTML Part
<body>
<div id="header">
<div class="description">{Description}</div>
</div>
<div id="page">
<div class="container">
<div class="postcol">
{block:Posts}
<div class="posts">
</div>
this excellent blog post explains exactly what you need, without any third party tools:
http://css-tricks.com/perfect-full-page-background-image
also, there are some jQuery plugins for that, including:
https://github.com/jaysalvat/vegas
https://github.com/buildinternet/supersized
SO...
What cover does (in my mind) is take the background image and do it's best to use the most of it that it can depending on the height or width of the box it is in. There are 2 ways to deal with this. One way is to make the box the perfect ratio for the image. The other is to actually use an img that will stretch the box to it's exact size. Here is how to do each. The plus of the background-image version, is that you can easily only serve a small version to small screens with an #media rule.
HTML
<header class="container global-header"></header>
<header class="container global-header2">
<img alt="banner-thing" src="http://placekitten.com/400/100" />
</header>
CSS
html, body {
height: 100%;
margin: 0;
}
.container {
width: 100%;
float: left;
}
.global-header {
width: 100%;
/* this is hacky - but it is your answer */
height: 0;
padding-bottom: 25%;
background-image: url("http://placekitten.com/400/100");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
/* you should have this too */
background-position: center center;
}
.global-header2 {
width: 100%;
/* height will be determined by image size */
}
.global-header2 img {
display: block;
width: 100%;
height: auto;
}
FIDDLE
use:
background-image: url(../images/myimage.jpg);
background-size: cover;
Do you want the background image in the header or on the main page?
It is currently in the header.
Set the background image on the html tag if you want it to cover the whole page.
Nasser's link to do that is a good one (I would leave out the browser specific hacks though).
EDIT
AHH You're talking about width.
I think it might be something to do with the irritating slider tumblr have coming in from the right - it is about that much too stretched.
I suggest trying these styles on jsfiddler - or another separate site - you'll probably find it works fine.

Background image of li element not showing in firefox

I have an html portion of code in my page that goes something like this:
<section class ="sidebar">
<ul>
<li class="facebook">Facebook</li>
<li class="linkedin">LinkedIn</li>
<li class="twitter">Twitter</li>
<li class="google-plus">Google+</li>
</ul>
</section>
And the css goes like this:
.sidebar ul {
float: left;
}
.sidebar ul li{
display: block;
width:35px;
text-indent: -9999px;
margin: 3px;
}
li.facebook{
height: 35px;
background: url(img/icon_face.png) center center no-repeat;
background-size: contain;
}
li.twitter{
height: 35px;
background: url(img/icon_twitter.png) center center no-repeat;
background-size: contain;
}
li.google-plus{
height: 35px;
background: url(img/icon_g+.png) center center no-repeat;
background-size: contain;
}
li.linkedin{
height: 35px;
background: url(img/icon_in.png) center center no-repeat;
background-size: contain;
}
What happens here is that I have 2 strange issues:
First the element li.google-plus does not show in any of the browsers. The browsers just ignore it. Here is what firebug shows:
The second is that the only image that shows in firefox is the twitter one. In chrome and opera all the other ones show correctly. As they are showing correctly in other browsers I assume the problem is not the path in the background property.
Any idea on what the problem may be?
EDIT:
Check what firebug says about the background image path:
It says that it couldn't load the given url.
Both in .sidebar ul li and in li.facebook,li.twitter etc. You should write width: and height: properties which You didn't set.
Ok, so it turns out that the problem was my AdBlock extension. After disabling it, it started working normally.
Figured it out through this answer: https://stackoverflow.com/a/466020/1235708