How to center navigation bar using css? - html

Hi im having trouble with centering the nav on this draft im making for a client.
Here is the link http://cjdrafts.info/germanserviceshop/
Please help thanks.

I'm not a professional, still learning coding and found a way to fix your issue.
What I did is commented the float left for .menu-wrapper
#Top_bar .menu_wrapper {
/* float: left;
z-index: 201;*/
}
Then defined 650px width and set the left and right margin to auto
.header-stack #Top_bar .menu_wrapper {
clear: both;
margin: 0 auto;
width: 650px;
}

Set width for menu_wrapper
#Top_bar .menu_wrapper {
z-index: 201;
width: 650px;
margin: auto;
}
remove float, set fixed width and set margin: auto.
Use display: inline-block instead of float for li
#Top_bar .menu > li {
margin: 0;
z-index: 203;
display: block;
display: inline-block;
}
and:
#Top_bar .menu_wrapper {
float: left;
z-index: 201;
width: 100%;
text-align: center;
}
set 100% width for parent and use text-align: center.

thanks for the help.
Doing the edits on a browser it does work but for some reason when i placed the css codes in the theme style sheet. Nothing work, i tried both solutions.
What seems to be the problem? I have been on this for atleast 7 days now.
I actually have a solution which is to use a menu plugin but this will be my last option.

Related

Aligning nav with logo using relative positioning

My CSS positioning skills have always been truly terrible. I'm looking to place my nav bar next to my logo, as well as making it move with the page and not get all screwy on anything smaller than a maximized window on a 1080p screen.
What it currently looks like: http://5.9.78.201/abellant/
It will likely look odd if you're on a different screen size.
I've (so far) used methods found on here, to no avail, using relative, absolute, and even clearing before giving up on it.
Can anyone show me where I'm screwing this up? I'm quite embarrassed by the fact that of all things, my positioning is just so bad.
Thank you.
If you want to position your logo and navbar at the center of the page::
Set #header "display:inline-block", "height:auto" and "text-align: center;" and remove all the css you have added to #logo and #navigation
#header {
width: 100%;
height: auto;
background: #f2f2f2;
margin: 0;
padding: 0;
box-shadow: 0 1.5px 1px #777;
display: inline-block;
text-align: center;
}
And if you want to set your logo and navigation side by side::
#header {
width: 100%;
height: auto;
background: #f2f2f2;
margin: 0;
padding: 0;
box-shadow: 0 1.5px 1px #777;
display: inline-block;
}
#logo {
float: left;
width: 50%;
}
#navigation {
float: right;
margin: 40px;
}
If you want to move your header section with page scroll. Set #header to "position:fixed".
So part of the problem is that you have a fixed left and right margin. Remove the fixed left and right margin for #logo and #navigation and do something like the following in your CSS:
#header {
margin: 0 auto; /* 0 px on top and bottom, auto on left and right => centered for a block element */
width: 960px; /* You need a width that will accomodate the logo and nav */
}
To make this work at other sizes, you'll need to look into CSS3 breakpoints. Here is a tutorial:
https://developers.google.com/web/fundamentals/design-and-ui/responsive/fundamentals/?hl=en
I solve your problem.
.container {
min-width: 500px;
position: relative;
text-align: center;
}
#logo {
display: inline-block;
vertical-align: middle;
}
#navigation {
display: inline-block;
}
If you noticed that the logo and the menu are NOT perfectly center it's because your image has a small white space, if you could delete that space and replace the new image it will be PERFECTLY center :)

multiple div alignment issues

I am trying to create multiple horizontal div elements on a page http://jsfiddle.net/bss6mc5a/
#body-left { float: left; content:url(http://placehold.it/240x930);}
#body { display: inline; }
#body-right { float: right; content:url(http://placehold.it/240x930);}
The layout is how I would like it to be displayed however when I add text (remove the comment tag) to the the div is moving down when I would like it to stay in place.
Thank you for any assistance / correction in how I achieve this.
You need to define width for the divs:
#body-left { float: left; content:url(http://placehold.it/240x930);}
#body { float: left; width: 960px; }
#body-right { float: right; content:url(http://placehold.it/240x930);}
Updated Fiddle:
http://jsfiddle.net/bss6mc5a/3/
Update 2:
http://jsfiddle.net/bss6mc5a/7/
Instead of trying to float your elements left or right, you can just set fixed location objects.
I updated your JSFiddle to do what I'm thinking will help.
Basically, your left and right content areas would normally have fixed width (though your images make up for that), and would be positioned absolutely to put them in the right place, then the content is just centered with:
margin-left: auto;
margin-right: auto;
width: 300px; /* some arbitary width */
But check out the Fiddle, see if that helps.
check this out I thing this what you want click Demo
Some changes in CSS
#body {
display: inline;
width: 960px;
float: left;
text-align: justify;
}
Hope this will help you...
give your body divs a display: inline-block;
http://jsfiddle.net/bss6mc5a/5/
#body-left {content:url(http://placehold.it/240x930);display: inline-block; vertical-align: top;} #body { display: inline-block; vertical-align: top; width: 30%;} #body-right {content:url(http://placehold.it/240x930); display: inline-block; vertical-align: top;}

