How to center a menu on my online shop? - html

I hope I am right here, I need your help with my upcoming online shop. I would like to center the main categorie menu on the top but I am missing the right CSS order.
This is what it looks right right now and there are 2 ways I want to test the looking.
First I want is a centered menu where "home" and "Kollektionen" have the same distance to the left or right.
And secondly I want to try out what it looks like when every li-element 'pushes' the next element to the right so that it's centered at the last one.
You know what I mean? 2 different ways of centering my menu and I don't find the right command....
I hope you can help me.
Thanks in advance.
PS: sorry for my bad english, it's not my native language.
EDIT: I cannot post code I'm afraid as it's not mine. But maybe this is enough: the basic template is made of this http://www.shopwaredemo.de/
2nd EDIT: after trying Asko's, Mike's and Tom's answer and both works I ask myself why? What is the difference between display:flex and display:inline-box and between text-align and justify-content set to center???

Perhaps use display: inline-block? E.g the following:
.menu {
text-align: center;
}
.menu li {
float: none; /* assuming the template has set this to 'left' */
display: inline-block;
margin-left: 20px; /* tweak this for the space inbetween items */
margin-right: 20px; /* and this, too */
}
Note that I didn't look at the code, so the div .menu is an example.

You can try to make the <ul> display: inline-block and apply text-align: center on parent.
JSFiddle Demo: http://jsfiddle.net/Q2hSv/1/

Without seeing some code, maybe this will help.
.topmenu {
width: 80%;
margin: auto;
}
.menuitems {
float: left;
width: // Here you take the number of items divided by 100%
// remember to take borders and margins into account

Dependent on your browser scope you could use display:flex;
HTML:
<nav>
<ul>
<li>Home</li>
<li>Neuheiten</li>
<li>Orschmuck</li>
<li>Ringe</li>
<li>Halsketten</li>
<li>Armbander</li>
<li>Kollecktion</li>
</ul>
</nav>
CSS:
nav {
background: #000;
margin: 0 auto;
width: 70%;
}
ul {
display: flex;
justify-content: center;
}
li {
list-style: none;
}
Example http://codepen.io/tom-maton/pen/AFpnJ

back to work and managed to achieve my goal:
Thanks again for every answer, I used and played a lot with your snippets and and I ended up using this (click click!):
#mainNavigation {
margin: 0 auto;
width: 98%;
}
#mainNavigation ul {
display: flex;
justify-content: center;
}
#mainNavigation li {
list-style: none;
width: 15%;
text-align: center; /* to center the li-elements itself */
}
which works perfectly! Still figuring out what excatly justify-center and display:flex do but I want you to know that you helped a lot.
CHEERS!
PS: how come my thread got a negative rating? it says -1 to me!? Did I do anything wrong?

Related

Unordered List Alignment - Products Side by Side

