CSS border wrap submenu and parent tab. - css

I have a CSS menu with submenu. At the top level, there is a border for top, left, and right. For the submenu, there is a border on all 4 sides. See the JSFiddle at https://jsfiddle.net/vjy8adff/.
I want to move the submenu up by 1px to create an effect that there is only one loop around the parent tab and submenu. Since my submenu is now "absolute" positioned, I can't do the following:
ul ul{
top: -1px;
}
What is the best solution here.

At line 17 add :
margin-top: -1px;
Full code :
ul.menu > li > ul {
width: auto;
margin-top: -1px;
display: none;
position: absolute;
white-space: nowrap;
background-color: #fff;
padding: 10px;
border-radius: 2px;
}

if you set top to -1px the element will calculate the top right from the top i have set the top to 100% which will bring the element down to 100% and removed 1px from it which is the border
top:calc(100% - 1px);
so that it takes the element to 100% below and exclude 1px border
you can also use #ianis solution where the element is moved 1px top with -ve margin it acts like position:relative with -ve top value
ul.no-style {
list-style: none;
margin: 0;
padding: 0;
}
ul.no-style li {
padding: 0;
}
ul.list-inline > li {
display: inline-block;
}
/* basic menu structure */
ul.menu > li {
padding-right: 15px;
position: relative;
width: 50px;
}
ul.menu > li > ul {
width: auto;
display: none;
position: absolute;
white-space: nowrap;
background-color: #fff;
padding: 10px;
margin-top: -1px;
border-radius: 2px;
}
ul.menu > li > div.multi-2col {
display: none;
position: absolute;
width: 180px;
white-space: nowrap;
background-color: #fff;
border: solid #eee 1px;
border-radius: 2px;
}
ul.menu > li > div.multi-2col div.multi-2a {
padding-right: 15px;
}
ul.menu > li > div.multi-2col div.multi-2a,
ul.menu > li > div.multi-2col div.multi-2b {
padding: 10px;
width: auto;
float: left;
}
ul.menu > li > div.multi-2col.right {
right: 0;
}
ul.menu > li > div.multi-2col.right .multi-2a {
padding-left: 15px;
}
ul.menu > li > div.multi-2col.right .multi-2a,
ul.menu > li > div.multi-2col.right .multi-2b {
width: auto;
float: right;
}
ul.menu > li:last-child {
padding-right: 0px;
}
ul.menu > li:hover ul,
ul.menu > li:hover div.multi-2col {
display: block;
}
/* border wrap submenu and parent */
ul.menu.border-wrap > li {
padding: 0px;
border-top: 1px solid transparent;
border-left: 1px solid transparent;
border-right: 1px solid transparent;
}
ul.menu.border-wrap > li > a {
position: relative;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
display: block;
background-color: #eee;
}
ul.menu.border-wrap > li:hover {
background-color: #eee;
border-top: solid red 1px;
border-left: solid red 1px;
border-right: solid red 1px;
}
ul.menu.border-wrap > li:hover a {
z-index: 5;
}
ul.menu.border-wrap > li:hover > ul,
ul.menu.border-wrap > li:hover > div.multi-2col {
background-color: #eee;
border: solid red 1px;
left: -1px;
z-index: 2;
}
<ul class="no-style list-inline menu border-wrap">
<li>
Home
<ul class="no-style">
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
</ul>
</li>
</ul>

Related

Unwanted see-though spaces between menu items (border not working)

