Center align Logo and align UL horizontally around it - html

I am trying to capture a layout that I have seen a few different places. The layout has a fixed header with an image centered, and then a horizontal UL that is split around the logo. Attached is the image that I feel represents this.
I need a suggestion to achieve splitting the UL around logo. Right now the UL is always under and not split.
http://jsfiddle.net/jgac8/1/
Here is some markup that I have been attempting:
HTML
<header>
<h1 id="logo"></h1>
<nav>
<ul>
<li>about</li>
<li>services</li>
<li>location</li>
<li>contact</li>
</ul>
</nav>
</header>
CSS
header {
width: 100%;
height: 150px;
text-align:center;
position: fixed;
top: 0;
left: 0;
background:#FF7D0D;
border-bottom: 1px solid #CCC;
z-index:100;
}
#logo {
display: inline-block;
padding:5px 0 0 0;
width: 80px;
height: 150px;
background: url(../img/PP_Logo_Vert_White.png) center no-repeat;
}
nav {
padding: 0px;
margin: 0px;
font-size:16px;
font-weight: 100;
clear:left;
}
nav ul {
padding: 0px;
margin: 0px;
list-style: none;
}
nav li {
display: inline-block;
padding: 0 50px;
}

You might have to do a bit of tweaking but I believe it is what you want.
HTML
<header>
<h1 id="logo"></h1>
<nav id="left">
<a href="#" ></a>
<ul>
<li>about</li>
<li>services</li>
</ul>
</nav>
<nav id="right">
<a href="#" ></a>
<ul>
<li>about</li>
<li>services</li>
</ul>
</nav>
</header>
CSS
header {
width: 100%;
height: 150px;
text-align:center;
position: fixed;
top: 0;
left: 0;
background:#FF7D0D;
border-bottom: 1px solid #CCC;
z-index:100;
}
#logo {
display: inline-block;
padding:5px 0 0 0;
width: 80px;
height: 150px;
background: url(http://findicons.com/files/icons/2141/web_design_creatives/128/small_smile.png) center no-repeat;
}
#left{position:absolute; left:10%; top:5px; list-style:none}
#right{position:absolute; right:10%; top:5px; list-style:none}
li{list-style:none}

There are many ways to go about this. Depending on how dynamic your site will be. If you are creating it with static html and css I would simply create a container, put three divs inside the container splitting it up how you want. In the first and third div create two separate menus. In the center put the logo. Something like the code below. At a certain width you can create some css media queries to bring it down and make it one navigation.
The very basic idea:
Example of html:
<div class="container">
<div class="left-nav">
</div>
<div class="logo">
</div>
<div class="right-nav">
</div>
</div>
Example CSS:
.container {
float: left;
width: 100%;
margin: 0;
padding: 0;
}
.left-nav {
float: left;
width: 400px;
}
.right-nav {
float: left;
width: 400px;
}
.logo {
float: left;
width: 200px;
}

Related

How can I stop the right floated nav content from overflowing when the window is resized

Trying to set up a simple 'cheat sheet' of logo and nav bar that I can reuse. I'm having trouble preventing the right floated nav from overflowing into content below.
NB. I'm new to this so I have added borders to all elements to help me see what's happening.
I have tried to add a clear:left (even though I know it should be clear:right as the content has been floated right) to the element proceeding the navigation but that did not work of course!
*{
box-sizing: border-box;
}
header{
display: inline-block;
}
.logo{
background-image: url("logo.png");
background-repeat:no-repeat;
width: 140px;
height: 81px;
margin: 10px;
display: inline-block;
}
nav{
border: 1px solid black;
float: right;
width: auto;
}
ul{
list-style: none;
padding-left: 0;
border: 1px solid red;
vertical-align: middle;
}
li{
display: inline-block;
width: auto;
padding: 20px;
background-color: yellow;
margin-bottom: 5px;
border: 1px solid yellow;
}
.divider{
clear: both;
}
<header>
<div class="logo"></div>
<nav>
<ul>
<li>About</li>
<li>Portfolio</li>
<li>Shopping</li>
<li>Contact Me</li>
</ul>
</nav>
</header>
<div class="divider"></div>
<main>
<h1>The display Property</h1>
So next I tried clear:both and that did not work.
I have also tried to set the nav to display:inline-block but that did not work.
Ideally I would like to solve this without using any pre-provided templates and my just raw code or display:flex.
Thanks in advance :)
Hope this helps.
.nav_bar {
margin: 10px;
padding: 10px;
background-color: #00021a;
color: white;
}
.logo {
display: inline-block;
vertical-align: middle;
width: 7%;
}
.logo img {
height: auto;
width: 50px;
}
.nav {
display: inline-block;
vertical-align: middle;
width: 90%;
}
.nav_container li {
list-style: none;
float: right;
padding: 10px;
}
<head>
<link rel="stylesheet" href="styles.css">
</head>
<div class="nav_bar">
<div class="nav_container">
<div class="logo">
<img class="logo"
src="https://t4.ftcdn.net/jpg/00/71/26/83/240_F_71268376_KIbJvY0SYwlvikWpahjNCv5IBfukykG9.jpg"/>
</div>
<nav class="nav">
<ul>
<li>About</li>
<li>Portfolio</li>
<li>Shopping</li>
<li>Contact Me</li>
</ul>
</nav>
</div>
</div>
Here's the Fiddle

