Floating multiple li's left and right - wordpress

I am trying to make a custom sidebar in wordpress, i have all the element and info in li's, what i am trying to do is try to shift the half of the total li's to left and half to the right...
What i am using is float/clear left and right, that not seems to work as i wanted...
HTML Structure:-
<ul>
<li class="left">Left</li>
<li class="left">Left</li>
<li class="left">Left</li>
<li class="left">Left</li>
<li class="left">Left</li>
<li class="right">Right</li>
<li class="right">Right</li>
<li class="right">Right</li>
<li class="right">Right</li>
<li class="right">Right</li>
</ul>
The CSS:-
.left { float:left; width:50%; clear:left; }
.right { float:right; width:50%; clear:right }
jsFiddle

If you're willing to give up your list style disc (depending on the browser), you can do this easily without floats or modifying your markup.
http://jsfiddle.net/Duejc/2/
ul {
-webkit-columns: 2;
-moz-columns: 2;
columns: 2;
}

Why don't you brake it down like this, depending on the case :)
<ul class="left">
<li>Left</li>
<li>Left</li>
<li>Left</li>
<li>Left</li>
<li>Left</li>
</ul>
<ul class="right">
<li>Right</li>
<li>Right</li>
<li>Right</li>
<li>Right</li>
<li>Right</li>
</ul>
.left{
float: left;
width: 50%; }
.right{
float: right;
width: 50%; }
or do it as #Xander says :)

Shuffle you're HTML. when an element is cleared it does so against the previously floated element; in your case, it was the sixth element clearing the fifth:
<ul>
<li class="left">Left</li>
<li class="right">Right</li>
<li class="left">Left</li>
<li class="right">Right</li>
<li class="left">Left</li>
<li class="right">Right</li>
<li class="left">Left</li>
<li class="right">Right</li>
<li class="left">Left</li>
<li class="right">Right</li>
</ul>
jsFiddle

Done it with simple markup and styles
http://codepen.io/ruinunes/pen/bpgpZV
HAML:
%ul.chat
%li.stamp
Saturday
%span 20:32
%li.left Who is it?
%li.right It's Little Nero's, sir. I have your pizza.
%li.left Leave it on the doorstep and get the hell outta here
%li.stamp
Saturday
%span 20:33
%li.right Okay, but what about the money?
%li.left What money?
%li.right Well, you have to pay for your pizza, sir.
%li.left Is that a fact? How much do I owe you?
%li.left Keep the change, ya filthy animal!
%li.right Cheapskate.
SCSS
ul.chat {
font-family: sans-serif;
list-style:none;
margin: 0 auto;
padding: 0;
width: 50%;
li {
margin-bottom: 10px;
display: inline-block;
border-radius: 8px;
padding: 10px;
&.left {
background: #e3e3e3;
float:left;
margin-right: 50%;
width:50%;
border-top-left-radius: 0;
}
&.right {
background: #6CCE66;
color: #fff;
float: right;
width: 50%;
border-top-right-radius: 0;
}
&.stamp {
color: #666;
font-size: 80%;
text-align: center;
width: 100%;
span {
color: #999;
}
}
}
}

Related

Menu items float left and down

I am creating a menu using an unordered list that mixes list items of different sizes, some are half the height and width of others. They all float left. What I'm getting is this:
If I add clear:left to the third small item I get this:
What I want is for the second and fourth (or third and forth) small items to float below the other two, like this:
Is there a way to do this with css? The menu is created dynamically so forcing a particular position won't work, it needs to be able to flow into the proper position.
Would having multiple <ul/> work for you ? If so, the following Codepen would work : https://codepen.io/anon/pen/qPaVar
Same code as an embedded code snippet :
ul {
list-style : none;
padding: 0;
margin: 0;
text-align: center
}
li {
margin: 0
}
li.left {
float: left
}
div.small {
background-color: blue;
width: 20px;
height: 20px
}
div.large {
background-color: yellow;
width: 40px;
height: 40px;
}
<ul>
<li class="left">
<div class="large">A</div>
</li>
<li class="left">
<ul>
<li class="left">
<div class="small">1</div>
</li>
<li class="left">
<div class="small">2</div>
</li>
</ul>
<ul>
<li class="left">
<div class="small">3</div>
</li>
<li class="left">
<div class="small">4</div>
</li>
</ul>
</li>
<li class="left">
<div class="large">B</div>
</li>
</ul>
Hope this helps!
Try the grid-auto-flow: dense
https://developer.mozilla.org/ru/docs/Web/CSS/grid-auto-flow
try this
.main li {
display: inline-block;
vertical-align: middle !important;
width: 200px;
height: 200px;
border: 1px solid;
}
.inner-div li {
width: 99px;
height: 89px;
display: inline-block;
list-style: none;
padding: 0;
margin: 0;
float: left;
text-align: center;
}
ul.inner-div {
list-style: none;
padding: 0;
}
<div class="container">
<ul class="main">
<li>div 1</li>
<li>div 2
<ul class="inner-div">
<li>div 21</li>
<li>div 21</li>
<li>div 21</li>
<li>div 21</li>
</ul>
</li>
<li>div 3</li>
</ul>
</div>