At my wits end. Have looked at other answered questions on here, and can't seem to get the answers to work.
My fiddle: (Exp:resso store code left in just to show that that's what I'm using.)
https://jsfiddle.net/4gk5qszm/
HTML:
<div class="StoreContent-Index">
{exp:store:search orderby="date" sort="desc"}
{exp:store:product entry_id="{entry_id}"}
<ul class="StoreContent-ProductIndexList">
<li>
<a href="{url_title_path='store/product'}">
<img src="{product_image}" class="TCBProductImgCat">
<h4>{title}</h4>
<p>{regular_price}</p>
</a>
</li>
</ul>
{/exp:store:product}
{/exp:store:search}
</div>
CSS:
ul.StoreContent-ProductIndexList{
display: inline-block;
*display: inline;
zoom: 1;
float: left;
}
ul.StoreContent-ProductIndexList li {
width: 200px;
display: inline-block;
vertical-align: top;
*display: inline;
*zoom: 1;
}
.StoreContent-Index{
background: #FFF;
width: 100%;
}
.StoreContent-ProductIndexList:after {
clear: both;
}
How it looks live:
http://www.thymecher.com/0316-S
I've tried grid alignment, floating, all the inline stuff - nada. I just want the danged things to align properly side by side in the list style shown in the fiddle. (Image, title underneath, price underneath that - repeated horizontally, not vertically, with - say - 8 products per line.)
Any help is greatly appreciated. Thanks!
So, as Andrew pointed out, your example code doesn't really match what's happening on your site. Within the .StoreContent-Index div, every one of your products is wrapped in a form element and, within that is a div and a ul, the latter of which has the actual product info in it.
The combination of form elements being block-level elements and the fact that many basic HTML elements have a default clearfix (What is clearfix?) applied to them in your stylsheet was really working against you here. I have a working, minimal example on CodePen that you can review, but assuming you can make changes to all of your stylesheets, the main changes you'll want to make will be in http://www.thymecher.com/?css=0316-Styles/store-main.v.1458927906
In that stylesheet, you can remove the following code:
ul.StoreContent-ProductIndexList{
display: inline-block;
*display: inline;
zoom: 1;
float: left;
}
ul.StoreContent-ProductIndexList li {
width: 200px;
display: inline-block;
vertical-align: top;
*display: inline;
*zoom: 1;
}
and replace it with this:
ul.StoreContent-ProductIndexList, ul.StoreContent-ProductIndexList > li {
list-style:none;
}
.store_product_form {
display:inline-block;
vertical-align:top;
width: 200px;
}
This should give you the layout you're looking for.
Fiddle not rendering correctly.
I don't think your CSS naming conventions are valid
ul.StoreContent-ProductIndexList li
You should just use the StoreContent-ProductIndexList class; or
.StoreContent-ProductIndexList li
I would research FlexBox. It really helps with alignment (someone's CodePen example: http://codepen.io/HugoGiraudel/pen/LklCv).
.StoreContent-ProductIndexList {
display: flex;
justify-content: space-around;
}
You may want to give your "li" lines a class name too
.liClasses {
margin: as needed;
others: as needed;
}

How to put unordered (gif image) list in middle?

I have an unordered list within a body and the body tag is aligned to the center, the text for the ul list goes to the middle but the gif image stays to the left side of the page. How do I fix this?
http://www.student.nvcc.edu/home/kosindi/test/ul.html
That is a link to my website which has an example of my problem.
Please explain your logic, thank you.
as per your HTML code you gave in link just few change will do.
in css
body {
padding-left: 45%; // add this css
text-align: left; // change this css
}
You have two variants, choose one:
1.Use this CSS and it will work:
li { list-style-position: inside; }
2.If you want the basket balls to appear one under another then use this CSS:
body { text-align: left; }
ul { width: 200px; margin: 0 auto; }

How to align a Wordpress navigation bar to the right of a logo?

I'm trying to get my navigation bar to the right of the logo in my Wordpress theme. It's being built with Underscores. I've managed to line up the primary navigation and the logo the way I want it, basically, with this CSS:
.main-navigation {
position: relative;
float: right;
top: -4em;
width: 55%;
display: block;
clear: both;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
}
.main-navigation ul {
list-style: none;
margin: 0;
padding-left: 0;
float: right;
}
and here's a picture of how I want it to look:
I understand that negative margins (assuming top: -4em; is considered with negative margins) aren't elegant or the best way to handle these sorts of things. Plus, I generally find these kinds of workarounds usually come back to bite me later on.
I'm new to playing around with JSFiddle, so I hope I've done this correctly! Here's my code, now condensed!: http://jsfiddle.net/DMDesigns/d39ej96r/11/
What's the best way to make this happen? I've been searching, seen a lot of people ask this question, but many of the answers have been too specific to their website to help me.
This took me the better part of the day to figure out, yesterday, but disappointed with the lack of responses, here's what I figured out. I'm posting it here for anyone else having a similar problem.
First, I took the logo (named .header-image) and added:
float: left;
position: relative;
Then I took the navigation I wanted to the left of (named .main-navigation) and removed my workaround, which was
float: right;
top: -4em;
width: 55%;
and changed clear:both; to clear:none;
I added a little personal CSS to my .main-navigation to make it match the logo which was
height: 112px;
background: #69d7f9;
z-index: -1;
padding: 28px 0;
and I removed any floats from .main navigation ul.
It's better to create a main div and insert both logo and navigation section in the same div with float:left; for both of them. Let me know if you get this or I'll let you know by an example.
Using the Underscores starter theme for WordPress, the navigation bar can be floated to the right of the logo (or site title) using the following method:
Add the following CSS to your style-sheet:
.site-branding{
float: left;
display: inline-block;
}
.site-description{
display: none;
}
#site-navigation{
float: right;
clear: none;
width: auto;
}
These instructions are based on the Underscores theme as is before customisation.

