Leaving Equal Width Gap Spacing Before and Between Menu Buttons

How can I create a horizontal menu with each item being equal width and spacing inbetween?

See: http://jsfiddle.net/f6qmm/

display: table is being used to evenly space a dynamic number of lis. Unfortunately, that doesn't work in IE7, so *float: left is used (for only IE7 and lower) so that at least they're all on one line - though it still looks horrendous.

padding-left: 5px is applied to every li, then li:first-child { padding-left: 0 } removes it for only the first li.

#main-nav {    list-style: none;    margin: 0;    padding: 0;    width: 100%;    display: table;    table-layout: fixed;    overflow: hidden}#main-nav li {    display: table-cell;    *float: left; /* improve IE7 */    height: 25px;    text-align: center;    padding-left: 5px}#main-nav li:first-child {    padding-left: 0}#main-nav li a {    width: 100%;    display: block;    height: 100%;    line-height: 25px;    text-decoration: none;    background-color: #e0e0f0;    font-weight: bold;    color: #021020;}#main-nav li a:hover {    background-color: #498cd5;    color: #ddeeee;}
<ul id="main-nav">    <li><a href="#">one</a></li>    <li><a href="#">two</a></li>    <li><a href="#">three</a></li></ul>
<hr />
<ul id="main-nav"> <li><a href="#">one</a></li> <li><a href="#">two</a></li> <li><a href="#">three</a></li> <li><a href="#">four</a></li> <li><a href="#">five</a></li></ul>

How to make a navigation bar have equal spacing?

.nav li {
font-family: 'Roboto', sans-serif;
width: 149.6666666px;
border-bottom: none;
height: 106px;
line-height: 106px;
font-size: 14px;
display: inline-block;
float:left;
margin: 0 auto;
}

In the above styling, width property is fixed. All the list items will be of equal width, irrespective of their content. Instead, get rid of width and play around with padding. For example:

padding-right: 5px;
padding-left: 5px;

This will give a 10px spacing between all the list elements despite the content.

How to make space between menu items in CSS/HTML

you can add margin-right value to the #menu li or #menu li a JS Fiddle

#menu li {
display: inline-block;
margin-right:50px;
}

Share the width for menu items with equal padding using CSS

Use this style (everything is dynamic here) -

CSS (modified) -

ul {
width: 600px;
display: flex;
list-style: none;
padding: 0px;
border: solid 1px blue;
}
li {
flex: auto;
text-align: center;
padding: 8px 0;
}
li:hover {
background: blue;
color: white;
cursor: pointer;
}

HTML (no change) -

<ul>
<li>
Test
</li>
<li>
Test Very Very Large Bigger Item
</li>
<li>
Test Bigger item
</li>
</ul>

Working demo here

center align menu with equal spacing

Try using Flex Box layout (Demo):

#container ul {
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-ms-box-orient: horizontal;
box-orient: horizontal
}

#container li {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-ms-box-flex: 1;
box-flex: 1;
border: solid 1px #000;
text-align: center
}

How to add Equal Spacing and equal width for button in iOS Auto layout

check this image and made your constraints like below...

Sample Image

RESULT:- preview in different sizes

Sample Image


With Stackview (For iOS 9.0 and above)

Sample Image

NOTE: If you have to make app for iOS 9 and later then UIStackView is another option for you



Related Topics



Leave a reply



Submit