how do I stack unordered list into 2 separate rows

I'm completely stuck and have been struggling with this for days because I'm not a developer and just learn from forums.
I cannot modify the li classes with the price and table, restriction on code blocks to generate this from my ecommerce platform. I would like to get the results displayed in two rows, qty on top and price on bottom.
96 150 300 450 600
8.06 7.66 7.26 6.86 5.97
li.QtyTabQty {
display: inline-block;
/* text-align: right; */
border-right: 1px solid #fff;
/* width: 100%; */
/* float: right; */
/* width: 100%; */
}
li.QtyTabPrc {
display: inline-block;
text-align: right;
border-right: 1px solid #fff;
/* width: 100%; */
float: right;
}
<ul class="none">
<li class="QtyTabQty">96</li>
<li class="QtyTabPrc">$8.06</li>
<li class="QtyTabQty">150</li>
<li class="QtyTabPrc">$7.66</li>
<li class="QtyTabQty">300</li>
<li class="QtyTabPrc">$7.26</li>
<li class="QtyTabQty">450</li>
<li class="QtyTabPrc">$6.86</li>
<li class="QtyTabQty">600</li>
<li class="QtyTabPrc">$5.97</li>
</ul>
if you want use lists you can do with flexbox:
.none {
display: flex;
flex-flow: column wrap;
/* height is required */
height: 50px;
}
.none li {
list-style: none;
flex: 1;
/* Modify padding as required */
padding: 0 7px;
}
<ul class="none">
<li class="QtyTabQty">96</li>
<li class="QtyTabPrc">$8.06</li>
<li class="QtyTabQty">150</li>
<li class="QtyTabPrc">$7.66</li>
<li class="QtyTabQty">300</li>
<li class="QtyTabPrc">$7.26</li>
<li class="QtyTabQty">450</li>
<li class="QtyTabPrc">$6.86</li>
<li class="QtyTabQty">600</li>
<li class="QtyTabPrc">$5.97</li>
</ul>
Another option...pretty close to what you already have.
li.QtyTabQty {
display: inline-block;
position:absolute;
}
li.QtyTabPrc {
display: inline-block;
float:left;
margin-top:30px;
margin-right:10px;
}
<ul class="none">
<li class="QtyTabQty">96</li>
<li class="QtyTabPrc">$8.06</li>
<li class="QtyTabQty">150</li>
<li class="QtyTabPrc">$7.66</li>
<li class="QtyTabQty">300</li>
<li class="QtyTabPrc">$7.26</li>
<li class="QtyTabQty">450</li>
<li class="QtyTabPrc">$6.86</li>
<li class="QtyTabQty">600</li>
<li class="QtyTabPrc">$5.97</li>
</ul>

CSS Space Between Submenu Items