navbar width exceeds viewport of webpage

hello guys i want to display html content in with margin on the sides with 50px &50px .
here is the problem my nav bar witdh is et to 100% then it elongates to right end but correctly positioned on left
i have given the image below:like this
i show the html& css
css:
<style>
.top{
width:100%;
height:300px;
color:#ccc;
font-size: 40px;
text-align: center;
background-color: forestgreen;
}
.align{
height:100%;
margin-left: 50px;
margin-right: 50px;
background-color: darkgray;
}
ul{
position: absolute;
width:100%;
list-style-type: none;
overflow: hidden;
background-color: black;
color: azure;
float:left;
padding: 0;
}
nav{
position: inherit;
}
li{
text-decoration: none;
padding: 14px 16px;
display: block;
float: left;
margin: none;
text-align: center;
}
li.active{
background-color: darkred;
}
.navbar-fixed {
top: 0;
z-index: 100;
position: fixed;
width: 100%;
}
</style>
HTML:
<body class="bg-danger">
<div class="align bg-success" >
<div id=image-header class=top>
NO:1 Hosting Site
</div>
<nav >
<ul>
<a href="index.php"><li class="active">
Home
</li></a>
<a href="login.php"><li>
Login
</li></a>
<a href="registration.php"><li>
Register
</li></a>
<a href="account.php"><li >
Profile
</li></a>
</ul>
</nav>
</div>
</body>
i want it to fix it like this (i used 92.5% in width)with 100% width this is just model like affix in bootstrap
and want to know why it cant be fixed with 100% in div element
image
You can use width: calc(100% - 100px); on that navbar to get the correct width.

Center logo and nav links vertically in header

I have just started my website, and I am currently working on the header/navigation bar. I've got it looking how I want, however the one thing I can't figure out, is how to centre the logo and hyperlinks vertically in the header?
Here is my HTML:
<body>
<div class="header">
<div class="container">
<div class="logo">
<h1><img src="logo.png"></h1>
</div>
<div class="nav">
<ul>
<li>ABOUT ME</li>
<li>PROJECTS</li>
<li>CONTACT</li>
</ul>
</div>
</div>
</div>
<div class="content">
<p>
</p>
</div>
</body>
And CSS:
body {
font-family: 'Nunito', sans-serif;
width: 100%;
margin: auto;
background: #F4F4F4;
}
a {
text-decoration: none;
color: #fff;
}
img {
max-width: 100%;
}
/**********************************
HEADING/NAVIGATION
***********************************/
li {
list-style: none;
float: left;
margin-left: 25px;
padding-top: 10px;
}
.container {
width: 960px;
margin: 0 auto;
}
.header {
background: #5BBB9B;
width: 100%;
height: 200px;
top: 0;
position: fixed;
border-bottom: 1px solid black;
}
.logo {
float: left;
}
.nav {
float: right;
}
I have tried using vertical-alignment: middle;, however this didn't work.
Anyone have any suggestions?
Use
display:table;
height:100%;
for the parent and
display: table-cell;
text-align: center;
vertical-align: middle;
and check out this awesome article:
https://css-tricks.com/centering-in-the-unknown/

I need to position my navbar within a div