This is a pure CSS navbar I got from CSS Tricks. I've been racking my brain trying to figure out what's causing the blank, open, see-through space below each item on the drop-down menu, going over every CSS property, but I can't get it. You can see the image slider through them, and we don't want that. Can anyone help?
It's more obvious on the web than in the fiddle.
Here's the HTML:
<nav>
<ul class="nav"> <!-- Menu from https://css-tricks.com/targetting-menu-elements-submenus-navigation-bar/ -->
<li>Home</li>
<li>Services
<ul class="align-left">
<li>Drug Formulation</li>
<li>Analytical & Bioanalytical Services</li>
<li>Thermal Analysis</li>
<li>Custom Synthesis</li>
<li>Pharmacology & Toxicology</li>
<li>Regulatory Support for Drugs & Medical Devices</li>
<li>Materials Testing</li>
<li>Catalog of Chemical Reagents & Materials</li>
<li>Food Analysis</li>
</ul>
</li>
<li>Technologies
<ul class="align-left">
<li>API Micronization</li>
<li>Drug Delivery
<ul class="align-left">
<li>Sol-gel Encapsulation</li>
<li>Smart Hydrogels and Biomaterials</li>
<li>Electrorheologically-Controlled Drug Release</li>
<li>Polyphosphazenes</li>
</ul>
<li>Materials Science
<ul class="align-left">
<li>Coatings</li>
<li>Structural Materials</li>
<li>Viscosity Control: Non-aqueous Systems</li>
</ul>
</li>
</ul>
</li>
<li>Bio-Pharma Storage</li>
<li>About Us</li>
<li>News</li>
<li>Contact</li>
</ul>
</nav>
And the CSS:
nav {
display: block;
width:100%;
text-align: center;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
.nav a {
display: block;
background-color: #003399;
color: white;
text-decoration: none;
padding: .5em 1.4em .7em;
font-size: 75%;
letter-spacing: 1px;
position: relative;
}
.nav {
vertical-align: top;
display: inline-block;
border-radius: 6px;
}
.nav li { position: relative; }
.nav > li {
float: left;
border-bottom: 4px #aaa solid;
margin-right: 1px;
}
.nav > li > a {
margin-bottom: 1px;
}
.nav > li:hover, .nav > li:hover >a { border-bottom-color: #99ddff; }
.nav li:hover > a { color: #99ddff; }
.nav > li:first-child { border-radius: 4px 0 0 4px; }
.nav > li:first-child>a { border-radius: 4px 0 0 0; }
.nav > li:last-child {
border-radius: 0 0 4px 0;
margin-right: 0;
}
.nav > li:last-child >a { border-radius: 0 4px 0 0; }
.nav li li a { margin-top: 1px }
.nav li a:first-child:nth-last-child(2):before {
content: "";
position: absolute;
height: 0;
width: 0;
border: 5px solid transparent;
top: 50%;
right: 5px;
}
/* submenu positioning*/
.nav ul {
position: absolute;
white-space: nowrap;
border-bottom: 5px solid #99ddff;
z-index: 1;
left: -99999em;
}
.nav > li:hover > ul {
left: auto;
padding-top: 5px;
min-width: 100%;
}
.nav > li li ul { border-left: 1px solid #fff; }
.nav > li li:hover > ul {
/* margin-left: 1px */
left: 100%;
top: -1px;
}
/* arrow hover styling */
.nav > li > a:first-child:nth-last-child(2):before { border-top-color: white; }
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-bottom-color: orange;
margin-top: -5px
}
.nav li li > a:first-child:nth-last-child(2):before {
border-left-color: #aaa;
margin-top: -5px
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-right-color: orange;
right: 10px;
}
.align-left { text-align: left; }
.nav > li {
float: left;
border-bottom: 4px #aaa solid;
margin-right: 1px;
}
remove the margin-right :-)

Autowidth on fixed element don't work on IE11

I am facing an issue on IE11 on a fixed element. That's a context menu that needs to grow horizontally depending on the text inside. This works perfectly on Firefox, Chrome and Safari, but not on IE.
The problem is that on IE11 the right arrow goes down to the next line, instead of growing the line to allow all text be shown.
The following is my code:
* {
box-sizing: border-box;
}
#context-menu {
display: none;
text-align: left;
position: fixed;
z-index: 1000000000;
}
#context-menu ul {
background-color: white;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 1px 1px 3px #444;
text-align: left;
min-width: 150px;
width: auto;
}
#context-menu ul,
#context-menu ul li {
padding: 0;
margin: 0;
position: relative;
display: block;
width: auto;
color: black;
text-align: left;
background-color: #fff;
}
#context-menu ul li {
padding: 5px 10px;
cursor: pointer;
}
#context-menu ul li:hover ul {
z-index: 1;
}
#context-menu ul li:first-child {
border-radius: 3px 3px 0 0;
}
#context-menu ul li:last-child {
border-radius: 0 0 3px 3px;
}
#context-menu ul li .fa {
margin-right: 10px;
width: 15px;
vertical-align: middle;
}
#context-menu ul li.group {
cursor: default;
background-color: #dfdfdf;
font-weight: bold;
}
#context-menu ul > li:not(.group):hover {
background-color: hsla(208, 56%, 53%, 1);
color: black;
}
#context-menu ul > li.submenu::after {
font-family: FontAwesome;
content: "\f105";
margin-left: 15px;
float: right;
}
#context-menu ul> li > ul{
display: none;
}
#context-menu ul > li:hover > ul {
display: block;
position: absolute;
left: 100%;
top: 0;
}
<link href="https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css" rel="stylesheet"/>
<div id="context-menu" style="display: block;">
<ul>
<li><span class="optionText">Long text to show the problem here on the right arrow</span></li>
<li class="submenu"><span class="optionText">Another text</span></li>
<li class="submenu"><span class="optionText">Long text to show the problem here on the right arrow</span>
<ul class="dropdownright">
<li><span class="optionText">Other</span></li>
</ul>
</li>
</ul>
</div>
If you see, if the text is longer than the min-width, it grows on all browsers except IE11, where the arrow goes down to the next line.
How can I make it grow the width automatically ?
Thank you.
Removing the "float: right" in the rule "#context-menu ul > li.submenu::after" seems to be working for me in Internet explorer 11.