I am trying to lessen the vertical space between items in the submenu of my drop down navigation bar. You can see what it currently looks like at http://www.mirandabee.com
I am trying to reduce the space vertically, but can't figure it out.
Here is my HTML for it:
<ul id ="nav">
<li><a href="http://www.mirandabee.com/search/label/About%20Me#.UuQfD-Io6Rs">About Me
<ul>
<li>About Me</li>
<li>Photo Album</li>
</ul>
</a></li>
<li><a href="http://www.mirandabee.com/search/label/Blog%20Series#.UuPc3uIo6Rs1">Blog Series
<ul>
<li>Guest Post Monday</li>
<li>Infographic Monday</li>
<li>What I Wore Wednesday</li>
<li>Fun Friday Link Party</li>
</ul>
</a></li>
<li><a href="http://www.mirandabee.com/search/label/Freebies#.UhDj0D92XiM">Freebies
<ul>
<li>Giveaways</li>
<li>Printables</li>
</ul>
</a></li>
<li><a href="http://www.mirandabee.com/search/label/Recipes#.UuPyGOIo6Rt">Recipes
<ul>
<li>All Recipes</li>
<li>Appetizers</li>
<li>Snacks</li>
<li>Main Dishes</li>
<li>Sides</li>
<li>Drinks</li>
<li>Desserts</li>
<li>Other Recipes</li>
</ul>
</a></li>
<li><a href="http://www.mirandabee.com/search/label/Projects%20%26%20Crafts#.UuP03OIo6Rt">Projects
<ul>
<li>For the Home</li>
<li>Kids & Family</li>
<li>Travel Solutions</li>
<li>Gift Ideas</li>
<li>Other</li>
</ul>
</a></li>
<li><a href="http://www.mirandabee.com/search/label/Organize%20Your%20Life#.UuP2yuIo6Rt">Organization
<ul>
<li>One Space at a Time</li>
</ul>
</a></li></ul>
CSS:
/* ----- NAVMENU ----- */
#nav, #nav ul {
padding: 0px;
margin: 0;
z-index: 999;
margin-top: -80px;
margin-left: 100px;
list-style: none;
color: #007581;
}
#nav a {
display: block;
width: 6.5em;
}
#nav li {
float: left;
width: 6.5em;
font-size:18px;
color: #ff6962
}
#nav li ul {
position: absolute;
width: 6em;
font-size: 5px;
left: -999em;
}
#nav li:hover ul {
left: auto;
width: 7em;
font-size:18px;
color: #ff6962;
margin-left: -2px;
padding-top:-112px;
}
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
#nav li:hover ul, #nav li.sfhover ul {
left: auto;
}
Keep in mind that I am very much a beginner, but I would appreciate any help I can get. Thanks so much!
Your HTML is totally broken. You have
<a><ul><li><a>...</a></li></ul></a>
you cannot have anchors inside anchors like that. Your css also doesn't make much sense. You've got position: absolute, but no position: relative anywhere else, so ALL of the nested <ul>'s are going to be in the wrong place.
Your HTML structure is bad. I'm sorry to say that. But here I try to fix it for you.
Fiddle
HTML:
<ul id="nav">
<li>
About Me
<ul>
<li>About Me</li>
<li>Photo Album</li>
</ul>
</li>
<li>
Blog Series
<ul>
<li>Guest Post Monday</li>
<li>Infographic Monday</li>
<li>What I Wore Wednesday</li>
<li>Fun Friday Link Party</li>
</ul>
</li>
<li>Freebies
<ul>
<li>Giveaways</li>
<li>Printables</li>
</ul>
</li>
<li>Recipes
<ul>
<li>All Recipes</li>
<li>Appetizers</li>
<li>Snacks</li>
<li>Main Dishes</li>
<li>Sides</li>
<li>Drinks</li>
<li>Desserts</li>
<li>Other Recipes</li>
</ul>
</li>
<li>Projects
<ul>
<li>For the Home</li>
<li>Kids & Family</li>
<li>Travel Solutions</li>
<li>Gift Ideas</li>
<li>Other</li>
</ul>
</li>
<li>Organization
<ul>
<li>One Space at a Time</li>
</ul>
</li>
</ul>
CSS:
/* ----- NAVMENU ----- */
#nav, #nav ul {
padding: 0px;
margin: 0;
z-index: 999;
margin-top: 0px;
margin-left: 100px;
list-style: none;
color: #007581;
}
#nav a {
display: block;
width: 6.5em;
}
#nav li {
float: left;
width: 6.5em;
font-size:18px;
color: #ff6962
}
#nav li ul {
position: absolute;
width: 6em;
font-size: 5px;
left: -999em;
}
#nav li:hover ul {
left: auto;
width: 7em;
font-size:18px;
color: #ff6962;
margin-left: -2px;
padding-top:-112px;
}
#nav li:hover ul, #nav li.sfhover ul {
left: auto;
}
I hope it will help you on solving this problem.. :)