I've tried everything from text-align to setting margins. I want the nav bar to be centered horizontally and at the bottom of the div vertically.
html: http://www.joekellywebdesign.com/businesssample/index.html
<div id="navbar">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a class="MenuBarItemSubmenu" href="projects.html">Projects</a>
<ul>
<li>Restaurant</li>
<li>House</li>
<li>Mall</li>
</ul>
</li>
<li>About</li>
<li><a class="MenuBarItemSubmenu" href="services.html">Services</a>
<ul>
<li><a class="MenuBarItemSubmenu" href="residential.html">Residential</a>
<ul>
<li>Housing</li>
<li>Storage</li>
</ul>
</li>
<li>Business</li>
<li>Government</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
css: http://www.joekellywebdesign.com/businesssample/css/styles.css
/* CSS Document */
* {
margin:0px;
padding:0px;
}
body {
background-color:#FF0;
}
#wrapper {
width:900px;
margin:10px auto;
background-color:#FFF;
}
#logo {
float:left;
width:200px;
background-color:#FFF;
}
#navbar {
float:right;
text-align:center;
width:700px;
margin: auto;
background-color:#FFF;
}
You could do something like this:
<style type="text/css">
div#container {
position:relative;
width: 500px;
height: 300px;
border: 1px solid black;
}
div#menu-container {
position: absolute;
bottom: 0;
width: 100%;
}
div#menu {
position: relative;
text-align: center;
}
</style>
<div id="container">
<div id="menu-container">
<div id="menu">
Hello World!
</div>
</div>
</div>
Check out this jsFiddle for a demonstration.
Using an absolute position would easily get it to the bottom:
You'd apply this to the #navbar: position: absolute; bottom: 0px;
Then you'd apply this to the parent: position: relative;
However, now that you've applied an absolute position, you should use a similar technique to center it horizontally. Since your navbar is 700px, we can use some math to center it using the same absolute position.
You'd apply this to the #navbar: left: 50%; margin-left: -350px;
Working example: http://jsfiddle.net/ky9av/
You can try this.
ul.MenuBarHorizontal {
margin-top: 8%;
float: right;
}
You can try with this,
ul.MenuBarHorizontal {
cursor: default;
font-size: 100%;
list-style-type: none;
margin: auto;
padding: 0;
width: 512px;
}
Secondly, as per your design, the navbar ends exactly where you ul ends,
so you might try this
#navbar {
background-color: #FFFFFF;
float: right;
margin: auto;
margin-top: 49px;
text-align: center;
width: 700px;
}

Building a fluid horizontal navigation

I'm trying to build a horizontal navigation using %'s, and I cant seem to figure out whats going on. I have it all set up how I want it, but whenever I specify a size to the A or LI nothing changes, and therefore, I can only see a silver of my background image.
<div id=mainwrap>
<div id=header>
<div id = title>
<img src="images/hangaquilt.png" width="483" height="78" alt="Hang A Quilt">
</div>
<div id = cartstatus>
<p> Your Cart Is Empty </p>
</div>
<div id=nav>
<ul>
<li>Home</li>
<li>Products</li>
<li>Contact Us</li>
<li>View Cart</li>
<li>Dealers</li>
</ul>
</div>
</div>
<div id=bodycontent>
<div id=sidebar>
</div>
<div id=bodytext>
</div>
</div>
<div id=slideshow>
</div>
<div id=footer>
</div>
</div>
and the CSS
body {
background-color: rgb(238,225,185);
}
#mainwrap {
margin: 0 auto;
height: 700px;
width: 75%;
max-width:1024px;
min-width:800px;
}
#header {
margin: 0 auto;
margin-top: 3%;
width: 100%;
height: 25%;
}
#header img{
margin-left: 3.3%;
}
#title {
float:left;
width: 55%;
}
#cartstatus{
float: right;
width: 45%;
}
#cartstatus p{
margin-right: 7.1%;
float: right;
}
#nav{
clear: both;
width: 100%;
height: 33%;
font-family:"Rockwell Extra Bold",Trebuchet MS, Arial, Helvetica, sans-serif;
}
#nav ul {
height: 100%;
list-style-type: none;
text-align: center;
}
#nav li{
padding: 0;
width: 20%;
height: 100%;
font-size:18px;
display:inline;
}
#nav ul li a{
background-image: url(../images/navbg.png);
width: 19%;
height: 98%;
color: black;
text-decoration: none;
}
I've done navigation likes this before, and have never had this problem. It's really frustrating as I know it's something really simple that I'm missing.
If you define element as "inline", you can't change it's width or height.
Instead of
display:inline;
try
display:inline-block;
Here is what you want: http://jsfiddle.net/JmTKb/