HTML Header Alignment - html

I am trying to create a header that contains an image along with links that will act as a nav menu for users to navigate.I want the layout to look something like this.
However, I cant seem to get the alignment of the nav menu right to vertically align right above the underline in the header.
<header>
<div>
<img id="headerimage" src="" />
</div>
<nav id="headernav">
<ul id="list">
<li class="menuitem">
Link1
</li>
<li class="menuitem">
Link2
</li>
</ul>
</nav>
</header>
CSS:
html, body {
height: 100%;
background-color: #cccccc;
margin: 0;
}
#header {
border-bottom: 2px solid black;
}
header {
margin: 0;
background-color: #cccccc;
}
height: 5%;
width: 100%;
}
.menuitem {
display: inline;
float: right;
vertical-align: top;
margin-right: 2%;
}
#headerimage {
width: 36px;
height: 36px;
margin-left: 3%;
vertical-align: middle;
}
How do I keep the links to the right of the page along with moving them above the border? Any help would be greatly appreciated.

Your CSS snippet has some typos, it probably should be:
html, body {
height: 100%;
background-color: #cccccc;
margin: 0;
}
header {
margin: 0;
background-color: #cccccc;
height: 5%;
width: 100%;
border-bottom: 2px solid black;
}
.menuitem {
display: inline;
float: right;
vertical-align: top;
margin-right: 2%;
}
#headerimage {
width: 36px;
height: 36px;
margin-left: 3%;
vertical-align: middle;
}
So you need to correct that.
Having a header that is 5% of the height of the page doesn't make a great deal of sense to me, and because the menuitem items are floated right, they don't have any block effect on the header content.
If you gave the header a fixed height that was big enough, e.g. height: 80px; then it would display as you want.
EDIT:
An alternative is to give the menuitems a relative position, then offset the top by the height of the image in the header (it's the only element with a fixed height), and apply the border to the div enclosing the header image (see http://codepen.io/raad/pen/oyncv):
HTML
<header>
<div class="imagecontainer">
<img id="headerimage" src="" />
</div>
<nav id="headernav">
<ul id="list">
<li class="menuitem">
Link2
</li>
<li class="menuitem">
Link1
</li>
</ul>
</nav>
</header>
CSS
html, body {
height: 100%;
background-color: #cccccc;
margin: 0;
}
header {
margin: 0;
background-color: #cccccc;
height: 5%;
width: 100%;
}
.imagecontainer {
border-bottom: 2px solid black;
}
.menuitem {
position: relative;
top: -36px;
display: inline;
float: right;
margin-right: 2%;
}
#headerimage {
width: 36px;
height: 36px;
margin-left: 3%;
vertical-align: middle;
}

Add this to your CSS:
#headernav {
float: right;
}
#headernav ul li {
display: inline;
}
This will float the nav to the right and display your list inline so each bullet is side-by-side.
JSFiddle: http://jsfiddle.net/tsukasadt/puf0ws3x/

Please see the following fiddle: http://jsfiddle.net/nfpzzao7/
<header>
<div class="headerimage-container">
<img id="headerimage" src="" />
</div>
<nav id="headernav">
<ul id="list">
<li class="menuitem">
Link1
</li>
<li class="menuitem">
Link2
</li>
</ul>
</nav>
</header>
html, body {
height: 100%;
background-color: #cccccc;
margin: 0;
}
#header {
border-bottom: 2px solid red;
}
header {
margin: 0;
background-color: #cccccc;
}
height: 5%;
width: 100%;
}
.menuitem {
display: inline;
float: right;
vertical-align: top;
margin-right: 2%;
}
#headerimage {
width: 36px;
height: 36px;
margin-left: 3%;
vertical-align: middle;
}
.headerimage-container {
display: inline-block;
}
#headernav {
display: inline-block;
}
#headernav li {
float: left;
margin-right: 10px;
}

Related

Way to remove space between nav-bar and drop down menu

