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 li
s. 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...
RESULT:- preview in different sizes
With Stackview (For iOS 9.0 and above)
NOTE: If you have to make app for iOS 9 and later then
UIStackView
is another option for you
Related Topics
How to Stretch a View to Its Parent Frame with Swiftui
How to Use Gpx File for UI Tests Only
Swift "Print" Doesn't Appear in Stdout But 3Rd Party C Library Logs Do When Running in Docker on Ecs
Upload Multiple Images to Ftp Server in iOS
Swift: Strange Behavior About Unwrapping
Parse Weird Bug in Swift That Causes Acl Write Permissions to Change to an Objectid
Swift: Check Which Value in Nsarray Is Closest to Another Given Value
How to Insert a Row in Tableview Without Using Reloaddata Function in Cocoa
Generic Function with Binary Operations
Occasional Blank Frames After Exporting Asset - Avexportsession
Exc Bad Access While Creating a New Characterset
Parse Migration Error to Mlabs and Heroku
Assigning Values to Tuple in for Loop
Custom Markers Disappear on Zoomin The Map and Appear on Zoomout The Map with Clustering