Creating three layer submenu and center depending width parent

I want to make a menu like this :
and here what I have done so far :
<nav class="container site-navigation clearfix">
<ul id="menu-main-menu" class="main-menu">
<li id="menu-item-7" class="current-menu-item current_page_item">
Home
</li>
<li id="menu-item-50" class="menu-item menu-parent-item">
Teaching
<div class="sub-menu-outer">
<div class="sub-menu-inner">
<ul class="sub-menu">
<li id="menu-item-75" class="menu-item">
Description
</li>
<li id="menu-item-84" class="menu-item">
Papers
</li>
<li id="menu-item-82" class="menu-item">
Tasks
</li>
<li id="menu-item-83" class="menu-item">
<a href="http://localhost/artech/teaching/log-in/">Log In
</a>
</li>
</ul>
</div>
</div>
</li>
<li id="menu-item-21" class="menu-item">
Creative Technology
</li>
<li id="menu-item-20" class="menu-item">
Blog</li>
<li id="menu-item-19" class="menu-item">Bio
</li>
<li id="menu-item-18" class="menu-item">
Contact
</li>
</ul>
</nav>
and the css :
ul{list-style: none; padding: 0; margin: 0;}
nav{
background: url(http://img29.imageshack.us/img29/3563/6s9a.png) repeat-x bottom left;
height: 44px;
}
#menu-main-menu > li{position: relative; float:left;}
#menu-main-menu > li:not(:first-child){
margin-left: 70px;
}
#menu-main-menu li a{color: #000000; line-height: 35px;}
#menu-main-menu .current-menu-item a,#menu-main-menu .current_page_item a, #menu-main-menu > li:hover a{
font-weight: 700;
}
#menu-main-menu > li:hover ul.sub-menu li a{
font-weight: 400;
}
#menu-main-menu > li:hover ul.sub-menu li:hover a{
font-weight: 700;
}
.sub-menu-outer{background: url(http://img12.imageshack.us/img12/5050/3g1y.png) repeat-y top right #FFFFFF;
} /* two line stripe y*/
.sub-menu-inner{
background: url(http://img12.imageshack.us/img12/5050/3g1y.png) repeat-y top left;
} /* two line stripe y*/
.sub-menu{
background: url(http://img29.imageshack.us/img29/3563/6s9a.png) repeat-x bottom left;
} /* one line stripe x*/
.sub-menu > li{
padding: 5px 15px;
text-align: center;
}
#menu-main-menu > li.menu-parent-item .sub-menu-outer {
display: none;
float: left;
position: absolute;
left: 0;
top: 0;
margin-top: 35px;
}
#menu-main-menu > li.menu-parent-item:hover > .sub-menu-outer{
display: block;
z-index: 1000;
}
http://jsfiddle.net/JY8k5/4/
I have the follow problems that couldn't solve my self :
The right and left y-stripes has to start form the begging of parent li and ending at the end of the sub-menu without covering (I have a white background) the parent's li word / page link.
The x-stripe at the bottom of the sub-menu has to be over the left and right stripes as the foto shows
The sub-menu has to be centered base the widht of parent
Is it possible to solve all this only with css or I have to use jquery. I try a lot especially with the positions but couldn't achieve the desired results.
Any help is very appreciate.
I manage to solve it somehow. I change my html markup to :
<li id="menu-item-22" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-parent-item menu-item-22">
Teaching
<div class="sub-menu-wrapper" style="margin-left: -75px;"> // This style has been put by jquery
<ul class="sub-menu">
<li id="menu-item-75" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-75">
Description
</li>
// more li's here
</ul>
</div>
</li>
the css :
.sub-menu-wrapper{
background: url(../img/stripe.png) repeat-x bottom left #FFFFFF;
padding-bottom: 9px;
}
.sub-menu-wrapper ul.sub-menu{
background: url(../img/double-stripe.png) repeat-y top right;
}
.sub-menu-wrapper ul.sub-menu > li{
padding: 5px 15px;
text-align: center;
background: url(../img/double-stripe.png) repeat-y top left;
}
.sub-menu-wrapper ul.sub-menu li:first-child{
padding-top: 36px;
}
#menu-main-menu > li.menu-parent-item .sub-menu-wrapper {
display: none;
width: 115%;
min-width: 150px;
float: left;
position: absolute;
left: 50%;
top: -28px;
margin-top: 35px;
z-index: 40;
}
#menu-main-menu > li.menu-parent-item:hover > .sub-menu-wrapper{
display: block;
z-index: 10;
}
#menu-main-menu > li.menu-parent-item a{
position: relative;
z-index: 50;
}
and lastly the js :
$(".menu-parent-item").hover(function(){
var subMenu = $(this).children(".sub-menu-wrapper");
var parentWidth = $(this).width();
var subMenuWidth = parentWidth * 1.15; // because .sub-menu-wrapper width is 115%
var margin = 0;
if(subMenuWidth <= 150){
margin = -75;
}else{
margin = (( subMenuWidth / 2 )) *(-1);
}
subMenu.css("margin-left", margin);
});
I couldn't find a css way (except to add a div with min-width and fake a min-margin) to center the submenu so I did it with jquery.

