This is look I'm trying to achive
<ul>
<li class="btn">A</li>
<li class="btn" hidden>B</li>
<li class="btn" hidden>C</li>
<li >D</li>
<li >E</li>
</ul>
or it can be like this
<ul>
<li class="btn">A</li>
<li class="btn" hidden>B</li>
<li class="btn">C</li>
<li >D</li>
<li >E</li>
</ul>
and this too
<ul>
<li class="btn">A</li>
<li class="btn">B</li>
<li class="btn">C</li>
<li >D</li>
<li >E</li>
</ul>
I tried css first and last child it did not work. button set need to appear as a group and first and last element need to be rounded, in some cases, the button group might have only two buttons, or just one. any advice ?
ul li.btn:first-child {
padding-left: 7px;
border-radius: 50px 0px 0px 50px;
}
ul li.btn:last-child {
padding-right: 7px;
border-radius: 0px 50px 50px 0px;
}
You were on the right track. This is what you are looking for:
ul {
list-style: none;
display: flex;
}
li {
padding: 16px;
}
li.group {
background-color: lightgray;
}
li.first {
border-radius: 50% 0 0 50%;
}
li.last {
border-radius: 0 50% 50% 0;
}
<ul>
<li class="group first">A</li>
<li class="group">B</li>
<li class="group">C</li>
<li class="group">D</li>
<li class="group last">E</li>
<li>F</li>
<li>G</li>
</ul>
Edit If you do not want the first and last class, this is a workaround
NOTE: this only works in this specific case:
group of buttons is always at the start
there is only one group, no other elements in between
this actually moves element B to the back
ul {
list-style: none;
display: flex;
}
li {
padding: 16px;
}
li.group {
background-color: lightgray;
}
li.group:first-child {
border-radius: 50% 0 0 50%;
}
li.group~.group~.group {
border-radius: 0;
order: 0;
}
li.group~li.group {
border-radius: 0 50% 50% 0;
order: 1;
}
li:not(.group) {
order: 2;
}
<ul>
<li class="group">A</li>
<li class="group">B</li>
<li class="group">C</li>
<li class="group">D</li>
<li class="group">E</li>
<li>F</li>
<li>G</li>
</ul>
ul {
list-style: none;
display: flex;
}
li {
padding: 16px;
}
li.btn {
background-color: lightgray;
}
ul li.btn:first-child {
border-radius: 50% 0 0 50%;
}
ul li.btn:last-child {
border-radius: 0 50% 50% 0;
}
<ul>
<li class="btn">A</li>
<li class="btn" hidden >B</li>
<li class="btn">C</li>
<li >D</li>
<li >E</li>
</ul>
Do you want to group the list items no matter how many items available ?
i think this is what you need:
.group,
.list {
display: flex;
align-items: center;
}
.list>div:not(.group) {
padding: 5px;
}
.group>div {
padding: 5px;
border: 1px solid #ccc;
}
.group>div:first-child {
border-radius: 5px 0 0 5px;
}
.group>div:last-child {
border-radius: 0 5px 5px 0;
}
<div class="list">
<div class="group">
<div>A</div>
<div>B</div>
<div>C</div>
</div>
<div>D</div>
<div>E</div>
<div class="group">
<div>A</div>
<div>B</div>
<div>C</div>
</div>
<div>D</div>
<div>E</div>
</div>
Related
I'm trying to make a drop-down menu that opens by click. I am trying to use the target property how below for this, but in vain. Could someone suggest how to fix the code?
:target + .parent > ul {
display:block;
position:absolute;
z-index:9999;
}
.parent {
display: block;
position: relative;
float: left;
line-height: 30px;
background-color: black;
border-right: #CCC 1px solid;
}
.parent a {
margin: 10px;
color: #FFFFFF;
text-decoration: none;
}
:target + .parent > ul {
display:block;
position:absolute;
z-index:9999;
}
.child {
display: none;
}
.child li {
background-color: #E4EFF7;
line-height: 30px;
border-bottom: #CCC 1px solid;
border-right: #CCC 1px solid;
width: 100%;
background-color: black;
}
.child li a {
color: #FFF;
color: red;
}
ul {
list-style: none;
margin: 0;
padding: 0px;
min-width: 10em;
}
ul ul ul {
/* left: 100%;
top: 0;
margin-left:1px;
*/
}
li:hover {
background-color: red;
}
.parent li:hover {
background-color: #F0F0F0;
}
.expand {
font-size: 12px;
float: right;
margin-right: 5px;
color: red;
}
nav {
margin: 0 auto;
display: table;
text-align: center;
}
nav ul {
text-align: center;
}
<nav>
<ul id="menu">
<li class="parent">
CAT 1
<ul class="child">
<li class="parent">
<a href="#">Video Games <span class="expand">
▼</span></a>
<ul class="child">
<li>Car</li>
<li class="parent">
<a href="#">Bike Race<span class="expand">
▼</span></a>
<ul class="child">
<li>Yoyo</li>
<li>Doctor Kit</li>
</ul>
<li>Fishing</li>
</ul>
</li>
<li>Barbies</li>
<li>Teddy Bear</li>
<li>Golf Set</li>
</ul>
</li>
<li class="parent">
CAT 2
<ul class="child">
<li>Yoyo</li>
<li>Doctor Kit</li>
<li class="parent">
<a href="#">Fun Puzzle<span class="expand">
▼</span></a>
<ul class="child">
<li><a href="#" nowrap>Cards</a></li>
<li><a href="#" nowrap>Numbers</a></li>
</ul>
</li>
<li>Uno Cards</li>
</ul>
</li>
<li class="parent">CAT 3
<li class="parent">CAT 4
<li class="parent">CAT 5
<li class="parent">CAT 6
<li class="parent">
CAT 7
<ul class="child">
<li>Battery Toys</li>
<li class="parent">
<a href="#">Remote Toys <span class="expand">
▼</span></a>
<ul class="child">
<li>Cars</li>
<li>Aeroplane</li>
<li>Helicopter</li>
</ul>
</li>
<li>Soft Toys
</li>
<li>Magnet Toys</li>
</ul>
</li>
</ul>
</nav>
You need to reference your child element, which should be displayed on click, in your anchor by setting an ID like #child-1: CAT 1
Add child-1 as ID to your child element, so that your anchor and your child are "connected". <ul class="child" id="child-1">. Now this child element will be addressed by the :target selector, when the anchor is clicked
Since the target selector addresses the child-element, your CSS can look like this ul:target { ... }.
Note: Keep in mind that IDs must be unique for each anchor/child pair.
Source with an executable example: https://www.w3schools.com/cssref/sel_target.asp
Additional: You want to implement a nested dropdown in your code. I'm not sure if this nested behavior is possible to be implemented in pure CSS, because you can not address the parent element in CSS, and therefore you have no chance to keep the parent(s) displayed, while the child is shown. If someone has any idea, please let me know!
.parent {
display: block;
position: relative;
float: left;
line-height: 30px;
background-color: black;
border-right: #CCC 1px solid;
}
.parent a {
margin: 10px;
color: #FFFFFF;
text-decoration: none;
}
ul:target {
display:block;
position:absolute;
z-index:9999;
}
.child {
display: none;
}
.child li {
background-color: #E4EFF7;
line-height: 30px;
border-bottom: #CCC 1px solid;
border-right: #CCC 1px solid;
width: 100%;
background-color: black;
}
.child li a {
color: #FFF;
color: red;
}
ul {
list-style: none;
margin: 0;
padding: 0px;
min-width: 10em;
}
ul ul ul {
/* left: 100%;
top: 0;
margin-left:1px;
*/
}
li:hover {
background-color: red;
}
.parent li:hover {
background-color: #F0F0F0;
}
.expand {
font-size: 12px;
float: right;
margin-right: 5px;
color: red;
}
nav {
margin: 0 auto;
display: table;
text-align: center;
}
nav ul {
text-align: center;
}
<nav>
<ul id="menu">
<li class="parent">
CAT 1
<ul class="child" id="child-1">
<li class="parent">
<a href="#child-1-1">Video Games <span class="expand">
▼</span></a>
<ul class="child" id="child-1-1">
<li>Car</li>
<li class="parent">
<a href="#child-1-1-1">Bike Race<span class="expand">
▼</span></a>
<ul class="child" id="child-1-1-1">
<li>Yoyo</li>
<li>Doctor Kit</li>
</ul>
<li>Fishing</li>
</ul>
</li>
<li>Barbies</li>
<li>Teddy Bear</li>
<li>Golf Set</li>
</ul>
</li>
<li class="parent">
CAT 2
<ul class="child" id="child-2">
<li>Yoyo</li>
<li>Doctor Kit</li>
<li class="parent">
<a href="#child-2-1">Fun Puzzle<span class="expand">
▼</span></a>
<ul class="child" id="child-2-1">
<li><a href="#" nowrap>Cards</a></li>
<li><a href="#" nowrap>Numbers</a></li>
</ul>
</li>
<li>Uno Cards</li>
</ul>
</li>
<li class="parent">CAT 3
<li class="parent">CAT 4
<li class="parent">CAT 5
<li class="parent">CAT 6
<li class="parent">
CAT 7
<ul class="child" id="child-7">
<li>Battery Toys</li>
<li class="parent">
<a href="#child-7-1">Remote Toys <span class="expand">
▼</span></a>
<ul class="child" id="child-7-1">
<li>Cars</li>
<li>Aeroplane</li>
<li>Helicopter</li>
</ul>
</li>
<li>Soft Toys
</li>
<li>Magnet Toys</li>
</ul>
</li>
</ul>
</nav>
I have the following HTML
ul {
margin: 0;
padding: 0;
list-style: none;
font-size: 12px;
display: inline-block;
}
li {
display: inline-block;
padding: 0 5px;
}
.number {
float:right;
}
.rec {
float: left;
}
<div style="background-color: grey;">
<span style="font-size:16px">Text</span>
<ul>
<li>10</li>
<li>records</li>
</ul>
</div>
<br>
<div style="background-color: grey;">
<span style="font-size:16px">Text</span>
<ul>
<li class="number">10</li>
<li class="rec">records</li>
</ul>
</div>
When the list item floats, they move higher vertically, See this screenshot
Here is the jsfiddle link:
https://jsfiddle.net/mddc/d193a4v8/1/
How to make floating items remain the original position vertically?
You can adjust the line-height and reduce it to line-height: 8px for the property ul and it should align it properly as follows:
ul {
margin: 0;
padding: 0;
list-style: none;
font-size: 12px;
display: inline-block;
line-height: 8px;
}
li {
display: inline-block;
padding: 0 5px;
}
.number {
float:right;
}
.rec {
float: left;
}
<div style="background-color: grey;">
<span style="font-size:16px">Text</span>
<ul>
<li>10</li>
<li>records</li>
</ul>
</div>
<br>
<div style="background-color: grey;">
<span style="font-size:16px">Text</span>
<ul>
<li class="number">10</li>
<li class="rec">records</li>
</ul>
</div>
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>
I'm tring to make a simple drop-down menu, which would be triggered on hover event over some element and stay active as long as the cursor is over that element or is over the dropdown list.
Sample code:
HTML
<div class="header">
<div class="items">
<div class="item">
<span>Caption</span>
</div>
<ul class="items_hidden">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
</div>
<input type="text">
CSS
.items {
float: right;
position: relative;
}
.item {
text-align: right;
}
.items_hidden {
display: none;
margin-top: 7px;
list-style: none;
z-index: 2000;
width: 80px;
border: 1px solid #f2f2f2;
text-align: left;
padding: 10px;
color: #333;
line-height: 30px;
border-bottom: 3px solid #f2f2f2;
}
input {
width: 100%;
}
JS
$(function() {
$('.items').on('mouseenter', function(e) {
$('.items_hidden').show();
});
$('.items').on('mouseleave', function(e) {
$('.items_hidden').hide();
});
});
I got that working, when the dropdown list is positioned relative, but the problem is once the list is displayed, it causes all following content to move down.
Here is an example: https://jsfiddle.net/2ya06aLo/
Another way would be to position the list absolute, so it wouldn't affect the content below. But in that case the list disappears as soons as I move the cursor out of 'Caption' (in contrast with the first fiddle).
Here is the second example https://jsfiddle.net/8L6ojqLm/
What would be a solution to make the list behave like in 1 and at the same time do not affect the rest of the content like in 2 ?
You can don't use JS
Example
.items {
float: right;
position: relative;
}
.item {
text-align: right;
padding: 10px;
}
.items_hidden {
position: absolute;
right: 0;
top: 20px;
display: none;
margin-top: 7px;
list-style: none;
z-index: 2000;
width: 80px;
border: 1px solid #f2f2f2;
text-align: left;
padding: 10px;
color: #333;
line-height: 30px;
border-bottom: 3px solid #f2f2f2;
}
input {
width: 100%;
}
.items:hover .items_hidden{
display: block;
}
<div class="header">
<div class="items">
<div class="item">
<span>Caption</span>
</div>
<ul class="items_hidden">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
</div>
<input type="text">
Live JSFiddle - https://jsfiddle.net/grinmax_/8L6ojqLm/1/
Couldn't it be done via pure css?
https://www.w3schools.com/howto/howto_css_dropdown.asp
Maybe this would help.
.navigation {
width: 100%;
}
.mainmenu, .submenu {
list-style: none;
padding: 0;
margin: 0;
}
.mainmenu a {
}
.mainmenu a:hover {
background-color: #D90000;
}
.mainmenu li:hover .submenu {
display: block;
max-height: 400px;
}
.submenu{
max-height: 400px;
}
.submenu a {
background-color: #FF4D4D;
}
.submenu a:hover {
background-color: #D90000;
}
.submenu{
overflow:hidden;
display:none;
}
<nav class="navigation"><!-- pocetak navigacije -->
<ul class="mainmenu">
<li>Link</li>
<li class="start">Link
<ul class="submenu">
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</li>
<li>Home</li>
</ul>
</nav>
To take up the comment of CBroe: The problem seems to be the "gap" between the and the element. To remove it you could either
give the "item"-Element a height so that it "reaches down" to the ul-element or
or remove the margin-top of the ul-element
When the menu "product" is clicked or mouse over, the another list of menus appear.. but the image block which is below the menu bar, moves away from the position. if i use css [ position:absolute;], then the image box remains static and the product's sub-menu overlaps the image block, which is what i wanted. but the image blocks width & height settings change drastically, thereby spoiling the alignment.
pls chk the codings in jsFiddle
.home_menu {
border: 1px solid black;
width: 98%;
height: 3.3%;
margin-right: auto;
margin-left: auto;
}
div#menuDemo {
clear: both;
//border:1px solid black;
height: 78%;
width: 100%;
position: relative;
left: 0;
top: 0;
background-color: #A55927;
/*Remove this next one in production - Used for demo purpose only*/
margin-bottom: 0.1%;
padding-top: 0.7%;
z-index: 4;
}
div#menuDemo ul {
list-style: none;
margin: 0;
padding: 0;
background-color: #A55927;
}
div#menuDemo > ul > li {
float: left;
text-align: center;
}
div#menuDemo ul li {
width: 25%;
//border: 5px solid purple;
}
div#menuDemo ul li a {
text-decoration: none;
font-weight: bolder;
text-align: center;
}
div#menuDemo > ul > li > ul {
display: none;
text-align: center;
}
div#menuDemo > ul > li:hover > ul {
display: block;
text-align: center;
}
.sub1 {
width: 100%;
//border:1px solid green;
}
.colouring {
color: black;
font-weight: bolder;
}
.colour {
//border:1px solid blue;
color: black;
text-align: center;
//width:100%;
}
.wrapper {
border: 5px solid pink;
width: 98.8%;
height: 82%;
margin-top: 1%;
z-index: 2;
}
.uniform_block {
border: 5px solid green;
width: 100%;
height: 40%;
cursor: pointer;
}
.uniform_block img {
width: 100%;
height: 100%;
}
<body>
<div class="home_menu">
<div id="menuDemo">
<ul>
<li id="homeMenu">About Us
</li>
<!-- <li >About Us</li> -->
<li>Products
<ul class="sub1">
<li> Uniforms
<ul>
<li>  
</li>
<li> Automobile Industry Uniforms
</li>
<li> Pharmaceutical Uniforms
</li>
<li> Food Industry Uniforms
</li>
<li> Government Sector Uniforms
</li>
<li> School/College Uniforms
</li>
<li>  
</li>
</ul>
</li>
<li>Shoes
<ul>
<li>  
</li>
<li> Industrial Shoes
</li>
<li> Safety & Security Shoes
</li>
<li> Executive Shoes
</li>
<li>  
</li>
</ul>
</li>
</ul>
</li>
<li>Contact Us
</li>
</ul>
</div>
</div>
<div class="wrapper">
<div class="uniform_block">
<img src=" http://t0.gstatic.com/images?q=tbn:ANd9GcSH-kRi3rkVciPcH_c6dDJJI6C1ntzwcKl9MoVQIyuKk8F7unpf" />
</div>
<div class="home_footer">
<div class="footer_contents"></div>
</div>
</div>
</body>
kindly help. My requirement is, when i mouse over the "product menu", the drop down menu should be viewed above the image block which is below the menu bar.
Add position:absolute to the css of your ul menu (in your case, the sub1 class), and remove the width:100% so it can inherit the default width of its parent. Absolute positioning will prevent your browser from trying to put your ul element after the previous element on the page.
ul.sub1 {
position:absolute;
}
http://jsfiddle.net/C2YXp/2/