Div with background image not displayed / height ignored - html

I am trying to build a header similar to this one: http://themes.tf/preview/?momentum
I've set a height but the div still won't get displayed and the content slips to the top.
How can I fix this?
The css is:
.header {
position:relative;
display:block;
width:100%;
z-index:1;
height:688px;
}
.bg-img {
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
background-attachment: fixed;
}
This is the html:
<div class="header bg-img" style="background-image: url('img/xlheader_s.jpg');">
<img src="img/schwager-baubetruung_logo.png" id="logo" alt="schwager baubetreuung logo">
<nav>
<ul>
<li class="current">Startseite</li>
<li>Über uns</li>
<li>Unsere Arbeit</li>
<li>Galerie</li>
<li>Kontakt</li>
<li>Impressum</li>
</ul>
</nav>
</div>
Here you can see the live version: http://suitsncats.de/index_copy.html
If you go to the index page you can see my previous attempt that worked but had a static header image.

I've looked into the source on your website and encountered two issues:
You've used an id selector (#header) instead of class selector (.header) in your style_copy.css and there's also a syntax error in it (no ; after the height declaration)
#header {
position:relative;
top:0px;
left:0;
height:668px
z-index:1;
}
/* should become: */
.header {
position:relative;
top:0px;
left:0;
height:668px; /* <--- note ; */
z-index:1;
}

In your live version, I've checked out your CSS file style_copy.css and noticed that you tell the CSS to look for #header even though in the HTML you're using .header.
You also forget the ; after the height declaration.
Solution:
Change this in the live version's CSS:
#header {
position:relative;
top:0px;
left:0;
height:668px;
z-index:1;
}
To this:
.header {
position:relative;
top:0px;
left:0;
height:668px;
z-index:1;
}
Hope this helps!

Hi I looked into your source at live website, try following solution:
<div class="header bg-img" style="background-image: url('img/xlheader_s.jpg');">
<img src="img/schwager-baubetruung_logo.png" id="logo" alt="schwager baubetreuung logo">
<nav>
<ul>
<li class="current">Startseite</li>
<li>Über uns</li>
<li>Unsere Arbeit</li>
<li>Galerie</li>
<li>Kontakt</li>
<li>Impressum</li>
</ul>
</nav>
</div>
and CSS:
.header {
position: static;
height: 100px;
width: 100%;
background-color: red;
}
nav {
width: 50%;
height: 30px;
margin: auto;
display: table;
z-index: 2;
text-transform: uppercase;
}
Not exactly how you wanted, but one step closer.

Related