I'm very new to coding and am working on a fictitious website for a restaurant. I can't seem to figure out how to remove the gap between my drop down menu and top navigation bar under the menu section. Ideally I would like the pink drop down box to be directly under the black nav bar. Any suggestions on what I have done wrong? I've played around with margins and padding everywhere. Even did a margin 0 and padding 0 at the start of my CSS page to see if that wold have an effect, it didn't.
Attached is my code for HMTL and CSS
body {
background-color: #41393d;
}
/* Header */
.header {
width: 100%;
height: 50px;
display: block;
background-color: black;
}
.header_content {
width: 100%;
height: 100%;
display: block;
margin: 0 auto;
background-color: black;
}
.logo_container {
height: 100%;
display: table;
float: left;
}
.logo {
height: 100%;
display: table-cell;
vertical-align: middle;
} /* Navigation */
.navigation {
float: right;
height: 100%;
} .navigation li {
float: left;
height: 100%;
display: table-cell;
padding: 0px 20px;
position: relative;
}
a:hover {
color: #8a8c8f !important;
} .navigation li a {
display: inline-block;
vertical-align: middle;
height: 100%;
color:#BE1E2D;
font-family: athelas,
serif; font-style:normal;
text-decoration: none;
} .sub_menu1 {
display: none;
}
.navigation li:hover .sub_menu1 {
display: block;
position: absolute;
background: #d4a18d;
} .navigation li:hover .sub_menu1 ul {
display: inline-block;
margin: 0%;
padding: 0%;
text-align: center;
}
.navigation li:hover .sub_menu1 ul li {
padding: 5px;
}
<!DOCTYPE html>
TOWN_Restaurant` <header>
<div class="header">
<div class="header_content">
<div class="logo_container">
<img alt="TOWN logo" id="image" class="logo" src="images/town_logo.png">
</div>`
<ul class="navigation">
<li>Home</li>
<li>Our Story</li>
<li>Menu
<div class="sub_menu1">
<ul>
<li>Cuisine</li>
<li>Beverages</li>
</ul>
</div>
</li>
<li>Contact</li>
<li>Reservations</li>
</ul>
</div>
</div>
</header>
The problem is that your nav <ul> has a margin of 16px for top and bottom while the height is 100% of the parent's height which is 50px so the total height of the <ul> is:
50px (parent's height) + 16px (margin-top) + 16px (margin-bottom) = 82px
and this is making it get out of the header which has a fixed height of 50px.
To get this fixed, you have to
1st: set your nav <ul>'s margin to 0 and use padding-top on the <li>s instead with their box-sizing value set to border box so that padding doesn't affect the height of the <li>s.
2nd: set the top of your "sub_menu1" to 100% (which is 50px in this case [the parent's height]) and this will get the the dropdown menu right beneath your navigation.
and here it is working:
body {
background-color: #41393d;
}
/* Header */
.header {
width: 100%;
height: 50px;
display: block;
background-color: black;
}
.header_content {
width: 100%;
height: 100%;
display: block;
margin: 0 auto;
background-color: black;
}
.logo_container {
height: 100%;
display: table;
float: left;
}
.logo {
height: 100%;
display: table-cell;
vertical-align: middle;
}
/* Navigation */
.navigation {
float: right;
height: 100%;
margin: 0;
}
.navigation li {
float: left;
height: 100%;
display: table-cell;
padding: 15px 20px;
position: relative;
box-sizing: border-box;
}
a:hover {
color: #8a8c8f !important;
}
.navigation li a {
display: inline-block;
vertical-align: middle;
height: 100%;
color: #BE1E2D;
font-family: athelas, serif;
font-style: normal;
text-decoration: none;
}
.sub_menu1 {
display: none;
}
.navigation li:hover .sub_menu1 {
display: block;
position: absolute;
background: #d4a18d;
top: 100%;
}
.navigation li:hover .sub_menu1 ul {
display: inline-block;
margin: 0%;
padding: 0%;
text-align: center;
}
.navigation li:hover .sub_menu1 ul li {
padding: 5px;
}
TOWN_Restaurant`
<header>
<div class="header">
<div class="header_content">
<div class="logo_container">
<img alt="TOWN logo" id="image" class="logo" src="images/town_logo.png">
</div>`
<ul class="navigation">
<li>Home</li>
<li>Our Story</li>
<li>Menu
<div class="sub_menu1">
<ul>
<li>Cuisine</li>
<li>Beverages</li>
</ul>
</div>
</li>
<li>Contact</li>
<li>Reservations</li>
</ul>
</div>
</div>
</header>

keep space between div's

I want show a html div wich contains a state-descritpiton with a circle (green or red). This circle shows the state of the enigne in the right corner of the description.
My problem is the following. If the windows size has changed (smaler), the description and the "state-circle" overlap each other.
How can i prevent this?
Do you know how the css-code should be?
structure is mainly this:
.statusdiv{
height: 40px;
}
.statusbeschreibung{
position: absolute;
margin-left: 40%;
}
.statuskreis {
position: absolute;
width: 25px;
height: 25px;
top: 13px;
/*left: 190px;*/
margin-left: 60%;
border: 1px solid black;
text-align: center;
border-radius: 12.5px;
}
.status-on{
background-color: green;
}
.status-off{
background-color: red;
}
<div class="list-block">
<ul>
<li>
<div class="statusdiv">
<p class="statusbeschreibung">Motorstatus</p>
<div name="motorstatus" id="motorstatus" class="item-link statuskreis status-off"></div>
</div>
</li>
</div>
This was based on your original screenshot images of your code: basically you should use display:inline-block instead of position:absolute to prevent your bullet from overlapping your text, and then use a margin-left on the bullet so that it always has enough space between it and the text.
.list-block ul {
padding: 0;
margin: 0;
}
.list-block li {
list-style: none;
}
.statusdiv {
white-space: nowrap;
}
.statusbeschreibung {
margin-left: 40%;
display: inline-block;
vertical-align: middle;
}
.statuskreis {
width: 25px;
height: 25px;
margin-left: 10px;
border: 1px solid black;
text-align: center;
border-radius: 12.5px;
display: inline-block;
vertical-align: middle;
}
.status-on {
background-color: green;
}
.status-off {
background-color: red;
}
<div class="list-block">
<ul>
<li>
<div class="statusdiv">
<p class="statusbeschreibung">Motorstatus</p>
<div name="motorstatus" id="motorstatus" class="item-link statuskreis status-off"></div>
</div>
</li>
<li>
<div class="statusdiv">
<p class="statusbeschreibung">Motorstatus</p>
<div name="motorstatus" id="motorstatus" class="item-link statuskreis status-on"></div>
</div>
</li>
</ul>
</div>
If I'm understanding it correctly, you style the circle with the class "motortatus".
Try to set the width and height in percentages, not in pixels. This should resize the status circle and prevent it from overlapping with the description, except the font of the description doensn't resize at all and fills up the whole div.
I love inline lists for this sort of thing, but you can also do columns in your preferred css framework of choice.
I've styled it so each of the two list items is 50% of the width of the ul container, but you can tweak those as you see fit.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.statusdiv {
list-style: none;
float: left;
margin: 0;
padding: 1em;
width: 100%;
color: #2d2d2d;
}
.statusdiv li {
width: 50%;
float: left;
padding: 0 1em;
}
.statusdiv li:first-child {
text-align: right;
height: 35px;
line-height: 35px;
}
.statusdiv li:last-child {
text-align: left;
}
.circle {
content: "";
background-color: aqua;
width: 35px;
height: 35px;
display: inline-block;
-webkit-border-radius: 100%;
-moz-border-radius: 100%;
border-radius: 100%;
}
<!-- EDIT THIS SNIPPET -->
<ul class="statusdiv">
<li>
Status thing:
</li>
<li><span class="circle"></span></li>
</ul>

Inline-block divs not aligning horizontally

I have a project where I need to align certain elements just so. For whatever reason, it's not working. My HTML:
<div class="heading">
<h1>Exotic <strong>Travel</strong></h1>
<div class="left">
<ul>
<li>homepage</li>
<br>
<li>about us</li>
<br>
<li>destinations</li>
<br>
<li>book a ticket</li>
<br>
<li>contact us</li>
</ul>
</div>
<div class="rightimg">
<img src="banner.jpg" alt="Beachside Hotel" />
</div>
<div class="righttext">
<h2>The Perfect Destination</h2>
</div>
</div>
and the CSS:
body {
background-image: url(sky.jpg);
font-family: "Verdana", sans serif;
}
h1 {
font-family: "Calibri Light", sans serif;
color: gray;
}
h2 {
background-color: green;
display: inline-block;
border: 0;
margin: 0;
text-align: center;
width: 750px;
}
a {
color: white;
margin: 4px;
padding: 5px 0 5px 0;
text-decoration: none;
}
.left{
background-color: red;
display: inline-block;
float: left;
height: 200px;
width: 350px;
}
.heading {
background-color: white;
margin: 0 auto;
overflow: auto;
width: 1000px;
}
.righttext {
display: inline-block;
float: right;
height: 60px;
width: 750px;
}
.rightimg {
display: inline-block;
float: right;
margin: 0;
padding: 0;
width: 750px;
}
This SHOULD be working, based on other similar examples I've seen on the site, but it's not taking. Any help here would be appreciated.
I think you are breaking it with your fixed widths, I used 40% width on the left and righttext and that seemed to get everything inline:
.left{
background-color: red;
display: inline-block;
float: left;
height: 200px;
width: 40%;
}
.righttext {
display: inline-block;
float: right;
height: 60px;
width: 40%;
}
https://jsfiddle.net/bkyLojx4/
Also as an fyi br tags are not valid in a ul. Rather use css to handle the styling of the list.
It is because you have the elements at a fixed width which means the combined width of all 3 elements is more than the space available. Try using a percentile widths for adaptive design or adjusting it to the resolution you want to support.

Centering a div container which is next to a second div container?

I've a div container which is named headline. In this div there are two elements, a menu bar of type unordered list and a div container. I'll centering horizontally the menu bar, the other div container should dock on the right display side with a margin of 5%. How I can do this, has someone an idea?
Okay here is my litte example from jsfiddle: http://jsfiddle.net/nchm3gyj/
HTML
<div class="headline">
<ul class="navbar">
<li>Home</li>
<li>Team</li>
<li>Info</li>
<li>Downloads</li>
</ul>
<img class="facebook" src="" />
</div>
CSS
* {
margin: 0px;
padding: 0px;
}
.headline {
height: 60px;
width: 100%;
background-color: black;
margin-top: 10px;
}
.headline .navbar{
margin: 0px;
padding: 0px;
padding-left: 10px;
padding-right: 10px;
float: left;
height: 60px;
width: auto;
background-color: yellow;
list-style: none;
}
.headline .navbar li{
display: inline;
}
.headline .navbar li a {
text-decoration: none;
line-height: 60px;
padding-left: 10px;
padding-right: 10px;
}
.headline .facebook {
width: 60px;
height: 60px;
margin-right: 5%;
float: right;
}
#clear {
clear: both;
}
If you want your navigation bar centered in the parent block, here is one way of doing it.
Apply display: inline-block to the .navbar and text-align: center to .headline.
Assuming that you want the navigation bar centered with respect to the full
width of the parent block, you need to take the image out of the content flow.
You can do this by applying position: absolute to the .facebook element.
.headline {
height: 60px;
width: 100%;
background-color: black;
margin-top: 10px;
text-align: center;
position: relative;
}
.headline .navbar{
margin: 0px;
padding: 0px;
padding-left: 10px;
padding-right: 10px;
height: 60px;
width: auto;
display: inline-block;
background-color: yellow;
list-style: none;
}
.headline .navbar li{
display: inline;
}
.headline .navbar li a {
text-decoration: none;
line-height: 60px;
padding-left: 10px;
padding-right: 10px;
}
.headline .facebook {
position: absolute;
top: 0;
right: 5%;
width: 60px;
height: 60px;
}
<div class="headline">
<ul class="navbar">
<li>Home</li>
<li>Team</li>
<li>Info</li>
<li>Downloads</li>
</ul>
<img class="facebook" src="http://placehold.it/60x60" />
</div>
I think you might need to position: absolute the facebook image and display: inline-block your menu bar (being centered by the .headline):
http://jsfiddle.net/nchm3gyj/32/
I'm a bit unsure of what you're trying to do, is this it? Applied text-align: center to .headline and display: inline-block to .navbar then position: absolute to .facebook?
http://jsfiddle.net/nchm3gyj/42/

Is it possible to make a href with bigger bottom padding for an arrow

I want to make top menu with arrow image on hover, that will display on border line of the next div.
My fast made fiddle:
and an image of what I want to do
HTML
<div class="wrapper">
<img src="" alt="" id="logo" />
<ul id="topmenu">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</div>
<div class="full-width-page">
<div class="wrapper">
<div id="header-image">
image with content goes here
</div>
</div>
</div>
CSS
.wrapper {
width: 800px;
margin-left: auto;
margin-right: auto;
}
.full-width-page {
width: 100%;
border-top: 1px solid #000;
border-bottom: 1px solid #000;
overflow: hidden;
}
#logo {
float: left;
width: 200px;
height: 30px;
background-color: gray;
margin-top: 15px;
}
#topmenu {
float: right;
display: block;
list-style: none;
margin: 0px;
padding: 20px;
}
#topmenu li {
display: inline-block;
padding-bottom: 20px;
}
#topmenu li a:hover {
background-image: url(http://www.ristatebassmasters.com/images/smallDownArrow.gif);
background-repeat: no-repeat;
background-position: center 8px;
}
#header-image {
height: 200px;
line-height: 200px;
}
I know that there is a solution to create the menu to be position: absolute. And then making padding-bottom on href will push the arrow down further, but when the menu will be positioned absolute I will not be able to push it using float: right.
Here's an updated fiddle of what you want.
CSS
#topmenu {
display: block;
list-style: none;
margin: 0px;
padding: 20px;
position: absolute;
right: 0;
top: 0;
}
#topmenu li {
display: inline-block;
padding-bottom: 20px;
}
#topmenu li a{
padding-bottom: 30px;
}
#topmenu li a:hover {
background-image: url(http://www.ristatebassmasters.com/images/smallDownArrow.gif);
background-repeat: no-repeat;
background-position: center 32px;
}
#header-image {
height: 200px;
line-height: 200px;
}
I've added padding-bottom to you <a> elements from menu and it works like here
Check and write if it's ok for You :)