CSS - Menubar changes width while hover

I created a menu and a submenu that should appear after I hover over the list elements of the main menu. The problem is that the widths of the main menu's list elements changes while hovering, and it looks puzzling. I tried it with a fixed width, but the space between the menu items is too big then.
I also tried to set the submenu to position absolute, but the problem was that the submenu was always located at the same position and not beneath the main menu's item which was active.
I created a codepen for this issue.
HTML:
<ul class="menubar">
<li class="menubar-li">Unternehmen
<ul class="menubar-sub">
<li class="menubar-sub-li">Profil
<li class="menubar-sub-li">Meilensteine
<li class="menubar-sub-li">Team
<li class="menubar-sub-li">News
<li class="menubar-sub-li">Jobs</li>
</ul>
</li>
<li class="menubar-li">Kompetenzen
<ul class="menubar-sub">
<li class="menubar-sub-li">Kreation
<ul class="menubar-subsub">
<li>Strategie
<li>Design
<li>Online
<li>Reinzeichnung</li>
</ul>
</li>
<li class="menubar-sub-li"> Prepress
<ul class="menubar-subsub">
<li>Seitenproduktion</li>
<li>Kreativretusche
<li>Colormanagement
<li>Proofen</li>
</ul>
</li>
<li class="menubar-sub-li">Druck
<ul class="menubar-subsub">
<li>Personalisiert</li>
<li>Web 2 Print</li>
</ul>
</li>
<li class="menubar-sub-li">Katalogmanagement</ul>
</li>
<li class="menubar-li">Portfolio</li>
<li class="menubar-li">Service
<ul class="menubar-sub">
<li class="menubar-sub-li">Mediapool</li>
<li class="menubar-sub-li">DUON</li>
<li class="menubar-sub-li">Datenupload</li>
<li class="menubar-sub-li">Downloads
</ul>
</li>
<li class="menubar-li">Kontakt
<ul class="menubar-sub">
<li class="menubar-sub-li">Ansprechpartner</li>
<li class="menubar-sub-li">Anfahrt</li>
<li class="menubar-sub-li">Impressum</li>
</ul>
</li>
</ul>
CSS:
.menubar {
list-style: none;
position: relative;
bottom: 16px;
}
.menubar a {
color: black;
text-decoration:none;
font-size: 13px;
position: relative;
}
.menubar-li {
float: left;
height:29px;
line-height:29px;
vertical-align: middle;
padding-left: 10px;
padding-right: 10px;
margin-right: 10px;
}
.menubar-li:hover {
background-color: #94ba1d;
cursor: pointer;
}
.menubar-li:hover .menubar-sub {
display: block;
}
.menubar-sub {
display: none;
list-style: none;
margin-top: 1px;
padding-bottom: 10px;
padding-right: 10px;
padding-left: 0px;
background-color: #94ba1d;
position: relative;
left: -10px;
}
.menubar-sub-li {
line-height: 14px;
padding-top: 5px;
padding-left: 10px;
}
.menubar-subsub {
display: none;
}
You can position the submenu below the main menu button by setting the main menu button to position: relative and placing the (absolute) submenu inside it. You then show/hide the submenu by toggling overflow: hidden and visible.
Here is a demo: http://codepen.io/seraphzz/pen/osGnh

Resources