When i add image into container i can`t make it responsive

I have a dilemma with some code in HTML & CSS, when I add a simple header with an image and I set properties to image {height:100%;
width: auto;} it works, but when I have the image in more complex code isn`t working anymore.
In the smaller code if i change height of header the images change as well,but on second code if i change height of header image stays on same size
Can someone please explain to me why that happens?
Down here i have two code snippets to see what I`m saying
header{
height:80px;
background:#eee;
}
.header-content{
display:flex;
}
.header-content img{
height:100%;
width:auto;
}
.links-list{
display:flex;
margin-top:50px;
}
.links-list li{
margin-right:4rem;
}
<!-- !Header -->
<header class="header ">
<div class="container">
<div class="header-content">
<img src="http://www.lazarangelov.com/wp-content/uploads/2015/12/logo1.jpg" alt="">
<div class="menu-links">
<ul class="links-list">
<li>Home</li>
<li>Bio</li>
<li>Training</li>
<li>Academy</li>
<li>Gallery</li>
</ul>
</div>
</div>
</div>
</header>
nav{
background:#eee;
height:80px;
}
nav img{
height:100%;
width:auto;
}
<nav>
<img src="http://www.lazarangelov.com/wp-content/uploads/2015/12/logo1.jpg" alt="">
</nav>
Here is the codepen link for reference: https://codepen.io/anon/pen/pmEgaM
you just need to keep the styling for header as height: 100%; and keep changing height of image in the header-content img styling this will give you expected result
header{
height: 100%; # this will make sure your header height is 100% irrespective of image geight
background:#eee;
}
.header-content img{
height:100%; #this height you can change
width:auto;
}

How do I place an image behind my navigation links?

I'm trying to place an image behind my navigation bar and I want it fixed on the top right side of the page but I'm having a hard time trying to do so.
Here's what I want the page to look like:
This is my HTML:
<div class="navbarcn">
<div class="navbar">
<img src="bamboo.png">
<nav class="header">
<a class="active" href="javascript:;">HOME</a>
<a class="headl" href="menu.html">MENU</a>
<a class="headl" href="about.html">ABOUT</a>
</nav>
</div>
The CSS:
.navbarcn{
margin:0;
height:120px;
position:fixed;
width:100%;
}
.navbar{
float:right;
text-align:right;
width:100%;
height:200px;
}
.navbar img{
width:250px;
float:right;
}
.navbar a{
padding:10px;
text-decoration: none;
font-size:1.4em;
font-weight: bold;
}
First, you should not use an img for this kind of styling. Use CSS. (Here I have commented out the image).
<div class="navbarcn">
<div class="navbar">
<!-- <img src="bamboo.png"> -->
<nav class="header">
<a class="active" href="javascript:;">HOME</a>
<a class="headl" href="menu.html">MENU</a>
<a class="headl" href="about.html">ABOUT</a>
</nav>
</div>
Next, add some background properties to target your navbar.
.navbarcn{
margin:0;
height:120px;
position:fixed;
width:100%;
}
.navbar{
float:right;
text-align:right;
width:100%;
height:200px;
background-image: url(https://placekitten.com/100/50);
background-repeat: no-repeat;
background-position: top right;
}
/*.navbar img{
width:250px;
float:right;}
*/
.navbar a{
padding:10px;
text-decoration: none;
font-size:1.4em;
font-weight: bold;
}
Fiddle: https://jsfiddle.net/Lf4exsv7/
Using IMG vs CSS background-image: When to use IMG vs. CSS background-image?
Give .navbarcn background image
.navbarcn{
margin:0;
height:120px;
position:fixed;
width:100%;
background-image:url('bamboo.png');
}
.navnarcn's parent must explicitely have the css property position defined.
There are two solutions
Best way
.navbarcn{
background: url('path to your image')
}
Alternative way
.navbar img{
height: 35px
}
.navbarcn{
margin-top: -35px
}
using background would be a better solution but this is also fine
use absolute position for the image
.navbar{
position:relative;
}
img{
position: absolute;
top:5px;
right:5px;
display block;
z-index:-1;
}

Positioning and Floating aren't working?

I've tried numerous of things to fix this. I cannot seem to get the nested div inside the parent div without having to use margin. I'm trying to get it in the regular way which is position:relative on parent and position:absolute on nested. It's not working though, anybody know why?
HTML
<div class="header">
<div class="logo">
<img src="/images/logo.png" width="96" height="82">
</div>
<div id="nav">
Portfolio
About
Contact
</div>
<div id="headerPro">
</div>
</div>
CSS
.header {
position:relative;
background-color: #2C2E31;
border-bottom: #242426 2px solid;
height: 182px;
}
.logo {
text-align: center;
padding-top: 35px;
}
#nav {
position:absolute;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav a {
border-bottom:#FFFFFF 2px solid;
color:#FFFFFF;
text-decoration:none;
margin-left: 8px;
margin-right:8px;
}
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
}
It's hard to tell what exactly you want it to look like, but maybe I got you right:
I revised your HTML code to use ul for the nav which is best practice:
<div class="header">
<div class="logo">
<img src="/images/logo.png" alt="logo"/>
</div>
<ul id="nav">
<li>Portfolio</li>
<li>About</li>
<li>Contact</li>
</ul>
<div id="headerPro">
</div>
</div>
With that your css code could look like that:
.logo > img {
display: inline-block;
width: 96px;
height: 82px;
}
#nav {
position:absolute;
list-style-type: none;
bottom: 0;
width: 100%;
text-align:center;
text-decoration:none;
font-size:20px;
font-family:raleway-regular;
}
#nav > li {
display: inline;
}
#headerPro {
position:absolute;
top: 35px; /* assuming you want this to line up with the logo */
right: 0;
width:100px;
height:100px;
background-color:red;
}
Here is a demo.
See this fiddle
Example
I have made two changes added a float:left to the logo css:
.logo {
float:left;
}
and removed the position:absolute from the header pro css
Your div is flowing outside the header block because of the logo div, if you make that float left (as I have done in the fiddle) the Red Div will move up.
It would help if you could explain exactly where you want the #HeaderPro div..
Apparently the browser positions your div#headerPro just below the previous(sibling) div. If you want it to be part of the parent div, add top:2% to position the red div in the top right corner of the black div.
#headerPro {
position:absolute;
float:right;
width:100px;
height:100px;
background-color:red;
top: 1%;
}

Trying to center fixed menu div on page

I've tried a few different rules but I can get my top menu to center. When I change the position to absolute or relative it does go to the center but then the height goes to 100% for some reason. I don't have a set height because I want the five to be the size of the children.
Here's the HTML:
<div id="topWrapper">
<a href="index.html">
<header id="top_header">
<h1>MacroPlay Games</h1>
</header>
</a>
<nav id="topnav">
<ul>
<li>Home</li>
<li>About</li>
<li>Trailers</li>
</ul>
</nav>
</div>
CSS:
#topWrapper {
border:1px solid #00ffff;
background-color:#0d0d0d;
text-align:center;
position:fixed;
z-index:9999;
width: 850px;
margin: 0px auto;
float:clear;
}
Fiddle: http://jsfiddle.net/kjAAy/
Add margin:0 auto with left:0px; right:0px
#topWrapper {
border:1px solid #00ffff;
background-color:#0d0d0d;
text-align:center;
position:fixed;
z-index:9999;
width: 850px;
margin: 0 auto; left:0px; right:0px;
float:clear;
}
DEMO
Same method works even for position:absolute
I noticed a small error in the original code and also the code for the most popular response from Sowmya.
More specifically, the property in question is "float: clear;", and to my knowledge there's no such thing as "float: clear;"
Unfortunately, since I just created this account I'm unable to correct the error or reply to that post. Which is why I created a new post.
You can check out W3C for float CSS properties here:
http://www.w3.org/wiki/CSS/Properties/float
Values listed are "left | right | none | inherit"
Thanks for listening!
Position="fixed" is not recommended though.
<div id="someid" align="center">
--whatever code--
</div>
This would do. I recommend you should read the purpose of position tag.
http://www.barelyfitz.com/screencast/html-training/css/positioning/
Or you could use:
border:1px solid #00ffff;
background-color:#0d0d0d;
text-align:center;
position:fixed;
z-index: 9999;
width: 850px;
float: clear;
left: 50%; /* position halfway from the left of screen */
margin: 0px 0px -425px 0px; /* pull the div into center */ }
Fiddle: http://jsfiddle.net/zXFdN/3/
ps align="center" is not supported in HTML5: http://www.w3schools.com/tags/att_div_align.asp

How to get stable menu?

I want to place a stable menu in my site. In the site, even if we move down the page, I would like to always display the menu on the top.
Example: iplex.co.in... Please visit this site for demo.
Using position:fixed you can set the position of the element relative to the browser window.
HTML:
<div id="main">
<div id="menu">
<ul>
<li>Menu1</li>
<li>Menu2</li>
<li>Menu3</li>
<li>Menu4</li>
</ul>
</div>
</div>​
CSS:
#main
{
height:1200px;
width:auto;
border:1px solid Red;
}
#menu
{
height:50px;
width:auto;
background-color:#DDD;
position:fixed;
top:20px;
left:60px;
}
#menu ul li
{
display:inline;
float:left;
margin:5px 10px;
}
​
See working sample
You can do it by placing the <div> with positions : fixed for sample
#navigationMenu {
position: fixed;
margin-left: 1086px;
z-index: 10000;
}
You should use position: fixed in order to make some element fixed in the page.
HTML:
<ul id=menu>
<li>Section 1
<li>Section 2
<li>Section 3
</ul>
CSS:
#menu {
position: fixed;
right: 0;
top: 50%;
width: 8em;
margin-top: -2.5em;
}
For your specific usage, check this page: http://www.w3.org/Style/Examples/007/menus.en.html
use a position:fixed; property to your menu id.