Hello I'm currently working on a website where I want the logo of the business to overlap into the content.
Similar to this website: http://www.menzies.com.au/
I'm not really sure how to approach this problem, I tried using negative margin, and z-index, but it just felt like the wrong approach
Example Code of what i've tried
<div class="container">
<ul class="nav nav-pills">
<img src="logo.jpg" style="float: left; z-index: 3;">
<li role="presentation" class="active">Home</li>
<li role="presentation">Profile</li>
<li role="presentation">Messages</li>
<li role="presentation">Profile</li>
<li role="presentation">Home</li>
</ul>
<img src="http://all4desktop.com/data_images/original/4172874-nordic-landscapes.jpg" style="z-index: -1; margin-top: -50px;">
</div>
What's occurring is that the second image is overlapping the logo image. It also just feels like a clunky way to approach the problem as I've never seen people advocate using negative margin unless absolutely necessary
Could anyone with experience in doing this point me in the right direction?
Basically what you need do is set the logo position to absolute, then it will be over the other elements. I did a example to you, look at this HTML:
<div id="menu">
<div class="logo"></div>
<nav>
<ul>
<li>Home</li>
<li>Contact</li>
</ul>
</nav>
</div>
The menu div has 75px of height, but his child can have more than this, and if they do, a overflow will occur, that is what you wanna. If it doesn't occur, as I said, you can try set the position to absolute. So, you set the logo div to something like 130px of height, and the nav to 100% height. I changed the height of logo to 130px, but it doesn't affect the other menu child. So, the nav height will be the menu height: 75px. Complete code:
#menu {
width:100%;
height:75px;
background-color:#333;
}
ul {
list-style:none;
}
ul li {
display:inline-block;
}
.logo {
width:150px;
height:130px;
background-image:url('http://placehold.it/150x130');
float:left;
position:absolute;
margin-left:25px;
}
nav {
color:#fff;
float:right;
font-size:1.3em;
line-height:75px;
margin-right:10px;
height:100%;
}
nav ul {
margin-top: 0px;
}
nav ul li {
margin-right:10px;
}
<div id="menu">
<div class="logo"></div>
<nav>
<ul>
<li>Home</li>
<li>Contact</li>
</ul>
</nav>
</div>
This problem is very relative, but with a simple CSS like this one, you can contour this.
Related
I made a fixed navbar and then a header that I used relative position to place it below the fixed navbar. But when I scroll up the header shows over the navbar.
<section class="nav-bar">
<ul>
<li class="nav-left">LOGO</li>
<li class="nav-right">FACEBOOK</li>
<li class="nav-right">GITHUB</li>
<li class="nav-right">TREEHOUSE</li>
</ul>
</section>
<h1 class="head">THIS IS THE HEADER</h1>
h1 {
position: relative;
top:2em;
}
.nav-bar{
background-color: blue;
width:100%;
position:fixed;
margin-top:-1.25em;
margin-left:-.55em;
padding-bottom:1em;
}
Any advice on how to keep the header behind the navbar? I'm sure it has something to do with the fixed and relative positioning but haven't found anything on how to remedy this.
Hanif is right, adding z-index to .nav-bar achieves the effect you desire.
h1 {
position: relative;
top:2em;
}
.nav-bar{
background-color: blue;
width:100%;
position:fixed;
margin-top:-1.25em;
margin-left:-.55em;
padding-bottom:1em;
z-index: 99;
}
<section class="nav-bar">
<ul>
<li class="nav-left">LOGO</li>
<li class="nav-right">FACEBOOK</li>
<li class="nav-right">GITHUB</li>
<li class="nav-right">TREEHOUSE</li>
</ul>
</section>
<h1 class="head">THIS IS THE HEADER</h1>
Can anyone help me with aligning my two divs? What did I do wrong? I have two inline blocks as my divs and am trying to align them at the highest point of the element side by side.
<body>
<ul id="navbar">
<li>Skills</li>
<li>Work</li>
<li>Contact<li>
</ul>
<div id="intro">
<p>HELLO</p>
</div>
css:
#navbar {
display:inline-block;
margin-left:25%;
list-style-type:none;
vertical-align:top;
width:12%;
}
#intro {
display:inline-block;
width:40%;
vertical-align:top;
}
Add margin-top: 0 or any other preferred size (ie margin-top: 20px;) to both IDs.
Ex. http://jsfiddle.net/K9K2X/6/
<ul id="navbar">
<li>Skills</li>
<li>Work</li>
<li>Contact</li> <!-- Forgot to close the element -->
</ul>
#navbar li{
display:inline-block;
margin-left:25%;
list-style-type:none;
vertical-align:top;
width:12%;
}
The links are side-by-side now.
http://jsfiddle.net/K9K2X/8/
so I am starting to learn CSS and I can't wrap my head around this.
I want to make a horizontal navigation bar composed of 3 images. These are the beggining image, the "filler image", and the ending image.
Here is a picture for further reference:
I really don't know how to go about doing this and I havn't been able to find any examples on the web for this.
Thanks in advance!
I'm preparing a jsfiddle demo for you, hang on.
It's pretty ugly, but it should give you a starting point on how to tweak it so it works as you wanted. http://jsfiddle.net/T9FXD/
Markup:
<div>
<div class="first"></div>
<nav>
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</nav>
<div class="last"></div>
CSS:
div {width:600px;height:61px;}
div.first {background-color:red; width:20px;float:left;}
li {display:inline; color: #fff}
nav {width: 500px; background:url('http://placekitten.com/g/1/61') repeat-x top; float:left;}
div.last {background-color:green; width:20px;float:left;}
I'm an hour late to this party, but most of these answers are markup overkill. An unordered list of links has all the styling hooks you need. Basically, padding left on the first li and put in the left image. Padding right on the last li and put in the right image. Main image on the a.
html:
<ul class="example">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
css:
ul.example {
margin:0;
padding:0;
font-size:0; /*this gets rid of the gaps between the items*/
}
ul.example li {
display:inline-block; /*this puts them all in a row*/
margin:0;
}
ul.example li:first-child {
padding-left:10px; /*set this to the width of your left image*/
background-image: url(http://dummyimage.com/10x61/f00/fff);
background-repeat:no-repeat;
}
ul.example li:last-child {
padding-right: 10px; /*set this to the width of your right image*/
background-image: url(http://dummyimage.com/10x61/00f/fff);
background-repeat:no-repeat;
background-position: top right;
}
ul.example li a {
font-size:16px; /*important to set this, as the ul has 0 height text*/
display:block;
height:61px;
line-height:61px;
text-align:center;
width:100px;
background-image: url(http://dummyimage.com/1x61/0f0/fff);
}
http://jsfiddle.net/EKacC/
HTML:
<div class="wrapper">
<div class="firstImage">
<!-- no content, simply assign a background-image -->
</div>
<div class="headerContent">
<div class="headerElement"></div>
<div class="headerElement"></div>
<div class="headerElement"></div>
<div class="headerElement"></div>
<!-- as many as items as you have -->
</div>
<div class="lastImage">
<!-- no content, simply assign a background-image -->
</div>
</div>
CSS:
.firstImage {
float: left;
background-color: red;
width: 50px;
height: 150px;
}
.lastImage {
background-color: blue;
float: left;
min-width: 50px;
height: 150px;
}
.headerElement {
float: left;
background-color: yellow;
width: 50px;
height: 150px;
border: 1px solid black;
}
Not the most elegant solution, but should do it for the beginning. There are - of course - more elaborate solutions... but I think this might work as well for you at the moment.
EDIT
Here is the above markup and css as a working example. I've put borders around the inner (yellow) cells for better visibility.
Stick with using <div> elements for this. Even though tables handle it well, it's more depreciated as they load slower.
It's literally as you depicted the image, with 3 main boxes.
HTML:
<div class="element1"></div>
<div class="element2">
<ul>
<li>Home</li>
<li>About</li>
<li>Forum</li>
<li>Content</li>
</ul>
</div>
<div class="element3"></div>
CSS:
When you have empty div elements, be sure to set dimensions within CSS so that it can show the image you'd like to display.
.element1, .element2 {
width:10px; height:100px;
}
For the image itself.
background:url('...') no-repeat;
CSS:
ul#menu-ediloc li
{
float:left;
padding-left:5px;
position:relative;
}
ul#menu-ediloc ul
{
z-index:500;
position:absolute;
}
I have a drop menu like this, but when it goes down the sub menu is hidden where it touches the next div with is a slideshow and it's outside the relative parent.
I tryed to put position:relative; to body but although it fixes the visibility problem it than messes up my menu.
Any ideas?
<div id="header">
<ul id="menu-ediloc">
<li>
<ul id="sub-menu">
<li>
</li>
</ul>
</li>
</ul>
</div>
<div id="slider">
</div>
I tryed to put the slider in the header and put relative on header, but its same as on body it messes up my sub-menu.
The only way my sub-menu works if i put the relative on the ul li tag.
add the following css
#header{
position: relative;
z-index: 999;
}
I have custom slider sitting at the top of my page but I'm having some issues. I would like the list items to stretch to the width of the screen but I'm having issues forcing this because the list items display below one another. I have set them to float and I have a div surrounding the list with an overflow hidden but to no avail.
I want it so that the current slide is the width of the screen regardless of size, possibly with a min width of 960px
HTML
<div id="slider">
<div class="slides">
<ul>
<li class="slide">
one
</li>
<li class="slide">
two
</li>
<li class="slide">
three
</li>
</ul>
</div>
</div>
CSS
#slider {
position:relative;
margin:0 auto;
top:85px;
width:100% !important;
}
.slides {
margin:0 auto;
overflow:hidden;
text-align:center;
position:relative;
left:0;
}
.slide {
height:630px;
width:100%;
float:left;
position:relative;
}
Try this...
Add a css class like following.
.ul_class {
margin: 0;
padding: 0;
list-style: none;
float: left;
}
After that, assign this new class (ul_class) to your <ul> like this.
<ul class="ul_class">
...
...
...
</ul>
Hope this will help you.