I'm currently making my web page responsive. I'm struggling with the nav bar, and don't have an idea on where to start to make it mobile friendly. This is what my nav bar looks like:
HTML:
<head>
<link href="https://fonts.googleapis.com/css?family=Gilda+Display|Montez|Sacramento" rel="stylesheet">
</head>
<nav>
<div class="navcontainer">
<ul>
<li class="right">Shop</li>
<li class="right">Login</li>
<li><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></li>
<li class="right">Contact us</li>
<li class="right">Blog</li>
</ul>
</div>
</nav>
<div class="clearfix"></div>
CSS:
html, body {
margin: auto;
padding: 0px;
}
.container{
margin: 0 auto;
width: 85%;
}
.clearfix{
clear:both;
}
/*******************************/
/*********************HEADER*******************/
nav {
text-align: center;
width: 100%;
background-color: white;
border:2px solid black;
}
nav ul {
padding: 0;
margin:0;
}
nav li {
color: black;
display: inline-block;
font-size: 30px;
font-weight: 300;
font-family: 'Sacramento', cursive;
vertical-align: middle;
margin: 16px 20px;
}
li a{
text-decoration: none;
color: black;
}
.logo{
height:100px;
}
Here is the codepen code to my nav bar:
https://codepen.io/teenicarus/pen/vZWJxX
This is how I would like it to look like on mobile:
Where do I go from here to create a similar result?
I appreciate all responses.
You need to use #media query to override the css based on screen size... working example as below
html, body {
margin: auto;
padding: 0px;
}
.container{
margin: 0 auto;
width: 85%;
}
.clearfix{
clear:both;
}
/*******************************/
/*********************HEADER*******************/
nav {
text-align: center;
width: 100%;
background-color: white;
border:2px solid black;
}
nav ul {
padding: 0;
margin:0;
}
nav li {
color: black;
display: inline-block;
font-size: 30px;
font-weight: 300;
font-family: 'Sacramento', cursive;
vertical-align: middle;
margin: 16px 20px;
}
li a{
text-decoration: none;
color: black;
}
.logo{
height:100px;
}
.small-screen{display:none;}
#media screen and (max-width: 768px) {
nav li {display:block}
.small-screen{display:block;}
.large-screen{display:none;}
}
<head>
<link href="https://fonts.googleapis.com/css?family=Gilda+Display|Montez|Sacramento" rel="stylesheet">
</head>
<nav>
<div class="navcontainer">
<ul>
<li class="small-screen"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></li>
<li class="right">Shop</li>
<li class="right">Login</li>
<li class="large-screen"><img class="logo" src="http://rubyfearless.com/wp-content/uploads/2012/08/style-insider-logo221.jpeg"></li>
<li class="right">Contact us</li>
<li class="right">Blog</li>
</ul>
</div>
</nav>
<div class="clearfix"></div>
For making responsive website, rather than starting from scratch use available frameworks such as Bootstrap.
Bootstrap provides a ready made collapsible navbar, that automatically collapses your navbar for mobile screens and displays a "humburger-icon" toggle drop down menu like you want. The official documentation can be found here : Bootstrap Nav-Bar.
You can also find a working example and a bit more explanation on how to implement bootstrap navigation bars, here: W3Schools Bootstrap Nav-Bar.
To actually implement it in your codepen is a bit of work, and but it is not hard. I think it would do you good to actually implement it yourself. If you have any particular issues while implementing it you can always come back to Stack Overflow. So good luck.
Here are some additional links that may be helpful :
How to add hamburger menu in bootstrap
Bootstrap NavBar with left, center and right aligned items
i've been trying for 2 hours to align the navigation bar nicely under the header image, but it just won't do it.The first 4 list items align in a row, but the last one goes under them, + the nav bar is not centered like i want it to be. I have searched for answers everywhere, and nothing works. Help will be greatly appreciated.
p.s. i am new to css and html so be gentle.
<html>
<head>
<style>
body {
background-image: url("http://i.imgur.com/SwKXk23.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
body {
margin: 0;
}
.header {
width: 100%;
height: auto;
background-color: none;
padding-top: 24px;
}
.headerContent {
width: 1024px;
height: auto;
margin: 0 auto;
}
.headerContent a img {
width: 659px;
height: 144px;
margin: 0px auto;
display: block;
}
.nav {
width:750px;
margin:0 auto;
list-style:none;
}
.nav li {
float:left;
}
.nav a {
display:block;
text-align:center;
width:150px; /* fixed width */
text-decoration:none;
}
.nav ul li{
height: 40 px;
background: #A14F53;
}
.nav ul li{
list-style-type: none;
width: 150px;
float: left;
}
.nav ul li a{
text-decoration: none;
color: black;
line-height: 40px;
display: block;
border-right: 1px solid #CCC;
text-align:center;
}
.nav ul li a:hover{
background-color:#F9C1B5;
}
.headerBreak{
width: 100%;
height: o%;
border bottom: 2px solid #128e75;
}
</style>
</head>
<body>
<div class="background">
<div class="header">
<div class="headerContent">
<a href="#">
<img style="border:0;width:900px;height:250px;" alt=""
title="" src="http://i.imgur.com/5NhCbxu.png">
</a>
</div>
<div class="nav">
<ul id="nav">
<li>Pagina principala</li>
<li>Despre noi</li>
<li>Clientii nostri</li>
<li>Produse</li>
<li>Contacte</li>
</ul>
</div>
</div>
<div class="headerBreak"></div>
</div>
</body>
</html>
You haven't given the nav bar enough width. Change the .nav rule:
.nav {
width:750px; <------- adjust this
margin:0 auto;
list-style:none;
}
I changed your width to 800px instead of 750px and now the menu fits on one line and is centred.
Here's a fiddle: https://jsfiddle.net/macg14fs/
Your .nav is too narrow for the content so it has wrapped. Press F12 on your browser to discover the interactive debug tools. After that, invest some time in learning about bootstrap.
With a Fiddle it would be much easier to know whats the problem, but try this:
#nav {
width: 100%;
}
#nav > li {
display: inline-block;
margin: 5px 5px 5px 5px;
text-align: center;
}
I have a top nav bar set to a fixed position, and I have a article element set to window height. When I set the article element to relative, the navbar is no longer shown.
How can I have the article be window height and the nav bar just kinda rest over it.
Here is my code.
<article id="navWrap">
<nav>
<ul>
<li>Home</li>
<li>My Work</li>
<li>Contact</li>
</ul>
</nav>
</article>
<article id="headWrap" class="head clearIt">
<header>
<p class="headpar">Hello I'm</p>
<h1 class="headText">Sebastian</h1>
<p class="headinfo">Web Developer | Corona SDK Developer | PHP Junkie</p>
</header>
</article>
And the CSS
#navWrap{
height: 100px;
width: 100%;
position: fixed;
}
nav{
width: 300px;
padding-top: 39px;
float: right;
}
nav ul{
list-style: none;
margin: 0px;
padding: 0px;
}
nav ul li{
display: inline;
margin-right: 30px;
}
nav ul li a{
text-decoration: none;
font-family: 'Open Sans', sans-serif;
padding: 0px 0px 5px 0px;
margin: 0px;
color: #fff;
}
nav ul li a:hover{
border-bottom: 1px solid #fff;
}
/*Used to clear floats*/
.clearIt{
clear: both;
}
#headWrap{
width: 100%;
height: 100px;
background-color: #2980b9;
position: relative;
}
And the JS to make the article window height
<script type="text/javascript">
$("#headWrap").height($(window).height());
</script>
Add top:100px; to your existing css for #headWrap to push it down below #navWrap
#headWrap{
top:100px;
}
Once you do that, you can't see the white text on the white background. So add background:#eee; to your existing css for #navWrap.
#navWrap{
background:#eee;
}
I ended up setting the z-index for the nav element to 2.
And the rest of the elements I set to 1.
The issue has now been fixed! Thanks to #seva.rubbo ! Here's the updated code in JSFiddle
I have created a layout which contains 1 div with a fixed width width: 900px;. and I have centered this div so in that I have 2 blank spaces on either side. What I want to do is add a navigation bar inside this div at the top and have its width fill up the width of the div. Here's my navigation html and css code;
<div id="content">
<nav>
<ul class="nav">
<li>Home</li>
<li>Categories</li>
<li>News</li>
<li>Members</li>
<li>Media</li>
</ul>
</nav>
</div>
The CSS for Navigation;
.nav{
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
text-align:center;
}
.nav li{
display:inline;
}
.nav a{
display:inline-block;
padding:20px;
background-color: #AEAEAE;
width: 15%;
text-decoration: none;
text-transform: uppercase;
}
.nav a:hover {
background-color: #fff;
}
The Div CSS;
div#content {
width: 900px;
margin-left: auto;
margin-right: auto;
background-color: #fff;
height: 1200px;
}
JSFiddle Link
All help would be greatly appreciated. I hope I've explained my problem well enough, I would post images but I have not got enough reputation. Thank you.
.nav li{
float: left;
width: 20%;
}
And remove width: 15% from .nav a
I can't seem to remove this bit of space at the top of my page, I've tried a number of things and read around. The only thing that seems to work is *{margin:0}, but I don't really want to do that. Anyone have some insight on what the problem is here?
You can view the page in question here: http://www.ryanlaurence.com/new/
HTML
<!DOCTYPE html>
<html>
<head>
<link href="Style.css" rel="stylesheet">
</head>
<body>
<div id = "Banner">
<p>Banner</p>
</div>
<div id = "Nav">
<div id="stripe"></div>
<ul>
<li> Link - </li>
<li> Link - </li>
<li> Link - </li>
<li> Link </li>
</ul>
</div>
<div class="Content">
<div></div>
</div>
<div id="Footer">
</div>
</body>
</html>
CSS
body, html{
background-color: #404040;
margin: 0;
padding: 0;
}
#Banner{
background-color: #333333;
height:200px;
top:0px;
}
#stripe{
height: 10px;
top: -14px;
position:relative;
background-color: #262626
}
#Nav{
width:100%;
height: 60px;
background-color: #262626;
}
#Nav ul{
margin: 0;
color: gray;
position: relative;
text-align: center;
}
#Nav ul li{
display: inline;
}
#Nav ul a{
color: gray;
text-decoration: none;
padding-right: 10px;
padding-left: 10px;
font-size: 25px;
font-family: "Orator Std", verdana;
text-align: center;
}
#Nav ul li a:hover{
color: white;
}
.Content{
background-color: #333333;
/*height: 800px;*/
position: relative;
top: 5px;
}
.Content div{
height:800px;
}
#Footer{
background-color:#57B4CC;
height:150px;
}
Add the CSS:
#Banner p {margin:0}
The paragraph in your banner div has a default margin that you want to get rid of.
I tried to give margin-top: -7px. It worked. But not sure why its has some space over there.
Some elements and browsers has some default styles that you need to overwrite to meet your needs.
I suggest you to use CSS reset script by Eric Meyer.
This is not only fix your problem but also help you to prevent and save a lot of time from dealing with cross browser compatibility problems in the future.
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video {
border:0;
font-size:100%;
font:inherit;
vertical-align:baseline;
margin:0;
padding:0
}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
display:block
}
body {
line-height:1
}
ol,ul {
list-style:none
}
blockquote,q {
quotes:none
}
blockquote:before,blockquote:after,q:before,q:after {
content:none
}
table {
border-collapse:collapse;
border-spacing: 0
}
Fiddle Demo