I have what is hopefully a simple problem that I'm just overcomplicating in my mind.
Here is a Fiddle to demonstrate my issue.
In the Fiddle above you will see a flyout menu setup. On the top option you will see an enlarged first option that has a broken float. This is where my issue is. I need those elements to float alongside each other without breaking the list container holding them.
I understand that the white-space:nowrap is causing the break of that containers space, however, whenever I try and remove that element I can't seem to get my float to honor. I'm sure this is a simple miss on my part due to thinking of things that will be surrounding it, but any advancement on this is appreciated and hopefully an easy up for someone.
CSS:
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-block; }
/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */
#nav{margin:0;padding:0;position:relative;float:left;}
#nav li {list-style:none;}
#nav a {
color:#fff;
display:block;
line-height:2.4;
padding:0 1em;
text-decoration:none;
border-bottom:1px solid #eee;
}
/* FLYOUT */
.sub {
top:0;
margin:0;
padding:0;
left:100%;
display:none;
min-height:100%;
position:absolute;
white-space:nowrap;
border-left:2px solid #eee;
}
#nav li:hover .sub {
display:block;
}
#nav li:hover .sub .sub {
display:none;
}
#nav .sub li:hover .sub{
display:block;
}
.sub a:hover {
color:#fff;
background:#333;
}
.sub img { min-width:120px; float:left; }
.sub .content { float:left; }
/*-- COLORS NOT NEEDED ON LIVE--*/
.first{background:#aaa;}
.second {background:#bbb;}
.third {background:#ccc;}
.fourth {background:#ddd;}
.fifth {background:#aaa;}
.sixth {background:#bbb;}
.seventh {background:#ccc;}
.eighth {background:#ddd;}
.nineth {background:#aaa;}
.tenth {background:#bbb;}
.all {background:#000}
<div id="nav">
<li><a class="first" href="#">Level 1 Option</a>
<ul class="sub first">
<li class="clearfix"><a href="#">
<div class="float">
<img src="https://placeholdit.imgix.net/~text?txtsize=20&txt=120%C3%9780&w=120&h=80" alt=""></div>
<div class="">
<h5>This will be a title</h5>
<p>
<strong>Sub-title</strong><br>
Specs<br>
<strong>Sub-title</strong><br>
Specs
</p>
</div>
</a>
<ul class="sub first">
<li>Option 1</li>
<li>Option 1</li>
<li>Option 1</li>
<li>Option 1</li>
</ul>
</li>
<li>Option 2
<ul class="sub first">
<li>Option 2</li>
<li>Option 2</li>
<li>Option 2</li>
<li>Option 2</li>
</ul>
</li>
</ul>
</li>
<li><a class="second" href="#">Level 1 Option</a>
<ul class="sub second">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="third" href="#">Level 1 Option</a>
<ul class="sub third">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="fourth" href="#">Level 1 Option</a>
<ul class="sub fourth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="fifth" href="#">Level 1 Option</a>
<ul class="sub fifth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="sixth" href="#">Level 1 Option</a>
<ul class="sub sixth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="seventh" href="#">Level 1 Option</a>
<ul class="sub seventh">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="eighth" href="#">Light Duty</a>
<ul class="sub eighth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="ninth" href="#">Level 1 Option</a>
<ul class="sub ninth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="tenth" href="#">Level 1 Option</a>
<ul class="sub tenth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="all" href="#">View All</a>
</li>
</div>
Remove the float left form the image within float div. And add some margin over there.
CSS:
.sub img {
min-width: 120px;
/* float: left; */ //Remove this line
margin-top: 10px;
}
See this fiddle.
One way to acheive your desired layout is to set inline-block for both the image container, and the container for the headings/sub headings.
vertical-align: top; is necessary to ensure the two containers align at their top edges.
For the sake of simplicity, I kept your existing float class. (Note that this class needed to be added to the container for the heading/sub-heading/specs.)
.float {
display: inline-block;
vertical-align: top;
}
Please check this code , i think you are looking for this, you dont need to set width to .sub i have added new division and add some property
.float , .inline-block {
display:inline-block;
vertical-align:top;
}
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix {
display: inline-block;
}
/* start commented backslash hack \*/
* html .clearfix {
height: 1%;
}
.clearfix {
display: block;
}
/* close commented backslash hack */
#nav {
margin: 0;
padding: 0;
position: relative;
float: left;
}
#nav li {
list-style: none;
}
#nav a {
color: #fff;
display: block;
line-height: 2.4;
padding: 0 1em;
text-decoration: none;
border-bottom: 1px solid #eee;
}
/* FLYOUT */
.sub {
top: 0;
margin: 0;
padding: 0;
left: 100%;
display: none;
min-height: 100%;
position: absolute;
white-space: nowrap;
border-left: 2px solid #eee;
}
#nav li:hover .sub {
display: block;
}
#nav li:hover .sub .sub {
display: none;
}
#nav .sub li:hover .sub {
display: block;
}
.sub a:hover {
color: #fff;
background: #333;
}
.sub img {
min-width: 120px;
float: left;
}
.sub .content {
float: left;
}
/*-- COLORS NOT NEEDED ON LIVE--*/
.first {
background: #aaa;
}
.second {
background: #bbb;
}
.third {
background: #ccc;
}
.fourth {
background: #ddd;
}
.fifth {
background: #aaa;
}
.sixth {
background: #bbb;
}
.seventh {
background: #ccc;
}
.eighth {
background: #ddd;
}
.nineth {
background: #aaa;
}
.tenth {
background: #bbb;
}
.all {
background: #000
}
.float , .inline-block {
display:inline-block;
vertical-align:top;
}
<div id="nav">
<li><a class="first" href="#">Level 1 Option</a>
<ul class="sub first">
<li class="clearfix"><a href="#">
<div class="float"> <img src="https://placeholdit.imgix.net/~text?txtsize=20&txt=120%C3%9780&w=120&h=80" alt=""></div>
<div class="inline-block"><h5>This will be a title</h5></div>
<div class="">
<p> <strong>Sub-title</strong><br>
Specs<br>
<strong>Sub-title</strong><br>
Specs </p>
</div>
</a>
<ul class="sub first">
<li>Option 1</li>
<li>Option 1</li>
<li>Option 1</li>
<li>Option 1</li>
</ul>
</li>
<li>Option 2
<ul class="sub first">
<li>Option 2</li>
<li>Option 2</li>
<li>Option 2</li>
<li>Option 2</li>
</ul>
</li>
</ul>
</li>
<li><a class="second" href="#">Level 1 Option</a>
<ul class="sub second">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="third" href="#">Level 1 Option</a>
<ul class="sub third">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="fourth" href="#">Level 1 Option</a>
<ul class="sub fourth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="fifth" href="#">Level 1 Option</a>
<ul class="sub fifth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="sixth" href="#">Level 1 Option</a>
<ul class="sub sixth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="seventh" href="#">Level 1 Option</a>
<ul class="sub seventh">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="eighth" href="#">Light Duty</a>
<ul class="sub eighth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="ninth" href="#">Level 1 Option</a>
<ul class="sub ninth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="tenth" href="#">Level 1 Option</a>
<ul class="sub tenth">
<li>Option 1</li>
<li>Option 2</li>
</ul>
</li>
<li><a class="all" href="#">View All</a> </li>
</div>
Related
I'm new to coding and learning.
Working on the project below.
I'm having trouble getting the sub-items ('choice 1' to 'choice 5') to display in the drop down.
I have been able to get the headings ('Sub-item') to display, but cannot get the list of contents underneath ('choice' etc) to display.
Can someone help?
HTML
<div class="sidebar_menu">
<ul>
<li>
<a href=""><label class="sidebar_menu_label" for="sidebar_menu">Main</label>
</a>
<ul id="lp_test_pop_up">
<div class="lp_test_popup_box">
<div class="lp_category_item">
<h3 id="">Sub-Item 1</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="">Sub-Item 2</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="">Sub-Item 3</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="">Sub-Item 4</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="">Sub-Item 5</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="">Sub-Item 6</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
</div>
</ul>
</li>
</ul>
</div>
</div>
CSS
.sidebar_menu ul {
list-style: none;
margin: 0;
padding: 0px 0px 0px 0px;
}
.sidebar_menu ul li {
padding: 10px;
position: relative;
width: 250px;
background-color: #fcfcfc;
border-top: 1px solid #e4e8ea;
}
.sidebar_menu ul li:hover {
box-shadow: 0 0 4px 0 rgb(0 0 0 / 12%);
position: relative;
}
.sidebar_menu ul ul {
transform: all 0.3s;
opacity: 0;
position: absolute;
visibility: hidden;
left: 100%;
top: -2%;
}
.sidebar_menu ul li:hover > ul {
cursor: pointer;
opacity: 1;
visibility: visible;
z-index: 9997;
}
.sidebar_menu ul li a {
font-size: 14px;
color: black;
text-decoration: none;
}
.sidebar_menu ul li ul {
width: 634px;
padding: 20px;
padding-bottom: 10px;
background-color: white;
box-shadow: 1px 2px 8px grey;
}
.sidebar_menu ul li ul ul {
width: 134px;
padding: 0px;
background-color: white;
}
.sidebar_menu ul li ul li {
min-width: 250px;
border: none;
}
label.sidebar_menu_label {
font-size: 14px;
margin-left: 10px;
color: black;
}
.lp_test_popup_box {
display: flex;
flex-wrap: wrap;
}
.lp_category_item {
width: 33%;
height: 125px;
}
.sidebar_menu ul ul {
transform: all 0.3s;
opacity: 0;
position: absolute;
visibility: hidden;
left: 100%;
top: -2%;
}
Choices are not displayed because of this CSS code. These styles are applied to every "ul" element present in ".sidebar_menu ul".
To know more about Selectors ,check out this site click here
I have added some classes to HTML and updated CSS code
Fix !!
HTML
<div class="sidebar_menu">
<ul class="sidebar_menu_list">
<li class="sidebar_menu_item">
<a href=""><label class="sidebar_menu_label" for="sidebar_menu">Main</label>
</a>
<ul id="lp_test_pop_up">
<div class="lp_test_popup_box">
<div class="lp_category_item">
<h3 id="lp_category_subheading">Sub-Item 1</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="lp_category_subheading">Sub-Item 2</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="lp_category_subheading">Sub-Item 3</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="lp_category_subheading">Sub-Item 4</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="lp_category_subheading">Sub-Item 5</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
<div class="lp_category_item">
<h3 id="lp_category_subheading">Sub-Item 6</h3>
<ul>
<li>choice 1</li>
<li>choice 2</li>
<li>choice 3</li>
<li>choice 4</li>
<li>choice 5</li>
</ul>
</div>
</div>
</ul>
</li>
</ul>
</div>
</div>
CSS
.sidebar_menu_list {
list-style: none;
margin: 0;
padding: 0px 0px 0px 0px;
}
.sidebar_menu_item {
padding: 10px;
position: relative;
width: 250px;
background-color: #fcfcfc;
border-top: 1px solid #e4e8ea;
}
.sidebar_menu_item:hover {
box-shadow: 0 0 4px 0 rgb(0 0 0 / 12%);
position: relative;
}
#lp_test_pop_up {
transform: all 0.3s;
opacity: 0;
position: absolute;
visibility: hidden;
left: 100%;
top: -2%;
}
.sidebar_menu_item:hover #lp_test_pop_up {
cursor: pointer;
opacity: 1;
visibility: visible;
z-index: 9997;
}
.sidebar_menu ul li a {
font-size: 14px;
color: black;
text-decoration: none;
}
#lp_test_pop_up {
width:634px;
padding: 20px;
padding-bottom: 10px;
background-color: white;
box-shadow: 1px 2px 8px grey;
}
.sidebar_menu ul li ul ul {
width: 134px;
margin:15px 0px;
list-style-type:none;
padding:0px;
}
.sidebar_menu ul li ul li {
min-width: 250px;
border: none;
}
label.sidebar_menu_label {
font-size: 14px;
margin-left: 10px;
color: black;
}
.lp_test_popup_box {
display: flex;
flex-wrap: wrap;
}
.lp_category_item {
width: 33%;
height: 125px;
}
#lp_category_subheading{
margin:0px;
}
.lp_category_item{
margin-bottom:20px;
}
.lp_category_item ul li{
margin:2px 0px;
}
there are navigation panel(div id=#nav) in which is located horizontal menu(nav_main_ul). It has submenu. When I load site main horizontal is appear but on hover submenu of main manu is not appear.
I write:
.nav_main_ul li a:hover .submenu{
top:150;
}
What is wrong?
Everything did work while I use flexbox for sidebar, content and footer.
I'm newbie in html and css. I think reason of failure is conflict between position(absolute, relative) and flexbox.
Thanks in advance.
* {
margin: 0;
padding: 0;
list-style: none;
}
html,
body {
height: 100%;
}
#nav {
left: 0;
top: 120px;
background-color: #00004d;
width: 100%;
}
.nav_main_ul {
position: relative;
margin: 0px 0 0 400px;
}
#nav ul {
height: 50px;
list-style: none;
background-color: #00004d;
}
#nav li {
display: block;
float: left;
font-family: Arial, sans-serif;
font-size: 20px;
position: relative;
}
#nav li a {
color: #fff;
display: block;
height: 50px;
padding: 0 10px;
text-decoration: none;
line-height: 50px;
}
.nav_main_ul li a:hover {
background: #000080;
}
/*.nav_main_ul li a:hover .submenu{
top:50;
}*/
.submenu {
position: absolute;
width: 250px;
top: -9999em;
}
.submenu li {
width: 100%;
height: 40px;
background: #00004d;
}
.submenu li a {
line-height: 50px;
height: 50px;
transition: background 0.5s;
}
.submenu li a:hover {
background-color: red;
}
li:hover .submenu li {
display: block;
z-index: 100;
}
<div id="nav">
<ul class="nav_main_ul">
<li>Main
<ul class="submenu">
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
<li>link 4</li>
</ul>
</li>
<li> News
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
</ul>
</li>
<li>About us
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
<li>link 9</li>
<li>link 10</li>
</ul>
</li>
<li>Gallery
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
<li>link 9</li>
<li>link 10</li>
</ul>
</li>
<li>Contacts
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
<li>link 9</li>
<li>link 10</li>
</ul>
</li>
</ul>
</div>
Edit
Hi Delphi - To answer your question about the + selector, let's take a look at your HTML markup:
<li>
Main
<ul class="submenu">
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
<li>link 4</li>
</ul>
</li>
We need to understand that in the above markup, we can express it as:
LI (Parent / Root)
- A (Child of LI, Sibling of UL)
- UL (Child of LI, Sibling of A)
- LI (Child of UL, Grand-Child of LI)
Your desired action is that when a user hovers over the A, we show the UL.
USUALLY with CSS, we think of NESTED (or PARENT/CHILD) use-cases. But in YOUR use case, the A and UL are NOT in a parent/child relationship. Rather, they are siblings.
So, what we want is: When a user hovers over the A, we want the SIBLING(s) of A (in this case, only UL) to have TOP: 50PX.
There are TWO sibling selectors in CSS, "Adjacent" and "General". Adjacent means that it will ONLY apply when the siblings are directly together. For example:
<div>
<p></p>
<span></span>
<span></span>
<p></p>
</div>
OR:
DIV
- P
- SPAN
- SPAN
- P
Let's assume in the above, we wanted to select every SPAN that is a SIBLING of P. If we did:
p + span { color : red }
Only the FIRST span would be applied. That's because, it's the only span that immediately is next to a P element. Demo: http://jsfiddle.net/ucq5pg13/
What if we wanted ALL spans following a P to be red? That's where our GENERAL sibling selector comes into play:
p ~ span { color: red }
What this says is that ANY span that's a SIBLING of P, that comes AFTER IT, will be red.
It's important to note that it MUST come after. For example:
p ~ span { color: red }
<div>
<span></span> <!-- I WOULD NOT BE RED -->
<p></p>
<span></span> <!-- I WOULD BE RED -->
<span></span> <!-- I WOULD BE RED -->
<p></p>
</div>
Demo: http://jsfiddle.net/kb7n5236/
Hopefully that helps :)
Original:
When you hover over the a link, you'll need to position the .submenu. You can do something like:
<!-- On hover, show submenu -->
.nav_main_ul li a:hover + .submenu,
.nav_main_ul li a + .submenu:hover {
top: 50px;
}
JSFiddle: http://jsfiddle.net/1us0q4m3/1/
* {
margin: 0;
padding: 0;
list-style: none;
}
html,
body {
height: 100%;
}
#nav {
left: 0;
top: 120px;
background-color: #00004d;
width: 100%;
}
.nav_main_ul {
position: relative;
margin: 0px 0 0 400px;
}
#nav ul {
height: 50px;
list-style: none;
background-color: #00004d;
}
#nav li {
display: block;
float: left;
font-family: Arial, sans-serif;
font-size: 20px;
position: relative;
}
#nav li a {
color: #fff;
display: block;
height: 50px;
padding: 0 10px;
text-decoration: none;
line-height: 50px;
}
.nav_main_ul li a:hover {
background: #000080;
}
.nav_main_ul li a:hover + .submenu,
.nav_main_ul li a + .submenu:hover {
top: 50px;
}
.submenu {
position: absolute;
width: 250px;
top: -9999em;
}
.submenu li {
width: 100%;
height: 40px;
background: #00004d;
}
.submenu li a {
line-height: 50px;
height: 50px;
transition: background 0.5s;
}
.submenu li a:hover {
background-color: red;
}
li:hover .submenu li {
display: block;
z-index: 100;
}
<div id="nav">
<ul class="nav_main_ul">
<li>Main
<ul class="submenu">
<li>link 1</li>
<li>link 2</li>
<li>link 3</li>
<li>link 4</li>
</ul>
</li>
<li> News
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
</ul>
</li>
<li>About us
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
<li>link 9</li>
<li>link 10</li>
</ul>
</li>
<li>Gallery
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
<li>link 9</li>
<li>link 10</li>
</ul>
</li>
<li>Contacts
<ul class="submenu">
<li>link 5</li>
<li>link 6</li>
<li>link 7</li>
<li>link 8</li>
<li>link 9</li>
<li>link 10</li>
</ul>
</li>
</ul>
</div>
I am trying to create a grid from a html <ul> list where the grid is supposed to be divided into sections by a <hr> after x-number of <li> items. My html list looks like this:
<ul class="sortable">
<li class="item">item 1</li>
<li class="item">item 2</li>
<li class="break">
<hr>
</li>
<li class="item">item 3</li>
<li class="item">item 4</li>
<li class="break">
<hr>
</li>
<li class="item">item 5</li>
</ul>
It could also look like this:
<ul class="sortable">
<li class="item">item 1</li>
<li class="item">item 2</li>
<li class="item">item 3</li>
<li class="break">
<hr>
</li>
<li class="item">item 4</li>
<li class="break">
<hr>
</li>
<li class="item">item 5</li>
</ul>
Meaning there is no pattern to where the breaks might show up.
The HTML above creates a pretty nice sectioned list but when styling it into a grid I get into trouble.
I'm trying use something like this, a fiddle with my attempt:
.sortable li {
display: block;
float: left;
}
.item {
min-width: 150px;
border: 1px solid black;
margin-right: 15px;
padding: 5px;
}
.break {
width: 25%;
clear: both;
}
This breaks the list up before the .break element but does not break again after it.
So the question is, how do I style the grid so that the .break element (regardless of where in the list it appears) shows up on it's own line?
I can change the HTML and CSS pretty much how ever I like, though I'd prefer if I could still have a list as there would be quite a lot of work to change the code for sorting and doing a bunch of other stuff with the list and it's item.
I'm trying to get something like this:
To achieve this you would have to change your CSS as follows:
.sortable li {
display: block;
}
.item {
min-width: 150px;
border: 1px solid black;
margin-right: 15px;
padding: 5px;
float: left;
}
.break {
width: 25%;
clear: both;
padding: 10px;
}
<!DOCTYPE html>
<html>
<head>
<title>Sectioned List</title>
</head>
<body>
<ul class="sortable">
<li class="item">item 1</li>
<li class="item">item 2</li>
<li class="break">
<hr>
</li>
<li class="item">item 3</li>
<li class="item">item 4</li>
<li class="break">
<hr>
</li>
<li class="item">item 5</li>
</ul>
</body>
</html>
This basically remove the float to the <li> item and add some padding to the <li> break element.
See fiddle here
.sortable li {
display: inline-block;
}
.sortable {
max-width: 500px;
padding: 0;
display: inline-block;
}
.item {
max-width: 45%;
width: 100%;
border: 1px solid black;
padding: 5px;
float: left;
margin-left: 1%;
}
.hr {
width: 90%;
clear: both;
padding: 10px;
}
<!DOCTYPE html>
<html>
<head>
<title>Sectioned List</title>
</head>
<body>
<ul class="sortable">
<li class="item">item 1</li>
<li class="item">item 2</li>
<li class="hr"><hr></li>
<li class="item">item 3</li>
<li class="item">item 4</li>
<li class="hr"><hr></li>
<li class="item">item 5</li>
<li class="item">item 6</li>
<li class="hr"><hr></li>
<li class="item">item 7</li>
<li class="item">item 8</li>
<li class="hr"><hr></li>
</ul>
</body>
</html>
I haven't centered the hr but this is the basic idea
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
.line{
width:75%;
}
ul {
list-style-type: none;
clear: both;
}
.item {
min-width: 150px;
border: 1px solid black;
margin-right: 15px;
padding: 5px;
}
<ul>
<li class="item">item 1</li>
<li class="item">item 2</li>
</ul>
<ul>
<li class="line"><hr></li>
</ul>
<ul>
<li class="item">item 3</li>
<li class="item">item 4</li>
</ul>
<ul>
<li class="line"><hr></li>
</ul>
<ul>
<li class="item">item 5</li>
</ul>
I am trying to align the ul li depending on the float value.
So if the float is left then it will align left else right. But the issue is that when a li gets float right then it aligns to the right but not at the top.
Html code--
<ul>
<li style="float:left;">Text 1</li>
<li style="float:left;">Text 2</li>
<li style="float:right;">Text 3</li>
</ul>
Demo -- https://jsfiddle.net/squidraj/t2qmfkya/
Now they are all in one line but I would like to display it in the following way
Text 1 Text 3
Text 2
I have no clue if this is at all possible by the html format I have.
Any help is highly appreciated.
you can use CSS3 columns
ul {
columns: 2;
-moz-columns: 2;
-webkit-columns: 2;
}
<ul>
<li>Text 1</li>
<li>Text 2</li>
<li>Text 3</li>
</ul>
UPDATE
More random lis
ul {
columns: 5;
-moz-columns: 5;
-webkit-columns: 5;
}
<ul>
<li>Text 1</li>
<li>Text 2</li>
<li>Text 3</li>
<li>Text 4</li>
<li>Text 5</li>
<li>Text 6</li>
<li>Text 7</li>
<li>Text 8</li>
<li>Text 9</li>
<li>Text 10</li>
</ul>
This isn't the prettiest, but might help you...
You can target the elements with a particular inline style.
jsfiddle
ul li[style="float:left;"] {
clear: left;
margin-right: 20px;
}
ul li[style="float:right;"] {
float: none !important;
}
ul {
width: 180px;
background: red;
display: block;
float: left;
padding: 1rem;
list-style: none;
}
ul li[style="float:left;"] {
clear: left;
margin-right: 20px;
}
ul li[style="float:right;"] {
float: none !important;
}
<ul>
<li style="float:left;">Text 1</li>
<li style="float:left;">Text 2</li>
<li style="float:right;">Text 3</li>
<li style="float:right;">Text 4</li>
<li style="float:left;">Text 5</li>
</ul>
Updated
ul li[style="float:right;"] {
float: none !important;
padding-left: 100px;
}
This ensures that all float:right elements line up.
fiddle
Try to do it in this way https://jsfiddle.net/t2qmfkya/5/
<ul>
<li class="right-item" style="float:right;">Text 3</li>
<li class="right-item" style="float:right;">Text 4</li>
<li>Text 1</li>
<li>Text 2</li>
</ul>
ul {
width: 180px;
background: red;
padding: 1rem;
list-style: none;
overflow: hidden;
}
ul li {
overflow: hidden;
}
.right-item{
width: 51%;
}
Rearrange element and use clear both can handle this :
ul {
width: 180px;
background: red;
display: block;
float: left;
padding: 1rem;
list-style: none;
}
ul li {}
<ul>
<li style="float:left;">Text 1</li>
<li style="float:right;">Text 3</li>
<li style="clear:both;">Text 2</li>
</ul>
I'm trying to create a submenu in html/css. I already have a piece of code, but i would like to have a submenu in block below each menu item, but i can't figure out how to do it. Anyone would like to help?
.mainmenu {
margin-left: auto;
margin-right: auto;
}
.mainmenu ul {
width: 940px;
;
overflow: hidden;
font-family: 'swis721_btroman';
position: relative;
background-image: url(../img/01.png);
list-style: none;
font-size: 16px;
color: #000;
}
.mainmenu ul li {
float: left;
text-transform: uppercase;
font-family: 'swis721_btroman';
padding: 0 20px 0 20px;
display: table-column;
font-size: 16px;
color: #000;
}
.mainmenu ul li:first-child {
background: none;
}
.mainmenu ul li a {
float: left;
text-decoration: none;
padding: 9px 0 9px 0;
font-family: 'swis721_btroman';
font-weight: bold;
font-size: 16px;
color: #292F51;
}
.mainmenu ul li a:hover {
text-decoration: none;
color: #FFF;
overflow: hidden;
padding: 9px 9px 9px 9px;
position: relative;
background-color: #292F51;
}
.mainmenu ul ul {
list-style-type: none;
display: none;
}
.mainmenu ul:hover ul {
display: block;
position: relative;
}
<div class="mainmenu">
<ul>
<li class="operador chefe">
operador chefe
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="safety">
safety
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="security">
security
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="atendimento">
atendimento
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="apoio unidades comerciais">
apoio unidades comerciais
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
</ul>
</div>
Right now, when i hove over a menu item, all the submenu items appear at once, and in inline-block, which is not what i want.
You have two main problems here:
First this selector .mainmenu ul:hover ul it's wrong since is showing all ul elements when you hover the main ul.
Change to this:
.mainmenu li:hover > ul
Making visible just the sub ul element inside a li.
Also those submenus need to be absolute positioned so they don't disturb the layout of the upper menu:
.mainmenu ul li {
position:relative;
}
.mainmenu ul li > ul {
display: none;
position: absolute;
z-index:10;
}
Check this Snippet
.mainmenu ul {
padding:0;
width: 940px;
position: relative;
list-style: none;
font-size: 16px;
color: #000;
}
.mainmenu ul li {
float: left;
text-transform: uppercase;
padding: 0 20px 0 20px;
font-size: 16px;
color: #000;
position:relative;
}
.mainmenu ul li a {
display:block;
text-decoration: none;
padding: 9px 0 9px 0;
font-weight: bold;
font-size: 16px;
color: #292F51;
}
.mainmenu ul li a:hover {
text-decoration: none;
color: #FFF;
background-color: #292F51;
}
.mainmenu ul li > ul {
display: none;
position: absolute;
z-index:10;
}
.mainmenu li:hover > ul {
display: block;
}
<div class="mainmenu">
<ul>
<li class="operador chefe">
operador chefe
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="safety">
safety
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="security">
security
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="atendimento">
atendimento
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
<li class="apoio unidades comerciais">
apoio unidades comerciais
<ul>
<li>menu 1
</li>
<li>menu 2
</li>
<li>menu 3
</li>
<li>menu 4
</li>
<li>menu 5
</li>
</ul>
</li>
</ul>
</div>
This will work fine.
The most important rule is that when you hover a li it should show its child ul.
.main-menu,
.sub-menu {
font-size: 0px;
margin: 0px;
list-style: none;
padding: 0px;
font-family: 'Helvetica';
}
.sub-menu {
display: none;
}
.menu-item,
.sub-item {
background: navy;
color: white;
font-size: 14px;
text-align: center;
min-width: 80px;
padding: 4px;
}
.menu-item {
display: inline-block;
vertical-align: top;
}
.menu-item:hover,
.sub-item:hover {
background: blue;
}
.menu-item:hover > ul {
display: block;
}
<ul class="main-menu">
<li class="menu-item">Item 1</li>
<li class="menu-item">Item 2 (With sub-items!)
<ul class="sub-menu">
<li class="sub-item">Item 3</li>
<li class="sub-item">Item 4</li>
</ul></li>
<li class="menu-item">Item 5</li>
<li class="menu-item">Item 6 (With sub-items!)
<ul class="sub-menu">
<li class="sub-item">Item 7</li>
<li class="sub-item">Item 8</li>
</ul></li>
</ul>
I don't really like submenu coded from scratch (from zero). You can today create some menu "without" any CSS.
You can use Bootstrap class to realize menu like that:
http://jsfiddle.net/fm571dsd/4/
html:
<body>
<div class="container">
<div class="row">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#" target="_blank">Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="dropdown">
operador chefe
<ul class="dropdown-menu">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</li>
<li class="dropdown">
safety
<ul class="dropdown-menu">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</li>
<li class="dropdown">
security
<ul class="dropdown-menu">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</li>
<li class="dropdown">
atendimento
<ul class="dropdown-menu">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</li>
<li class="dropdown">
apoio unidades comerciais
<ul class="dropdown-menu">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
</div>
</body>
js:
(function($){
$(document).ready(function(){
$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
event.preventDefault();
event.stopPropagation();
$(this).parent().siblings().removeClass('open');
$(this).parent().toggleClass('open');
});
});
})(jQuery);