Div should be centered but it's not?

Everything looks fine in both the HTML & CSS, so the div in question should be centered on the page. I have included some code snippets below, but the real code can be found here: http://jsfiddle.net/stbx08mk/
test-div at the bottom should be centered in the 1024 area, but it isn't. Why not?
#page-wrapper {
background-color: white;
margin: 0 auto;
overflow: auto;
padding: 0;
width: 1024px;
}
#test-div {
background-color: orange;
float: left;
height: 100px;
margin: 0 auto;
width: 800px;
}
Based on your fiddle, you need to adjust your #test-div style to float: none; and clear: both;
#test-div {
background-color: orange;
clear: both;
float: none;
height: 100px;
margin: 0 auto;
width: 800px;
}
Your JSFiddle Updated
floating divs to center "works" with the combination of display:inline-block and text-align:center.
First, remove the float attribute on the inner divs. Then, Text-align:center on the main outer div. And for the inner divs, display:inline-block.
Just tested it - display:inline-block on the inner divs works. Might also be wise to give them explicit widths too.
For your problem
Check this fiddle
Remove float:left; and add clear:both; to #test-div.
It just worked for me..
This will solve your problem
Try it..
The reason your #test-div is not centered, is because you're using the property float: left; on it in your CSS. The auto margins don't work on floated elements.
Try removing the float: left; property to get your desired result.
Float: left is whats making it ignore your margin: 0 auto;
Make sure your <html> and <body> tags take up the entire width of the browser and the margin and padding are both 0. This caused my content to be almost centered, but a little bit offset from center. Use this CSS:
html, body {
width: 100%;
margin: 0;
padding: 0;
}
In addition, in your #test-div use:
#test-div{
margin: 0 auto;
}

html renders different in same browser

I am creating a simple blog template. In the right corner of the template there is a search box in the header. The search box should appear there, but at some moments it appears under the header.
This happens every now and then, if I refresh the page a few times the box will somethimes jump positions. I have used Google Chrome for the developent The html of this page is purely static, so I don't have a clue why this is happening. Could anyone find out why this box is jumping up and down.
The affected page can be found here.
I can't re-create your problem, but I'm sure adding position:relative to either nav or .wrapper
.wrapper {
width: 800px;
margin: 0 auto;
position: relative;
}
and position:absolute to the searchbox will prevent any jumping.
header#top #searchBox {
position:absolute;
top: 0;
right: 0;
display: block;
width: 240px;
height: 45px;
// line-height, any other styles
}
Try the following
header#top #searchBox{
float: right;
display: inline-block;
line-height: 45px;
width: 63%;
text-align: right;}
The solution is quite simple,
just ad float: left; to the menu element ( header#top nav ul)
header#top nav ul {
list-style: none;
height: 45px;
display: inline-block;
float: left;
}
than you will only need to add height to the wrapper
.wrapper {
width: 800px;
margin: 0 auto;
height: 46px;
}

Don't manage positioning (side-by-side)

I have following fiddle: http://jsfiddle.net/BFSH4/
As you see there are two issues:
The h1 and h2 aren't vertically aligned.
The nav and the content aren't horzontal alligned.
For the 1. I already tried margin and padding. No success...
The second one also isn't that easy the common ways of floating and using inline-block don't work...
What am I doing wrong?
I finally managed floating the header. The problem was that hgroup isn't a block element.
However even it worked after all I think it is better to use a real image for the enterprise name and slogan.
Now only the issue with the horizontal alignment fails.
I don't know why:
http://jsfiddle.net/BFSH4/2/
I can do what I want there is no way that they wan't to be side by side!
Solution for your first problem (found here):
HTML
<div class="header">
<span></span><img src="images/prototype.png" /><hgroup><h1>Prototype</h1><h2>SideBySide</h2></hgroup>
</div>
CSS
.header {
height: 160px;
border: 1px solid #8a2be2;
/* text-align: center; */
}
.header span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
.header img {
display: inline-block;
height: 160px;
float: left; /* added, so the image will appear left to the text correctly */
}
.header hgroup {
margin: 0;
vertical-align: middle;
display: inline-block;
}
This solution depends on display: inline-block
Solution for the second problem:
.nav {
width: 229px;
display: block;
margin: 0 auto;
}
Live demo: http://jsfiddle.net/BFSH4/4/