CSS - Chrome showing overlap border in lighter color.

I used a negative margin technique to overlap the border of a sub-menu and parent.
To create a visual effect that there is only loop around.
This works in IE, but in Chrome, the overlap border actually is a lighter version of the border.
Please see the fiddle at https://jsfiddle.net/xxe9e8ej/
ul.no-style {
list-style: none;
margin: 0;
padding: 0; }
ul.no-style li {
padding: 0; }
ul.list-inline > li {
display: inline-block;
}
/* basic menu structure */
ul.menu > li {
padding-right: 15px;
position: relative;
width: 50px;}
ul.menu > li > ul {
width: auto;
margin-top: -1px;
display: none;
position: absolute;
white-space: nowrap;
background-color: #fff;
padding: 10px;
border-radius: 2px;
}
ul.menu > li > div.multi-2col {
display: none;
position: absolute;
width: 180px;
white-space: nowrap;
background-color: #fff;
border: solid #eee 1px;
border-radius: 2px; }
ul.menu > li > div.multi-2col div.multi-2a {
padding-right: 15px; }
ul.menu > li > div.multi-2col div.multi-2a,
ul.menu > li > div.multi-2col div.multi-2b {
padding: 10px;
width: auto;
float: left; }
ul.menu > li > div.multi-2col.right {
right: 0; }
ul.menu > li > div.multi-2col.right .multi-2a {
padding-left: 15px; }
ul.menu > li > div.multi-2col.right .multi-2a,
ul.menu > li > div.multi-2col.right .multi-2b {
width: auto;
float: right; }
ul.menu > li:last-child {
padding-right: 0px; }
ul.menu > li:hover ul,
ul.menu > li:hover div.multi-2col {
display: block; }
/* border wrap submenu and parent */
ul.menu.border-wrap > li {
padding: 0px;
border-top: 1px solid transparent;
border-left: 1px solid transparent;
border-right: 1px solid transparent; }
ul.menu.border-wrap > li > a {
position: relative;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
display: block;
background-color: #eee; }
ul.menu.border-wrap > li:hover {
background-color: #eee;
border-top: solid red 1px;
border-left: solid red 1px;
border-right: solid red 1px; }
ul.menu.border-wrap > li:hover a {
z-index: 5; }
ul.menu.border-wrap > li:hover > ul, ul.menu.border-wrap > li:hover > div.multi-2col {
background-color: #eee;
border: solid red 1px;
left: -1px;
z-index: 2; }

Drop down width same as parent

I'm creating a drop down menu, the top level list item will display a username.
I have a bit of an issue because I want the dropdown menu to be the same width at the top level list item being hovered over.
However, if I set ul li ul li to width 100%, it takes 100% of the overall container, not of the ul above it. I think because ul ul's are position absolute?
Any ideas how I can make the drop down menu's the same width as the parent list item?
The page can be seen here.
and here's the HTML
<ul>
<li><span aria-hidden="true" data-icon="a"> A long name here
<ul>
<li>View Profile</li>
<li>Edit Profile</li>
<li>Settings</li>
<li>My Payments</li>
</ul>
</li>
<li> <span aria-hidden="true" data-icon="c"> Online</li>
<li> Log Out</li>
</ul>
CSS
.head-link ul ul {
display: none;
}
.head-link ul li:hover > ul {
display: block;
}
.head-link ul {
list-style: none;
position: relative;
display: inline-table;
}
.head-link ul li {
float: left;
border-top-left-radius: 0.5em;
border-top-right-radius: 0.5em;
height: 2em;
width: auto;
padding: 0.5em 0.98em;
}
.head-link ul li:hover {
background: #ffffff;
}
.head-link ul li:hover a {
color: #434343;
border-bottom: none;
}
.head-link ul li a {
display: block;
color: #ffffff;
text-decoration: none;
}
.head-link ul ul {
background: #ffffff;
border-radius: 0px;
padding: 0;
position: absolute;
top: 99%;
left: 0;
text-align: left;
border-bottom-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
padding-bottom: 0.8em;
padding-top: 0.5em;
box-shadow: 0px 0.3em 0.4em rgba(0,0,0,0.3);
}
.head-link ul ul li {
float: none;
position: relative;
padding: 0em;
}
.head-link ul ul li a {
padding: 0.5em 1.24em;
color: #434343;
border-bottom-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
}
.head-link ul ul li a:hover {
background: #ffffff;
text-decoration: underline;
}
.head-link ul ul ul {
position: absolute;
left: 100%;
top:0;
}
Here's how I made it look like this:
Just modify these rules:
.head-link ul li {
position: relative;
... /* Keep all current rules */
}
.head-link ul li ul {
width: 100%;
... /* Keep all current rules */
}

CSS pseudo selector on drop down menu

I am using the CSS :before pseudo-selector to create a block above the first item in a drop down list. I've been having trouble getting this block created with the pseudo-selector to be the same width as the <li> above it.
For example when you hover over "About" the pseudo block that appears beneath it should be the same width as the block that contains the word "About" and so on for the other 3 blocks.
Here's a fiddle to what I have got so far: http://jsfiddle.net/jh67P/
Here's my HTML:
<nav>
<ul class="main">
<li>About
<ul class="secondary">
<li>Learn About Us</li>
<li>Nice things to know</li>
</ul>
</li>
<li>Products
<ul class="secondary">
<li>Product One</li>
<li>Product Two</li>
</ul>
</li>
<li>Features
<ul class="secondary">
<li>Something Nice</li>
<li>Another nice thing</li>
</ul>
</li>
</ul>
</nav>
Here's the CSS:
nav .main {
font-size: 1em;
margin: 0;
padding: 0;
list-style: none;
}
.main > li {
display: block;
position: relative;
float: left;
}
.main > li a {
display: block;
text-decoration: none;
color:#FFF;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
.main > li a:hover {
background: #3b3b3b;
color:#FFF;
}
.secondary {
display:none;
list-style: none;
margin: 0;
padding: 0;
}
.main li:hover .secondary {
display: block;
position: absolute;
}
.main li:hover ul li {
float: none;
font-size: 1em;
}
.main > li:hover a { background: #3b3b3b; }
.main > li:hover li a:hover {
background: #1e7c9a;
}
.main li:hover ul:before {
content:'';
display:block;
width:100%;
height:10px;
border-bottom:10px solid #1e7c9a;
border-right: 10px solid transparent;
}
Edit: Using absolute positioning I was able to achieve the effect. Here's the updated CSS.
nav .main {
font-size: 1em;
margin: 0;
padding: 0;
list-style: none;
}
.main > li {
display: block;
position: relative;
float: left;
}
.main > li a {
display: block;
text-decoration: none;
color:#FFF;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
.main > li a:hover {
background: #3b3b3b;
color:#FFF;
}
.secondary {
display:none;
list-style: none;
margin: 0;
padding: 0;
}
.main li:hover .secondary {
display: block;
position: absolute;
top:40px;
}
.main li:hover ul li {
float: none;
font-size: 1em;
}
.main > li:hover a { background: #3b3b3b; }
.main > li:hover li a:hover {
background: #1e7c9a;
}
.main > li:hover:after {
content:'';
display:block;
width:100%;
height:10px;
border-bottom:10px solid #1e7c9a;
border-right: 10px solid transparent;
position:absolute;
top:20px;
margin-left:1px;
}
How about changing:
.main li:hover ul:before {
To:
.main > li:hover > a:after {
Is that what you are after?
jsFiddle

Resources