vertical alignment and floats

I'm sorry if my question seems stupid, but I spent too much time on this. I have a div display block containing two span, one on the right and the other one on the left.
<div class="user-bar">
<span class="username">Martin GOYOT</span>
<span class="user-options"><input type="button" class="disconnect" value="déconnexion"/></span>
</div>
I tried two thing to get them vertical aligned: First one, getting these two floats, but the problem is that I can clearly see that they are out of flow (normal) and thereby, if I apply a background, to the container, it doesn't cover them:
http://jsfiddle.net/M7Ffd/1/
Second solution, let the first in the flow and put the second one as a float, but the result is that I can't find out how to vertically aligning them:
http://jsfiddle.net/M7Ffd/2/ (be careful of the button, it is not really vertically aligned even if it looks like)
So, the question is: what is the best solution, and, how to fix at least one of these two misbehaviour.
thanks, and sorry, I'm a css newbie.
Vertical alignment is a hard issue. And floating seems to be everyone's first goto solution for everything. Avoid the gotos, how about using
position: absolute;
right: 0;
http://jsfiddle.net/M7Ffd/3/
Is this what you want? fiddle here
.user-bar {
padding: 0.5em;
margin: 0 1em 1em 1em;
background-color: green;
font-weight: bold;
font-size: 1.25em;
height:30px;
min-width:300px;
}
.user-options {
display: inline-block;
background-color: #CCC;
float: right;
}
.username {
float: left;
background: yellowgreen;
}
​
Setting the minimum width and giving height solves the alignment + Background solution.
Use the clearfix hack on the parent element of the 2 floated children to resolve your issue.
.clearfix:before, .clearfix:after { content: "\0020"; display: block; height: 0; overflow: hidden; }
.clearfix:after { clear: both; }
.clearfix { zoom: 1; }
I updated your fiddle to show you it http://jsfiddle.net/M7Ffd/5/

li with display: inline-block; property jumps down in Google Chrome & Safari

I am trying to build a website and have encountered a tricky issue with li having display: inline-block; property.
My website is: http://www.gypsytours.in/
If you visit this site, on homepage, I have a horizontal list under the heading "Himalayan Packages by Gypsy Tours".
In this list, I have a block element A with display: block; property.
Here are my simplified codes:
HTML:
<div id="menu-board">
<ul>
<li>Elephant Safari Packages in Jim Corbett Park, India</li>
<li>Chopta Tungnath Trekking Package</li>
<li>River Rafting Packages in Rishikesh</li>
</ul>
</div>
CSS:
#menu-board
{
text-align: center;
}
#menu-board ul
{
}
#menu-board ul li
{
float: none;
display: inline-block;
}
#menu-board ul li a
{
display: block;
width: 180px;
height: 130px;
background-color: #C50000;
text-align: center;
overflow: hidden;
}
Now, the issues is: My link-text in 2nd box, is not longer than two lines, unlike the other two boxes where link-text spreads in three lines. This boxes look perfectly fine in IE and FireFox but when I open the site in Google Chrome or Safari, the box in the center (with relatively shorter text) pops down. If I make the text long enough to span in three lines, it comes back to original position. I am not able to figure out how to fix this. My apologies for not being able to put across my issue in simple and short manner. I am relatively inexperienced with web-designing. I will really appreciate if you guys can help me out. Thanks in advance.
Ok, after more digging, I found out that it was a computed float issue.
I believe that adding:
#splash-list ul li a {
float:left;
}
will solve the problem. It may compute very slightly differently on other browsers, but at least they'll be in the proper line.
Hope this helps!
Mason