Please consider the following code snippet.
My question is: why is the second li, the one with class filterdivision, lower in the layout than the previous one instead of being verticaly aligned with it ? I gave it the same height and see no margin or padding that might push it down.
Javascript code isn't relevant to the question but allows the snippet to be functional.
var triggerFilter = function(filterData)
{
console.log(filterData);
}
$(".customDropdown li").on('click',function(){
var $self = $(this);
var $list = $self.parent();
if($list.hasClass("listVisible"))
{ //Whole list is visible => Selecting an option
$list.find('.active').removeClass("active");
$self.addClass("active");
$list.removeClass("listVisible");
triggerFilter({filterName:$list.data("fieldname"),filterValue:$self.data("fieldvalue")});
}
else
{
//Show whole list
$list.addClass("listVisible");
}
});
.wrapper { background: #f2f2f2;; padding: 20px;position: relative;height:60px;}
.wrapper input { box-sizing: border-box; border: 1px solid #c2c2c2; font-size: 14px; padding: 10px 15px; width: 100%;}
.wrapper ol.filters { padding:0; margin: 0; font-size: 0; height:58px;}
.wrapper ol.filters > li
{
list-style-type: none;
display: inline-block;
width: 150px;
margin-right:20px;
height: 58px;/*Need to fix height because of absolute positionned fake dropdowns*/
position:relative;
}
.wrapper ol.filters > li:last-child{ margin-right:0;}
.wrapper ol.filters > li:first-child{ width: 150px;}
.wrapper label { display:block; font-size:12px; color: #797979; margin-bottom: 3px;}
/* CSS for custom dropdown */
.customDropdown {
position:absolute;
z-index: 50;
padding:0;
margin:0;
list-style-type: none;
background: #fff;
border: 1px solid #c2c2c2;
cursor: pointer;
width:150px;
}
.customDropdown li {display:none;padding: 10px 15px;font-size:14px;}
.customDropdown li::after { position: absolute; top: 10px; right: 10px; content: ""; display: inline-block; width: 0.5em; height: 0.5em; border-right: 2px solid black; border-bottom: 2px solid black; transform: rotate(45deg);}
.customDropdown li.active {display:block;}
.customDropdown.listVisible li {display:block;border-bottom: 1px solid #f2f2f2;}
.customDropdown.listVisible li:hover {background: #f2f2f2;color:#4fbbeb;}
.customDropdown.listVisible li.active {color:#4fbbeb;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<ol class="filters">
<li class="filterSearch">
<label for="filterSearch">Search</label><input type="text" id="search">
</li>
<li class="filterDivision">
<label>Division</label>
<ol class="customDropdown" data-fieldname="division">
<li class="active" data-fieldvalue="all">All divisions</li>
<li data-fieldvalue="consulting">Consulting</li>
<li data-fieldvalue="digital">Digital</li>
<li data-fieldvalue="other">Other</li>
</ol>
</li>
<!-- ... Other filter options in li tags -->
</ol>
</div>
Try using
float:left
instead of
display:inline-block
in
.wrapper ol.filters > li
Although this doesn't seem to be an issue here, floating elements wont affect the parent elements height, unless you add
clear:both;
overflow:auto;
to the parent elements style like this:
<div style="clear:both; overflow:auto">
<div style="float:left">hello</div>
<div style="float:left">world</div>
</div>
here's you code snippet using floating elements (I'm not sure what's causing your issue exactly, but floating left fixes it)
var triggerFilter = function(filterData)
{
console.log(filterData);
}
$(".customDropdown li").on('click',function(){
var $self = $(this);
var $list = $self.parent();
if($list.hasClass("listVisible"))
{ //Whole list is visible => Selecting an option
$list.find('.active').removeClass("active");
$self.addClass("active");
$list.removeClass("listVisible");
triggerFilter({filterName:$list.data("fieldname"),filterValue:$self.data("fieldvalue")});
}
else
{
//Show whole list
$list.addClass("listVisible");
}
});
.wrapper { background: #f2f2f2;; padding: 20px;position: relative;height:60px;}
.wrapper input { box-sizing: border-box; border: 1px solid #c2c2c2; font-size: 14px; padding: 10px 15px; width: 100%;}
.wrapper ol.filters { padding:0; margin: 0; font-size: 0; height:58px;}
.wrapper ol.filters > li
{
list-style-type: none;
float:left;
width: 150px;
margin-right:20px;
height: 58px;/*Need to fix height because of absolute positionned fake dropdowns*/
position:relative;
}
.wrapper ol.filters > li:last-child{ margin-right:0;}
.wrapper ol.filters > li:first-child{ width: 150px;}
.wrapper label { display:block; font-size:12px; color: #797979; margin-bottom: 3px;}
/* CSS for custom dropdown */
.customDropdown {
position:absolute;
z-index: 50;
padding:0;
margin:0;
list-style-type: none;
background: #fff;
border: 1px solid #c2c2c2;
cursor: pointer;
width:150px;
}
.customDropdown li {display:none;padding: 10px 15px;font-size:14px;}
.customDropdown li::after { position: absolute; top: 10px; right: 10px; content: ""; display: inline-block; width: 0.5em; height: 0.5em; border-right: 2px solid black; border-bottom: 2px solid black; transform: rotate(45deg);}
.customDropdown li.active {display:block;}
.customDropdown.listVisible li {display:block;border-bottom: 1px solid #f2f2f2;}
.customDropdown.listVisible li:hover {background: #f2f2f2;color:#4fbbeb;}
.customDropdown.listVisible li.active {color:#4fbbeb;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<ol class="filters">
<li class="filterSearch">
<label for="filterSearch">Search</label><input type="text" id="search">
</li>
<li class="filterDivision">
<label>Division</label>
<ol class="customDropdown" data-fieldname="division">
<li class="active" data-fieldvalue="all">All divisions</li>
<li data-fieldvalue="consulting">Consulting</li>
<li data-fieldvalue="digital">Digital</li>
<li data-fieldvalue="other">Other</li>
</ol>
</li>
<!-- ... Other filter options in li tags -->
</ol>
</div>
Inline blocks are blocks that try to span the entire width and in your code, the .wrapper didn't have the width set, which forced it to take up space beside, and not below
var triggerFilter = function(filterData)
{
console.log(filterData);
}
$(".customDropdown li").on('click',function(){
var $self = $(this);
var $list = $self.parent();
if($list.hasClass("listVisible"))
{ //Whole list is visible => Selecting an option
$list.find('.active').removeClass("active");
$self.addClass("active");
$list.removeClass("listVisible");
triggerFilter({filterName:$list.data("fieldname"),filterValue:$self.data("fieldvalue")});
}
else
{
//Show whole list
$list.addClass("listVisible");
}
});
.wrapper { background: #f2f2f2;; padding: 20px;position: relative;height:150px; width: 60px}
.wrapper input { box-sizing: border-box; border: 1px solid #c2c2c2; font-size: 14px; padding: 10px 15px; width: 100%;}
.wrapper ol.filters { padding:0; margin: 0; font-size: 0; height:116px;}
.wrapper ol.filters > li
{
list-style-type: none;
display: inline-block;
width: 150px;
margin-top: 10px;
margin-right:20px;
height: 58px;/*Need to fix height because of absolute positionned fake dropdowns*/
position:relative;
}
.wrapper ol.filters > li:last-child{ margin-right:0;}
.wrapper ol.filters > li:first-child{ width: 150px;}
.wrapper label { display:inline-block; font-size:12px; color: #797979; margin-bottom: 3px;}
/* CSS for custom dropdown */
.customDropdown {
position:absolute;
z-index: 50;
padding:0;
margin:0;
list-style-type: none;
background: #fff;
border: 1px solid #c2c2c2;
cursor: pointer;
width:150px;
}
.customDropdown li {display:none;padding: 10px 15px;font-size:14px;}
.customDropdown li::after { position: absolute; top: 10px; right: 10px; content: ""; display: inline-block; width: 0.5em; height: 0.5em; border-right: 2px solid black; border-bottom: 2px solid black; transform: rotate(45deg);}
.customDropdown li.active {display:block;}
.customDropdown.listVisible li {display:block;border-bottom: 1px solid #f2f2f2;}
.customDropdown.listVisible li:hover {background: #f2f2f2;color:#4fbbeb;}
.customDropdown.listVisible li.active {color:#4fbbeb;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<ol class="filters">
<li class="filterSearch">
<label for="filterSearch">Search</label><input type="text" id="search">
</li>
<li class="filterDivision">
<label>Division</label>
<ol class="customDropdown" data-fieldname="division">
<li class="active" data-fieldvalue="all">All divisions</li>
<li data-fieldvalue="consulting">Consulting</li>
<li data-fieldvalue="digital">Digital</li>
<li data-fieldvalue="other">Other</li>
</ol>
</li>
<!-- ... Other filter options in li tags -->
</ol>
</div>
Related
Trying to make the background for the "Submit Assignment" button green. Our website is http://www.stephensengineering.com/stephens33/. Solved the issue with the borders and now i need to make the background of the one menu item green. I tried adding css but still no luck.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Horizontal Navigation Bar w/Rollover Effect</title>
<style type="text/css">
<!--
#navbar ul {
margin: 0;
padding: 10px;
list-style-type: none;
text-align: right;
background-color: #000;
}
#navbar ul li {
display: inline;
}
#navbar ul li a {
font-family: 'Montserrat';
text-decoration: bold;
padding: .2em 1em;
color: #fff;
background-color: #000;
}
#navbar ul li a:hover {
color: #000;
background-color: #fff;
}
#navbar{
position: fixed;
z-index: 100000; /*To bring the navbar to the top of the stacking context*/
width: 100%;
}
nav.stricky-fixed.fadeInDown.animated{
top:40px; /*Since this element is already set as relative in the original code,
the top property places the slideIn menu 40px (height of black nav menu)
from the top of the page.*/
}
.social-icon-wrapper:hover {
background-color: transparent !important;
}
.social-icon {
width: 20px;
vertical-align: top;
}
-->
</style>
</head>
<body>
<div id="navbar">
<ul>
<li style="float:left"><a class="social-icon-wrapper" href="#about"><img class="social-icon" src="https://i.imgur.com/tonPA8V.png"></a></li>
<li style="float:left"><a class="social-icon-wrapper" href="#about"><img class="social-icon" src="https://i.imgur.com/fEvitJl.png"></a></li>
<li style="float:left"><a class="social-icon-wrapper" href="#about"><img class="social-icon" src="https://i.imgur.com/UiwMSrt.png"></a></li>
<li>project#stephensengineering.com</li>
<li>888-300-0642</li>
<li>Stephens University</li>
<li>Submit Assignment</li>
</ul>
</div>
</body>
</html>
#MercedesPennell here's the revised solution. Hope it will meet your requirement.
#navbar ul {
height: inherit;
margin: 0;
list-style-type: none;
text-align: right;
background-color: #000;
}
#navbar ul li {
display: inline-block;
padding: 10px 5px;
height: inherit;
border-left: 1px solid #fff;
}
#navbar ul li a {
font-family: 'Montserrat';
text-decoration: bold;
padding: .2em 1em;
color: #fff;
/* background-color: #000; */
}
#navbar ul li:hover {
background-color: #fff;
}
#navbar ul li:hover a {
color: #000 !important;
}
#navbar{
position: fixed;
z-index: 100000; /*To bring the navbar to the top of the stacking context*/
width: 100%;
}
nav.stricky-fixed.fadeInDown.animated{
top:40px; /*Since this element is already set as relative in the original code,
the top property places the slideIn menu 40px (height of black nav menu)
from the top of the page.*/
}
.social-icon-wrapper:nth-child(3) {
border-right: 1px solid #fff;
}
.social-icon-wrapper:hover {
background-color: transparent !important;
}
.social-icon {
width: 20px;
vertical-align: top;
}
.submit-btn {
background-color: green !important;
border-left: none !important;
}
<!-- -->
<div id="navbar">
<ul>
<li class="social-icon-wrapper" style="float:left"><img class="social-icon" src="https://i.imgur.com/tonPA8V.png"></li><!-- --><li class="social-icon-wrapper" style="float:left"><img class="social-icon" src="https://i.imgur.com/fEvitJl.png"></li><!-- --><li class="social-icon-wrapper" style="float:left"><img class="social-icon" src="https://i.imgur.com/UiwMSrt.png"></li><!-- --><li>project#stephensengineering.com</li><!-- --><li>888-300-0642</li><!-- --><li>Stephens University</li><!-- --><li class="submit-btn" >Submit Assignment</li>
</ul>
</div>
Here's my solution. I made several changes in html and css files. Hope it will work for you.
#navbar ul {
height: inherit;
margin: 0;
list-style-type: none;
text-align: right;
background-color: #000;
}
#navbar ul li {
display: inline-block;
padding: 10px 5px;
height: inherit;
border-left: 1px solid #fff;
}
#navbar ul li a {
font-family: 'Montserrat';
text-decoration: bold;
padding: .2em 1em;
color: #fff;
/* background-color: #000; */
}
#navbar ul li:hover {
background-color: #fff;
}
#navbar ul li:hover a {
color: #000 !important;
}
#navbar{
position: fixed;
z-index: 100000; /*To bring the navbar to the top of the stacking context*/
width: 100%;
}
nav.stricky-fixed.fadeInDown.animated{
top:40px; /*Since this element is already set as relative in the original code,
the top property places the slideIn menu 40px (height of black nav menu)
from the top of the page.*/
}
.social-icon-wrapper:nth-child(3) {
border-right: 1px solid #fff;
}
.social-icon-wrapper:hover {
background-color: transparent !important;
}
.social-icon {
width: 20px;
vertical-align: top;
}
<!-- -->
<div id="navbar">
<ul>
<li class="social-icon-wrapper" style="float:left"><img class="social-icon" src="https://i.imgur.com/tonPA8V.png"></li><!-- --><li class="social-icon-wrapper" style="float:left"><img class="social-icon" src="https://i.imgur.com/fEvitJl.png"></li><!-- --><li class="social-icon-wrapper" style="float:left"><img class="social-icon" src="https://i.imgur.com/UiwMSrt.png"></li><!-- --><li>project#stephensengineering.com</li><!-- --><li>888-300-0642</li><!-- --><li>Stephens University</li><!-- --><li>Submit Assignment</li>
</ul>
</div>
Just simply add a CSS outline property, like outline: 3px solid red;, to your #navbar ul li selector. The border will make overlapping borders around each navigation link. To make your Submit Assignment button green, add style="background-color: green" to the respective li element.
To make the "Submit Assignment" button green i added a class:
<li><a class="active" href="http://github.com">Submit Assignment</a></li>
in this example i use "active" as the class and add the following CSS
.active {
padding: 10px;
background-color: green;
color: beige;
text-decoration: none;
}
And for the border, i added "border-left" to archieve what you want
#navbar ul li {
display: inline;
border-left: #fff 1px solid;
}
#navbar ul li a {
font-family: 'Montserrat';
text-decoration: bold;
padding: .2em 1em;
color: #fff;
padding: 10px;
/*background-color: #000;*/
}
as you can see in the bottom code i create li to make list instead select option in html tag. but i get undesirable thing in appearance.
how to make li width same like bottom width. i have added value of width in css. the value 100% make li wider than bottom.
how tom make caret and number inside li position float in right. i can add class pull-rigt to make it in right position but it make caret higher than text in left position (i want make them in same middle vertical position)
.instead-option {
z-index:999;
position: absolute;
margin: 0;
max-height:300px;
background: #ffffff;
border-radius:4px;
border:1px solid #dddddd;
width:100%;
overflow:auto;
}
.instead-option > li {
width:100%;
background: #eee;
line-height: 25px;
font-size: 14px;
padding: 0 10px;
cursor: pointer;
}
.instead-option > li > a{
display: flex;
width: 100%;
}
.instead-option > li:nth-child(odd) {
background-color: #ffffff;
}
.instead-option > li:nth-child(even) {
background-color: #e5e5e5;
}
.instead-option > li:hover {
background: #aaa;
}
.instead-option > li > a{
color:#232323;
text-decoration:none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-12">
<button type="button" class="form-control text-left nominal">Pilih nominal<span class="caret caret-right"></span></button>
<ul class="instead-option list-unstyled">
<li>English <span class="text-primary pull-right">10000</span></li>
<li>Deutsch <span class="text-primary pull-right">50000</span></li>
</ul>
</div>
</div>
</div>
Since you have position: absolute; on .instead-option element, you can have another element wrapping with position: relative;.
You can use a small hack to position the caret both horizontally and vertically by using top: 50%; rule.
.instead-option {
z-index: 999;
position: absolute;
margin: 0;
max-height: 300px;
background: #ffffff;
border-radius: 4px;
border: 1px solid #dddddd;
width: 100%;
overflow: auto;
}
.instead-option > li {
width: 100%;
background: #eee;
line-height: 25px;
font-size: 14px;
padding: 0 10px;
cursor: pointer;
}
.instead-option > li > a {
display: block;
width: 100%;
}
.instead-option > li:nth-child(odd) {
background-color: #ffffff;
}
.instead-option > li:nth-child(even) {
background-color: #e5e5e5;
}
.instead-option > li:hover {
background: #aaa;
}
.instead-option > li > a {
color: #232323;
text-decoration: none;
}
.dropdown-container {
position: relative;
}
.dropdown-container .caret {
position: absolute;
/* Have the same padding to right as in the button*/
right: 12px;
/* Position the element from top by 50% of the parent element's height */
top: 50%;
/* Moves the element from its current position by -50% on Y axis to position the element vertically middle*/
transform: translateY(-50%);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="dropdown-container">
<button type="button" class="form-control text-left nominal">Pilih nominal<span class="caret caret-right"></span>
</button>
<ul class="instead-option list-unstyled">
<li>English <span class="text-primary pull-right">10000</span>
</li>
<li>Deutsch <span class="text-primary pull-right">50000</span>
</li>
</ul>
</div>
</div>
</div>
</div>
You're using position:absolute on the .instead-option list. As such, width:100% is calculated independent of the containing div's padding value.
You can fix this by changing your css to match the padding on the col div
.instead-option {
z-index:999;
position: absolute;
margin: 0;
max-height:300px;
background: #ffffff;
border-radius:4px;
border:1px solid #dddddd;
/* width:100%; */ /* REMOVE THIS LINE */
overflow:auto;
left:15px; /* matches column left padding */
right:15px; /* matches column right padding */
}
Below is your answer. Fixed both points, See additional css added at the end of css code .
.instead-option {
z-index: 999;
position: absolute;
margin: 0;
max-height: 300px;
background: #ffffff;
border-radius: 4px;
border: 1px solid #dddddd;
width: 100%;
overflow: auto;
}
.instead-option > li {
width: 100%;
background: #eee;
line-height: 25px;
font-size: 14px;
padding: 0 10px;
cursor: pointer;
}
.instead-option > li > a {
display: flex;
width: 100%;
}
.instead-option > li:nth-child(odd) {
background-color: #ffffff;
}
.instead-option > li:nth-child(even) {
background-color: #e5e5e5;
}
.instead-option > li:hover {
background: #aaa;
}
.instead-option > li > a {
color: #232323;
text-decoration: none;
}
/*Additional Css*/
.instead-option {
width: calc(100% - 30px)
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-12">
<button type="button" class="form-control text-right nominal">
<span class="pull-left">Pilih nominal</span><span class="caret caret-right"></span>
</button>
<ul class="instead-option list-unstyled">
<li>English <span class="text-primary pull-right">10000</span>
</li>
<li>Deutsch <span class="text-primary pull-right">50000</span>
</li>
</ul>
</div>
</div>
</div>
I'm trying to make a responsive menu for the cellphone-size.
What I want is a collapseable navigation-menu, for example:
(not expanding) BUTTON A
(not expanding) BUTTON B
(expandable) BUTTON C
BUTTON C option A
So when you see the menu first, you only see button A,B and C.
When you click on Button C, below it appears (by clicking on it) the option A.
What I have so far is a button with a three-lines nav icon.
When you click on it, you see button a,b,c .
But when you click on Button c, the whole list collapse back, and when re-opening, you see the full list. This is not what I had in mind...
My coding:
HTML
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$(".text").hide();
$(".accordeon div:first-child").addClass("expand_first");
$(".expand").click(function() {
$(".text").slideUp(500);
if ($(this).next(".text").is(":visible")) {
$(this).next(".text").slideUp(500);
} else {
$(this).next(".text").slideToggle(500);
}
});
});
$(window).load(function() {
$('.flexslider').flexslider();
});
$('ul li a').click(function() {
$(this).parent().find('ul.sub-menu').toggle();
return false;
});
</script>
<div id="nav-small">
<div class="accordeon">
<div class="expand"><img src="http://localhost:8080/wordpress/wp-content/uploads/2016/06/navicon.png" alt="Navigation" width="50%" height="auto" />
Navigation
</div>
<div class="text">
<ul>
<li>Home</li>
<li>Library</li>
<li class="sub-menu">Lifestyle▼
<ul>
<li>Cleaning & Organizing</li>
<li>Health & Beauty</li>
<li>Travel</li>
</ul>
</li>
</ul>
</div></div></div>
My CSS:
#nav-small{
width:100%;
height:auto;
}
#nav-small img{
width:50%;
max-width:30px;
max-height:30px;
}
#nav-small ul{
list-style:none;
padding:0;
margin:0;
font-family:verdana;
}
#nav-small ul li{
text-align:center;
text-decoration:none;
padding: 2% 0;
border-bottom:1px solid black;
}
#nav-small ul li a{
text-decoration:none;
}
#nav-small ul li.sub-menu{
border-bottom:none;
padding-bottom:0;
}
.accordeon{
text-align:center;
background-color: rgba(104,144,192,1.00) ;
width:100%;
}
.accordeon .expand {
display:inline-block;
width:30%;
height:auto;
margin:auto;
font-family: Verdana;
background-color: rgba(104,144,192,1.00) ;
cursor:pointer;
padding:1% 0;
border-left:1px solid #ccc;
border-right:1px solid #ccc;
}
.accordeon .text{
display:none;
float:left;
width:100%;
height:auto;
margin:auto;
border-top:0px;
border-bottom:1px solid #ccc;
background-color: rgba(211,196,213,1.00);
text-align:left;
}
SOLUTION:
Wrap your icon in a span to add a selector and add a click event listener to it.
Also I added a class that uses display: none for your nested ul.
JSFiddle
CODE SNIPPET:
$(document).ready(function() {
$(".text").hide();
$(".accordeon div:first-child").addClass("expand_first");
$(".expand").click(function() {
$(".text").slideUp(500);
if ($(this).next(".text").is(":visible")) {
$(this).next(".text").slideUp(500);
} else {
$(this).next(".text").slideToggle(500);
}
});
$("#trigger").on("click", function() {
$(".sub-menu > ul").slideToggle(500, function() {
$(this).toggleClass("is-not-visible");
});
});
});
$(window).load(function() {
$('.flexslider').flexslider();
});
$('ul li a').click(function() {
$(this).parent().find('ul.sub-menu').toggle();
return false;
});
#nav-small {
width: 100%;
height: auto;
}
#nav-small img {
width: 50%;
max-width: 30px;
max-height: 30px;
}
#nav-small ul {
list-style: none;
padding: 0;
margin: 0;
font-family: verdana;
}
#nav-small ul li {
text-align: center;
text-decoration: none;
padding: 2% 0;
border-bottom: 1px solid black;
}
#nav-small ul li a {
text-decoration: none;
}
.accordeon {
text-align: center;
background-color: rgba(104, 144, 192, 1.00);
width: 100%;
}
.accordeon .expand {
display: inline-block;
width: 30%;
height: auto;
margin: auto;
font-family: Verdana;
background-color: rgba(104, 144, 192, 1.00);
cursor: pointer;
padding: 1% 0;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
}
.accordeon .text {
display: none;
float: left;
width: 100%;
height: auto;
margin: auto;
border-top: 0px;
border-bottom: 1px solid #ccc;
background-color: rgba(211, 196, 213, 1.00);
text-align: left;
}
.is-not-visible {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="nav-small">
<div class="accordeon">
<div class="expand"><img src="http://placehold.it/100x100" alt="Navigation" width="50%" height="auto" /> Navigation
</div>
<div class="text">
<ul>
<li>Home</li>
<li>Library</li>
<li class="sub-menu">Lifestyle <span id="trigger">▼</span>
<ul class="is-not-visible">
<li>Cleaning & Organizing</li>
<li>Health & Beauty</li>
<li>Travel</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
I'm trying to have these small left and right borders either side of the text. Here is what I'm trying to make:
http://imgur.com/xCZnGgJ
My problem is that the borders are not the same height of the surrounding div however they only go the same height of the text. Here is a screen shot:
http://imgur.com/I2jjsAm
I have dried adding height: 30px to the li and ul however this does not change anything.
*{margin:0;}
#header {
width:100%;
}
#pre_header {
width:100%;
height:30px;
background-color:#202020;
}
.pre_header_content {
margin:0 auto;
width:1040px;
}
#pre_header ul {
list-style-type: none;
margin: 0;
padding: 0;
line-height:30px;
}
#pre_header li {
display: inline;
border-right: .5px solid #414141;
border-left: .5px solid #414141;
}
#pre_header a {
text-decoration:none;
color:#fff;
padding:6px 15px 6px 15px;
}
#pre_header a:hover {
background-color:#4e4e4e;
}
<div id="header">
<div id="pre_header">
<div class="pre_header_content">
<ul>
<li>Voucher codes</li>
<li>In-store codes</li>
<li>Online codes</li>
<li>Free samples</li>
<li>Advertise</li>
</ul>
</div>
</div>
<div id="main_header">
<div class="main_header_content">
Test
</div>
</div>
</div>
If anyone knows is there also anyway to bring the two borders together closer also?
Add the padding:6px 15px 6px 15px; to the li instead of a. And also, 0.5px does not work. What's half a pixel? Updated your code. See below!
EDIT: Note: I also changed your hover effect to affect the li element instead of a.
*{
margin:0;
box-sizing: border-box;
}
#header {
width:100%;
}
#pre_header {
width:100%;
height:30px;
background-color:#202020;
}
.pre_header_content {
margin:0 auto;
width:1040px;
}
#pre_header ul {
list-style-type: none;
margin: 0;
padding: 0;
line-height:30px;
}
#pre_header li {
display: inline;
border-right: 1px solid #414141;
border-left: 1px solid #414141;
padding: 0 15px;
float:left;
margin-right: 2px;
}
#pre_header li:last-child{
margin-right: 0;
}
#pre_header a {
text-decoration:none;
color:#fff;
}
#pre_header li:hover {
background-color:#4e4e4e;
}
<div id="header">
<div id="pre_header">
<div class="pre_header_content">
<ul>
<li>Voucher codes</li>
<li>In-store codes</li>
<li>Online codes</li>
<li>Free samples</li>
<li>Advertise</li>
</ul>
</div>
</div>
<div id="main_header">
<div class="main_header_content">
Test
</div>
</div>
</div>
You could simply change the li to display: inline-block; I've created a jsfiddle for you.
#pre_header li {
display: inline-block;
border-right: 1px solid #414141;
border-left: 1px solid #414141;
}
Also, don't use .5px, use a single amount. I have used 1px.
http://jsfiddle.net/xeqsn83a/
If you want the borders to touch, you would need to float it. And as others have mentioned, your border width needs to be an actual pixel size. There is no such thing as .5px. Here is an example of what (I think) you are trying to do:
http://jsfiddle.net/tuc4Lwuu/
#pre_header li {
float: left;
border-right: 1px solid #414141;
border-left: 1px solid #414141;
margin-right: 2px;
}
Try this:
* {
margin: 0;
}
#header {
width: 100%;
}
#pre_header {
width: 100%;
height: 30px;
background-color: #202020;
}
.pre_header_content {
margin: 0 auto;
width: 1040px;
}
#pre_header ul {
list-style-type: none;
margin: 0;
padding: 0;
font-size: 0;
}
#pre_header li {
display: inline-block;
border-right: 1px solid #414141;
border-left: 1px solid #414141;
margin-right: 1px;
}
#pre_header a {
text-decoration: none;
color: #fff;
padding: 6px 15px 6px 15px;
font-size: 16px;
line-height: 30px;
}
#pre_header a:hover {
background-color: #4e4e4e;
}
<div id="header">
<div id="pre_header">
<div class="pre_header_content">
<ul>
<li>Voucher codes</li>
<li>In-store codes</li>
<li>Online codes</li>
<li>Free samples</li>
<li>Advertise</li>
</ul>
</div>
</div>
<div id="main_header">
<div class="main_header_content">
Test
</div>
</div>
</div>
I changed display: inline to inline-block for li and border-width to 1px (it has to be an integer). Also made li items closer to each other with font-size: 0 technique (read this article for understanding).
I have a ul with two columns (of lis). I'm trying to make a visible separation between the two columns, but I can't get it to work. The goal is to make each li have a bottom-color line, but make those lines separated.
This is what I currently have: http://codepen.io/anon/pen/JeluB
HTML
<ul id="double">
<li>asdas</li>
<li>eee</li>
<li>iii</li>
<li>qqqq</li>
<li>yyyy</li>
<li>pppp</li>
<li>p222</li>
</ul>
CSS
ul{
width:200px;
overflow: hidden;
border: 1px solid red;
padding: 5px;
}
li{
line-height: 1.5em;
float: left;
display: inline;
border-bottom: 1px solid #DDDDDD;
border-right: 2px;
}
#double li {
width: 45%;
}
One solution is to apply border-right using :nth-child(odd):
ul {
width: 200px;
overflow: hidden;
border: 1px solid red;
padding: 5px;
}
li {
line-height: 1.5em;
float: left;
display: inline;
border-bottom: 1px solid #DDDDDD;
border-right: 2px;
}
#double li {
width: 45%;
}
#double li:nth-child(odd) {
border-right: solid 1px #DDDDDD;
}
#double li:nth-child(even) {
margin-left: 5px;
}
<ul id="double">
<li>asdas</li>
<li>eee</li>
<li>iii</li>
<li>qqqq</li>
<li>yyyy</li>
<li>pppp</li>
<li>p222</li>
</ul>
I think you simply need to give the li elements a margin.
For example
li {
...
margin: 0 5px;
...
}
just add margin-left and margin rigth in li element
it may be works. http://jsfiddle.net/vrajeshdave148/t89yvepj/3/
the property column-gap resolves it.
I have added the odd and even classes to the li tags
and I have added the float:right CSS rule to the li tags with even class
and I have added the float:left CSS rule to the li tags with odd class
and I have added a border-bottom to each of the li.even and li.odd separatly
here is I've achieved
ul{
width:200px;
overflow: hidden;
border: 1px solid red;
padding: 5px;
}
li{
line-height: 1.5em;
float: left;
display: inline;
}
#double li {
width:45%;
}
li.odd {border-bottom:3px solid #ccc;float:left;}
li.even {border-bottom:3px solid #ccc;float:right;}
<ul id="double">
<li class="odd">asdas</li>
<li class="even">eee</li>
<li class="odd">iii</li>
<li class="even">qqqq</li>
<li class="odd">yyyy</li>
<li class="even">pppp</li>
<li class="odd">p222</li>
</ul>