I am trying to create a responsive centered logo header with side navigation. because I want it to be responsive there are no fixed widths which makes it difficult to accomplish the centering (margin:auto). As the window becomes smaller I would like the li tags to sit on top of each other. I do not want to float left and float right the side navigations because I want them to be be attached to the sides of the logo not the sides of the window, with the same amount of space between logo and menu on left and right.
html:
<div id="header">
<div id="nav">
<div id="nav-inner">
<ul id="site_nav_1">
<li id="menu-item">
The Problem
</li>
<li id="menu-item">
Why Sanitize
</li>
</ul>
<div id="logo-nav">
<div id="logo"></div>
</div>
<ul id="site_nav_2">
<li id="menu-item">
About Us
<li id="menu-item">
Sanitize Now!
</li>
</ul>
</div>
</div>
</div>
http://jsfiddle.net/7PhJZ/74/
You need to use media queries and set different styles depending on breakpoints. I would suggest mobile first.
Very rough fiddle at http://jsfiddle.net/7CcjD/ - try changing the width of the Result box.
<div id="header">
<div class="menu-1">Menu 1</div>
<div class="logo">Logo</div>
<div class="menu-2">Menu 2</div>
</div>
div {border: 1px solid #999}
.menu-1 {border-color: red}
.logo {border-color: green}
.menu-2 {border-color: blue}
.menu-1, .logo, .menu-2 {
margin: 1em auto;
width: 80%
}
#header {text-align: center;}
#media only screen and (min-width: 640px) {
.menu-1, .logo, .menu-2 {
border-width: 2px;
width: 20%;
display: inline-block;
}
}
you could use inline-block instead floatting :
http://jsfiddle.net/7PhJZ/75/
#nav {
margin:auto;
display: block;
border: 1px solid green;
}
#nav-inner {
max-width:810px;
height:200px;
margin:auto;
display: block;
border: 1px solid grey;
white-space:nowrap;/* keep them on one line */
}
#header {
position: fixed !important;
overflow: visible;/* auto if fixed would be wised somehow */
padding: 0px;
width: 100%;
top: 0;
left:0;
border: 1px solid purple;
}
#logo-nav {
display: inline-block;
}
#logo {
border: 1px solid blue;
margin: 0px auto 0px auto;
width: 225px;
height: 124px;
}
ul#site_nav_1 {
display:inline-block;
border: 1px solid red;
text-align:right;
max-width:32%;
}
ul#site_nav_2 {
display:inline-block;
border: 1px solid red;
text-align:left;
max-width:29%;
}
li#menu-item {
display:inline-block;
padding:20px;
text-align: center;
}
a {
font-family:'gobold_boldregular';
font-size:25px;
text-transform:uppercase;
letter-spacing: 1px;
text-shadow: 3px 3px 3px rgba(0, 0, 0, 0.3);
}
/* some reset */
#logo-nav, #site_nav_1, #site_nav_2 {
vertical-align:middle;
}
ul, li {
padding:0;
margin:0;
white-space:normal;
}
Related
In my Responsive website, the Headr text is not responsive compare to the page. As in my screenshot below:
Here is the relevant code I use:
html, body {
margin: 0 auto;
padding: 0;
}
.container {
max-width: auto;
margin: 0 auto;
width:100%;
}
.box {
border: 2px white dotted;
border-radius: 15px;
margin-top: 30px;
width: 380px;
padding: 10px;
left: 0;
right: 0;
margin-right:auto;
margin-left:auto;
position:absolute;
display:table-cell;
vertical-align:middle;
}
.nav-pills li a {
color: black;
border-radius: 10px;
margin: 3px;
font-size: 15px;
font-weight: 589px;
border-radius:0px;
background-color: white;
margin-top:260px;
}
.nav-pills li a:hover {
color: white;
background-color: transparent;
display:inline-block;
border: 1px white solid;
font-weight: 300;
}
.box h2 {
font: 70px/1.2 'Pacifico', Helvetica, sans-serif;
color: white;
text-shadow: 2px 2px 0px rgba(0,0,0,0.2), 4px 4px 8px rgba(0,0,0,0.2);
padding-right: 5px;
padding-left: 5px;
margin-left: 15px;
}
.box span {
margin-left: 70px;
}
.nav-pills {
display:table;
margin:0 auto;
position:relative;
}
/* centered columns styles */
.row-centered {
text-align:center;
}
.col-centered {
display:inline-block;
float:none;
/* reset the text-align */
text-align:left;
/* inline-block space fix */
margin-right:-4px;
}
<div class="header" id="header">
<div class="container">
<div class="row row-centered">
<div class="col-md-6 col-centered">
<div class="box">
<h2>Lewis <br><span>Designs</span></h2>
</div>
</div>
</div>
<div class="menu">
<div class="row row-centered">
<div class="col-md-6 col-centered">
<ul class="nav nav-pills">
<li>About</li>
<li>Consultations</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
Very new to this, been getting help with centering in a previous question.
My only problem now, is that my header box is no longer responsive when i shrink my screen. I wonder what I did wrong.
It looks like all you need to do is define a width on the .col-centered class, because you defined the nested .box class with postion:absolute, which would set the position in reference to the parent element. Since the parent element had no width and was centered in its own parent element, the header box was positioned with that as the left reference point and extending 380px from there. You can read more about the CSS box model and how it works here.
.col-centered {
display:inline-block;
float:none;
width:100%;
/* reset the text-align */
text-align:left;
/* inline-block space fix */
margin-right:-4px;
}
See fiddle.
I'm trying to do something so astonishingly simple, and yet after pounding my head on the wall I'm unable to get the div that contains my navigation menu to center within the container. I would appreciate it if you'd have a look and let me know why it isn't working. I have a 1px border around the elements so you can see how the 'nav' div is staying left justified.
Here's a link to jsfiddle:
http://jsfiddle.net/glennw9/7vr7tovh/3/
html, body {
background-color:#F2EED6;
width:900px;
height:900px;
border: 1px solid #630800;
margin: 0px 0px 0px 0px;
}
#container {
/*border: 1px solid #630800;*/
width: 860px;
margin: 0 auto;
border: 1px solid #630800;
}
h1 {
font-size: 2.5em;
font-family: Georgia;
letter-spacing: 0.1em;
color: #630800;
text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.6);
text-align: center;
}
div.nav {
margin-left: auto;
margin-right: auto;
display: inline-block;
border: 1px solid #630800;
text-align: center;
}
ul.nav {
width: 840
margin: 0 auto;
display: block;
}
ul.nav, li.nav {
list-style-type: none;
}
li.nav, a.nav {
background: #354178;
color: white;
font-family: Arial, Helvetica, sans-serif;
padding: 6px 10px;
text-decoration: none;
}
li.nav, a.nav:hover {
background: #4A5AA7;
display:inline;
}
li {
display:inline;
padding: 10px;
}
a.active {
background: white;
color: black;
border: 1px solid #CCCCCC;
}
<body>
<div id="container">
<h1>Edit Order Record</h1>
<div class="nav">
<ul class="nav">
<li><a class="nav" href="inv-main.php">Main Page</a>
</li>
<li><a class="nav" href="prod-view-paged.php">View Products</a>
</li>
<li><a class="nav active" href="order-view-paged.php">View Orders</a>
</li>
<li><a class="nav" href="cat-view.php">View Categories</a>
</li>
<li><a class="nav" href="#Bot">Go to Bottom</a>
</li>
</ul>
</div>
<br>
<br>
<br>
</body>
Simply add text-align: center; to the #container element.
Here's a fiddle.
You can center align it by simply two ways.
This "div.nav" class has inline-block. To make it center aligned with its parent, you have to use "text-align:center" to its parent.
Remove inline-block for "div.nav" class and add margin:0 auto in this class. It will be center aligned.
you have a lot of options mentioned above. This too counts as one of them: position: absolute;
left:50%;
margin-left: (half of the width of the div u wish to center)
Remember, set your parent element/div to relative.
What about this (updated fiddle)?
div.nav {
margin: 0 auto;
border: 1px solid #630800;
text-align: center;
}
If you want to consider using flex-box, you can do something like this too (see the fiddle, and here's the browser compatibility table):
HTML:
<nav>
<h1>Hello world</h1>
<ul>
<li>Thing</li>
<li>Another thing</li>
<li>Yet another</li>
</ul>
</nav>
CSS:
nav {
border: 1px solid gray;
display: flex;
flex-flow: column wrap;
align-items: center;
width: 100%;
}
li {
display: inline-block;
border: 1px solid black;
}
And lastly, here's a list of ways to center stuff:
Set this on the child element: { margin-left: 50%; transform: translateX(-50%) }
If the child element is block do this: { margin: 0 auto }
Or, on the parent element, do: { text-align: center }
remove the margin:0px 0px 0px 0px; and change that to margin:auto; in html,body{}
and add text-align:center in #container.
html, body {
background-color:#F2EED6;
width:900px;
height:900px;
border: 1px solid #630800;
/* margin: 0px 0px 0px 0px;*/
margin: auto;
}
#container {
/*border: 1px solid #630800;*/
margin: 0 auto;
border: 1px solid #630800;
text-align:center;
}
just edit the css part. and it will generate the output like this:
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
First attempt on doing a website after a online course on HTML and CSS. I'm struggling with the horizontal menu.
I have three elements in the "header": img1; img2; ul/li elements
I want to make them stick together so i have a logo on the left, a triangule in the middle and the menu on the righ, all stick together, with no spaces beetween them and centered.
Can you help me out ?!
Here's the CSS:
* {
border: 1px solid white;
background-color:#000;
color: white;
}
#header {
border: 1px solid blue;
height: 60px;
}
#logo {
float: left
}
#logo img {
display:inline-block;
width: 300px;
height: 50px;
}
#triangulo {
display:inline-block;
}
#triangulo img {
display:inline-block;
width: 50px;
height: 50px;
}
#menu {
display:inline-block;
border: 1px solid pink;
float: right
}
#menu li {
display: inline-block;
text-color: white;
font-weight: bold;
font-family: Arial;
}
Thank you so much for the patience
edit: html
<div id="header">
<div id="logo"><img src="images/Olympic-logo.png" width=300 height=50 /></div>
<div id="triangulo"><img src="images/Triangle(shape).jpg" width=50 height=50 /></div>
<div id="menu">
<ul>
<li>Quem Somos</li>
<li>Soluções</li>
<li>Instalações</li>
<li>Contactos</li>
<li>X</li>
<li>X</li>
</ul>
</div>
</div>
edit2: fiddle link i want the 3 elements sticked toghther with no spaces between them and make it all the same row, with enough space to li/ul elements
Check thIS FIDDLE :DEMO
1) I have added a wrapper for the header and given it width and margin:auto , so that the menu is centered to the width (since you wanted the menu to be centered.)
2) and all the menu's are in a single line with equal spacing , this is done by applying display:inline-block;
HTML:
<div id="header-wrapper">
<div id="header">
<div id="logo"><img src="images/Olympic-logo.png" width=300 height=50 /></div>
<div id="triangulo"><img src="images/Triangle(shape).jpg" width=50 height=50 /></div>
<div id="menu">
<ul>
<li>Quem Somos</li>
<li>Soluções</li>
<li>Instalações</li>
<li>Contactos</li>
<li>X</li>
<li>X</li>
</ul>
</div>
</div>
</div>
CSS:
#header-wrapper{
width:800px;
margin:0 auto;
}
}
#header {
border: 1px solid blue;
height: 60px;
}
#logo {
display:inline-block;
}
#triangulo {
display:inline-block;
}
#menu {
display:inline-block;
border: 1px solid pink;
height: 50px;
width: 400px;
}
#menu li {
display: inline-block;
color: white;
font-weight: bold;
font-family: Arial;
}
Let me know if this is what you wanted.
There are many problem with your CSS Code. For example not wisely use float:left and float:right and second thing is there is no such property text-color: white; it should be color: white;.
Have a look at DEMO first . this is achieve by using display:inline-block;
CSS Code:
ul{margin:0; padding:0; vertical-align:top; list-style-type:none;}
#header {
white-space:nowrap;
border:1px solid #c6c6c6;
}
#logo {
display:inline-block;
}
#triangulo {
display:inline-block;
}
#menu {
display:inline-block;
border: 1px solid pink;
}
#menu ul li ,#menu ul li a
{
color: black;
font-weight: bold;
font-family: Arial;
display:inline-block;
text-decoration:none;
}
You need to float all of those inline divs left.
#header {
border: 1px solid blue;
height: 60px;
margin:0 auto 0 auto;
}
#logo {
float: left;
}
#triangulo {
display:inline-block;
float:left;
}
#menu {
display:inline-block;
border: 1px solid pink;
float:left;
height: 50px;
width: 400px;
}
#menu li {
display: inline-block;
color: white;
font-weight: bold;
font-family: Arial;
}
This should do it.
<style>
* {
border: 1px solid white;
background-color:#000;
color: white;
}
#header {
border: 1px solid blue;
height: 60px;
}
#logo {
display:inline-block;
padding:0px;
margin:0px;
width: 300px;
height: 50px;
float:left;
}
#triangulo {
display:inline-block;
width: 50px;
height: 50px;
padding:0px;
margin:0px;
float:left;
}
#menu {
display:inline-block;
border: 1px solid pink;
float:left;
}
#menu ul {
float:left;
padding:0px;
margin:0px
}
#menu li {
display: inline-block;
text-color: white;
font-weight: bold;
font-family: Arial;
}
</style>
<div id="header">
<img id="logo" src="images/Olympic-logo.png" width=300 height=50 />
<img id="triangulo" src="images/Triangle(shape).jpg" width=50 height=50 >
<div id="menu">
<ul>
<li>Quem Somos</li>
<li>Soluções</li>
<li>Instalações</li>
<li>Contactos</li>
<li>X</li>
<li>X</li>
</ul>
</div>
</div>
http://jsfiddle.net/hmaQR/
Here is my html:
<div id="page">
<div id="logo">
<h1>My Website</h1>
</div>
<div id="navigation-wrapper">
<ul id="top-navigation">
<li class="home">Home</li>
<li class="about">About</li>
<li class="Blog">Blog</li>
<li class="Contact">Contact</li>
</ul>
</div>
<div id="body"></div>
</div>
and the CSS
#page {
margin: 0 auto;
border: 2px solid black;
width: 960px;
height: 700px;
}
h1 {
font-family: Helvetica;
text-decoration:;
color: #0099CC
}
#logo {
position: relative;
margin: 0 auto;
text-align: center;
font-size: 20px;
border: 1px dashed blue;
}
#navigation-wrapper {
margin: 0 auto;
border: 1px dashed blue;
text-align: center;
}
#top-navigation {
border: 1px solid black;
margin: 0 auto;
list-style: none;
}
#top-navigation li {
width: 80px;
height: 20px;
background-color: orange;
padding: 5px;
color: blue;
font-family: Helvetica;
display: inline-block;
}
You'll notice that the orange navbar/list is not quite centered to the logo above it. What the heck am I missing?
I cannot seem to get the #top-navigation to center to the middle of the page. I'm super new to css, so any help would be appreciated.
I suggest you in each css file of a page that you make, always put the following first to disable all margin and padding of the default css:
* { margin:0;padding:0}
Try that, and then you can tweak the margin and padding of your h1
Hope this helps
I forked your fiddle: http://jsfiddle.net/hmaQR/1/
ul { padding-left: 0; }
I highly recommend getting a good dev toolbar. Chrome has a great one out of the box.
I have the following code for my nav bar and can't seem to center it on the website. What am I doing wrong? Removing float: left does nothing for positioning.
Thanks.
css
ul#list-nav {
list-style: none;
margin: 20px auto;
padding: 0px;
width: 800px;
}
ul#list-nav li {
display: inline;
}
ul#list-nav li a {
text-decoration: none;
padding: 5px 0;
width: 100px;
float: left;
background: #485e49;
color: #eee;
text-align: center;
border-left: 1px solid #fff;
}
ul#list-nav li a:hover {
background: #a2b3a1;
color: #000
}
html
</head>
<body>
<div id="as">
<ul id="list-nav">
<li>Home</li>
<li>About Us</li>
</ul>
</div>
</body>
It is already centered, it's just that you are using explicit width for your menu so consider decreasing your menu width
Demo
CSS
ul#list-nav {
list-style:none;
margin:20px auto;
padding:0px;
width:800px;
border: 1px solid #ff0000;
overflow: hidden;
}
Currently I've made it 205px
CSS
ul#list-nav {
list-style:none;
margin:20px auto;
padding:0px;
width:205px;
border: 1px solid #ff0000;
overflow: hidden;
}
Fixed demo
You will need to add display: block;
You need to wrap your nav bar in a wrapper div and then set the margin of that div to auto like so:
<style>
#wrapper {
margin: auto;
}
</style>
<div id="wrapper">
<!-- (your nav bar code here) -->
</div>
I believe following should do the trick;
<div id="as" align="center">