I have a ul list like below. I want to make equal space between each li elements, in all viewports - desktops/ mobile/ table.
I had give padding-right for the icons inside the li, but this does break when seen in other resolutions (like mobile).
How to give equal ideal spacing between the li elements in all the resolutions?
I want the horizontal list of li elements to be center-aligned and equally spaced on whichever screen (desktop/ phone/ tablet)
<ul class="navbar-nav navbar-right">
<li class="dropdown">
<a href="javascript:void(0);">
<img src="1.svg" class="imgicon">
<span class="username">li 1</span>
</a>
</li>
<li class="dropdown" id="li2" >
<a href="javascript:WindowLocation('/123');">
<img src="2.svg" class="imgicon">
<span class="hidden-xs">li 2</span>
</a>
</li>
<li class="dropdown" id="li3" >
<a href="javascript:WindowLocation('/123');">
<img src="3.svg" class="imgicon">
<span class="hidden-xs">li 3</span>
</a>
</li>
<li class="dropdown" id="li4" >
<a href="javascript:WindowLocation('/123');">
<img src="4.svg" class="imgicon">
<span class="hidden-xs">li 4</span>
</a>
</li>
</ul>
as #Laif suggested you can try the flexbox. Flex can does exactly what you are asking for.
Notice the below code. it has 4 li inside ul and we have space between all li.
on mobile it will look like
ul {
display:flex;
list-style:none;
padding: 0px;
justify-content: space-between;
}
li{
border:1px solid grey;
padding:5px 10px;
}
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
`
Solution 1. Try viewport meta tag to tell the browsers on whichever device to use the same measurements. It maintains the same aspect ratio on all devices.
Solution 2. If solution 1 does not work for you, then try css media queries to make the right spacing on mobile and other screens.
try this:
in css you can apply
*{
margin: 0;
padding: 0;
}
ul
{
text-align: center;
}
ul li
{
list-style: none;
display: inline-block;
padding: 20px;
}
#media(max-width:340px)
{
ul li
{
padding: 15px;
}
}
you will get your li in center of the screen in all the resolution
Related
This is normally a question I don't need answered, however, I am baffled. I have tried everything I can think of.
This picture includes a gray piece at the right. That is the scroll bar, figured I would include it. This is on Google Chrome and how I want it.
And this is how Microsoft Edge does it.
I narrowed the problem down to my list items <li>. On Google Chrome (according to my resolutions), the width of <li> is 226.141px and on Microsoft Edge, using the same exact CSS, the width of <li> is 226.35px.
Here is my style.css:
div.menuContainer {
width:100%;
height:48px;
}
ul.menuItems {
/*margin:-12px;*/
}
li.menuItem {
display:inline-block;
box-sizing:border-box;
width:calc(100% / 7);
float:left;
text-align:center;
height:48px;
font-weight:bold;
background-color:#DD4400;
color:#454545;
padding:12px 0;
overflow:hidden !important;
}
li.menuItem:hover {
background-color:#454545;
color:#DD4400;
}
li.menuItem a {
color:#454545;
}
li.menuItem a:hover {
color:#DD4400;
}
Here is my menu:
<div class="menuContainer">
<ul class="menuItems">
<a href="/videos.php">
<li class="menuItem">
Videos
</li>
</a>
<a href="/playlists.php">
<li class="menuItem">
Playlists
</li>
</a>
<a href="/categories.php">
<li class="menuItem">
Categories
</li>
</a>
<a href="/actors.php">
<li class="menuItem">
Actors
</li>
</a>
<a href="/photos.php">
<li class="menuItem">
Photos
</li>
</a>
<?php if($logged_in == 0) { ?>
<a href="/login.php">
<li class="menuItem">
Login
</li>
</a>
<a href="/register.php">
<li class="menuItem">
Register
</li>
</a>
<?php }
else { ?>
<a href="/logout.php">
<li class="menuItem">
Logout
</li>
</a>
<a href="/account.php">
<li class="menuItem">
My Account
</li>
</a>
<?php }
?>
</ul>
</div>
Any help you can provide would be greatly appreciated. Thank You.
Here's a different way of approaching the same problem using flexbox. I also made some slight modifications to your HTML. The key to this approach is using display: flex on the container and flex-grow: 1 on the children of that container. Note: I also use display: flex to achieve vertical and horizontal centering on the <a> elements, rather than having to use top and bottom padding.
.menu {
height: 48px;
display: flex;
}
.menu a {
flex-grow: 1;
display: flex;
font-weight: bold;
background-color: #DD4400;
color: #454545;
align-items: center;
justify-content: center;
text-decoration: none;
}
.menu a:hover {
text-decoration: underline;
}
<div class="menu">
Videos
Playlists
Categories
Actors
Photos
Logout
My Account
</div>
Here's a quick article explaining what flexbox can do for you - css-tricks.com/snippets/css/a-guide-to-flexbox. I'd highly recommend adding this to your toolkit - it's relatively modern, but has very good browser support caniuse.com/#feat=flexbox. I use it very regularly.
Do a reset in your css, as a first thing:
* {
/* So 100% means 100% */
box-sizing: border-box;
}
See link for details.
On my custom shopify site when the main menu is in responsive mode, the links get all wonky and out of line, but only in a short area that seems to be random depending on browser.
Here is how they are supposed to look:
Here is how they look when they are breaking:
According to all of the responsive code, they are set up all the same.
Here is the code:
li a {
display: block;
padding: 7px 10px !important;
text-align: left !important;
}
li ul li:first-child {
display: none !important;
}
li ul li {
font-size: 13px !important;
clear: left !important;
text-align: left !important;
display: block !important;
}
<li class="site-nav--has-dropdown" aria-haspopup="true">
<a href="/pages/studios" class="site-nav__link">
STUDIOS
<span class="icon icon-arrow-down" aria-hidden="true"></span>
</a>
<ul class="site-nav__dropdown">
<div>
<li>
STUDIOS
</li>
<li>
LOCATIONS
</li>
<li>
UPCOMING CLASSES
</li>
<li>
EVENTS
</li>
</div>
<span class="arrow"> </span>
</ul>
</li>
Below is my code:
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
}
#sam_ul li {
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF';
}
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
The content pseudo element is displayed differently in both IE and mozilla. By different I mean in IE it is displaying correctly while in mozilla it is adding some extra padding and displaying the content.
check the difference between the first li element and the second li element.
Can anyone help me with this?
Add padding:0 to unordered list
#sam_ul{
padding:0
}
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF'; }
#u_l_sear:before {
content: '\0FBF'; }
<body>
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
</body>
Try to normalize everything. HTML and body has default margin and padding for every browser that could ruin your design. Almost all block elements has that.
Try:
html,body{
margin: 0;
padding:0;
}
Or download and add normalize.css
I am trying to make a navigation bar with a four columns submenus. I coded most of things, but when I creating the submenu I found the problem.
This is my HTML:
<div id="navigation">
<ul>
<li class="current">
Home
</li>
<li class="sub-menu">
Our Products
<div class="subnav product">
<div class="content">
<div class="col">
<ul>
<li class="one">
Main Menu Item
</li>
<li class="one">
Main Menu Item
</li>
<li class="one">
Main Menu Item
</li>
</ul>
</div>
<div class="col">
<ul>
<li class="two">
<img src="" />
Promoting Peace in the Niger Delta
</li>
<li class="three">
<img src="" />
Promoting Peace in the Niger Delta
</li>
<li class="four">
<img src="" />
Promoting Peace in the Niger Delta
</li>
<li class="five">
<img src="" />
Promoting Peace in the Niger Delta
</li>
</ul>
</div>
</div>
</div>
</li>
<li class="">
Service Maintenance
</li>
<li class="sub-menu">
Frequently Ask Questions
<li class="sub-menu">
Our Products
<div class="subnav product">
<div class="content">
<div class="col">
<ul>
<li class="one">
Main Sub Item
</li>
<li class="one">
Main Sub Item
</li>
<li class="one">
Main Sub Item
</li>
</ul>
</div>
</div>
</div>
</li>
</ul>
</div>
Hope somebody will help me out.
Thank you.
The problem is the container width is defined at 300px
#navigation ul li > div.product {
width: 300px;
}
And its child elements are taking up 100% of that space. So you need to make sure they have room to float left.
#navigation div.col {
float: left;
height:200px;
width: 25%;
}
Hopefully that helps with your question.
Fiddle
Check this http://jsfiddle.net/qtvVK/11/embedded/result/.
I made some changes to your markup and used display:inline-block; instead of floating elements
Relevant CSS syles
/* Dropdown styles */
#navigation ul > li > ul.sub-menu {
display: none;
position:absolute;
padding:10px 0;
background:#fff;
border: 1px solid #DDDCDC;
top: 24px;
z-index: 1;
}
/* Show dropdown when hover */
#navigation ul > li:hover > ul.sub-menu {
display:block;
}
.row {
width:auto;
white-space: nowrap;
}
.col {
display: inline-block;
vertical-align: top;
padding: 0 10px;
}
i suggest using jQuery.
it has simple function called slideDown().
Here is a link to a good tutorial.
You should do like so: First hide your menu when script starts:
$("#idOfDropDownMenu").hide();
And command to drop menu down when mouse enters button and slide up when it leaves it:
$("#idOfButton").hover(function(){ //function that fires when mouse enters
$("#idOfDropDownMenu").slideDown();
}, function() { //function that fires when mouse leaves
$("#idOfDropDownMenu").slideUp();
}
Instead of using IDs you can use any CSS selector.
I hope this helps with your question.
css
ul li ul
{
display: none;
position: fixed;
margin-left: 191px;
margin-top: -37px;
}
ul li:hover ul
{
display: block;
}
ul li a:hover
{
color: #fff;
background: #939393;
border-radius:20px;
}
ul li a
{
display: block;
padding: 10px 10px;
color: #333;
background: #f2f2f2;
text-decoration: none;
}
ul
{
background: #f2f2f2;
list-style:none;
padding-left: 1px;
width: 194px;
text-align: center;
}
html
<ul>
<li>Home</li>
<li>
About
<ul>
<li>About Me
<li>About Site
</ul>
</li>
<li>Contact</li>
</ul>
I am stumped. I am trying to make a set of icons that sit inside a container with a fixed width. The elements must be inside the parent container but must extend beyond the boundary and not line break when they reach the right border of the parent.
I am using Floated li elements
Here is the fiddle
Would like it to look like this.
Not this:
Thanks for any Help.
Here is the Code:
<div class="mainFooter">
<div class="iconContainer">
<ul class="nav nav-pills">
<li rel="tooltip" data-original-title="Services"><a class="icon-th-list icon-white">A</a>
</li>
<li class="" rel="tooltip" data-original-title="Assets"><a class="icon-briefcase icon-white">B</a>
</li>
<li class="" rel="tooltip" data-original-title="Clients"><a class="icon-group icon-white">C</a>
</li>
<li class="" rel="tooltip" data-original-title="Reports"><a class="icon-dashboard icon-white">D</a>
</li>
<li class="" rel="tooltip" data-original-title="Preferences"><a class="icon-cogs icon-white">E</a>
</li>
<li class="" rel="tooltip" data-original-title="Assets"><a class="icon-briefcase icon-white">F</a>
</li>
<li class="" rel="tooltip" data-original-title="Assets"><a class="icon-briefcase icon-white">G</a>
</li>
</ul>
</div>
.mainFooter {
background: #dddddd;
position: relative;
height: 40px;
width:30%;
}
.iconContainer {
position: absolute;
width: 100%;
border:1px solid red;
top:5px;
}
.mainFooter .nav > li{
float:left;
}
.mainFooter .nav > li > a {
padding:0px;
margin: 1px;
height:25px;
width:30px;
background:#2f65bb;
color: #ffffff;
font-size: 130%;
line-height: 25px;
display: inline-block;
text-align:center;
}
.white-space: nowrap on the <ul>. Do not float the elements, but use display: inline-block.
http://jsfiddle.net/nJydR/3/
you may try to setup fixed width for .nav-pills, something like
.nav-pills {
width: 230px;
}
http://jsfiddle.net/nJydR/4/