Possible to have one border overlap/cancel out another border? - html

I have two lists sitting side-by-side. In the full code there will be the ability to select one of the list items from the MainList which will show the relevant list items from the SubList. What I would like is for the border-right of the MainList to overlap the border-left of the SubList to make it look like the SubList items are being shown as a result of the selection in the MainList.
ul {
list-style: none;
}
.BigContainer {
border: 2px solid #d50f67;
border-radius: 5px;
margin: 10px 0;
padding: 5px;
overflow: auto;
}
.MainListContainer {
width: 50%;
float: left;
}
.MainListItem {
border-bottom: 1px solid #ddd;
border-right: 1px solid white;
padding: 5px;
z-index: 2;
}
.MainListItem:last-of-type {
border: none;
}
.SubListContainer {
width: 45%;
float: left;
border: 1px solid #ddd;
border-radius: 5px;
}
.SubListItem {
padding: 5px;
z-index: 1;
}
<div class="BigContainer">
<div class="MainListContainer">
<ul class="MainList">
<li class="MainListItem">List Option A</li>
<li class="MainListItem">List Option B</li>
<li class="MainListItem">List Option C</li>
</ul>
</div>
<div class="SubListContainer">
<ul class="SubList">
<li class="SubListItem">Sub-Option 1</li>
<li class="SubListItem">Sub-Option 2</li>
<li class="SubListItem">Sub-Option 3</li>
<li class="SubListItem">Sub-Option 4</li>
<li class="SubListItem">Sub-Option 5</li>
</ul>
</div>
</div>
So, the border-right of the MainList would be white/transparent to basically erase a portion of the SubList border. I appreciate that, at the moment, making this happen would remove more of the SubList border than desired, but I will code the selection process properly to ensure only the selected item has the relevant border styling applied.

Add selected class to the selected item, then add
.selected:after{
content:"";
position: absolute;
right:-2px;
top:0;
width: 1px;
height: 100%;
background-color: white;
}
This will be placed right where you want it to. Note that MainListItem needs to have a position: relative; for the position to work.
.selected:after{
content:"";
position: absolute;
right:-2px;
top:0;
width: 1px;
height: 100%;
background-color: white;
}
ul {
list-style: none;
}
.BigContainer {
border: 2px solid #d50f67;
border-radius: 5px;
margin: 10px 0;
padding: 5px;
overflow: auto;
}
.MainListContainer {
width: 50%;
float: left;
}
.MainListItem {
border-bottom: 1px solid #ddd;
border-right: 1px solid white;
padding: 5px;
z-index: 2;
position: relative;
}
.MainListItem:last-of-type {
border: none;
}
.SubListContainer {
width: 45%;
float: left;
border: 1px solid #ddd;
border-radius: 5px;
}
.SubListItem {
padding: 5px;
z-index: 1;
}
<div class="BigContainer">
<div class="MainListContainer">
<ul class="MainList">
<li class="MainListItem">List Option A</li>
<li class="MainListItem selected">List Option B</li>
<li class="MainListItem">List Option C</li>
</ul>
</div>
<div class="SubListContainer">
<ul class="SubList">
<li class="SubListItem">Sub-Option 1</li>
<li class="SubListItem">Sub-Option 2</li>
<li class="SubListItem">Sub-Option 3</li>
<li class="SubListItem">Sub-Option 4</li>
<li class="SubListItem">Sub-Option 5</li>
</ul>
</div>
</div>

Related

Overflow defeats negative margin to hide border

I am designing a simple tab bar with a content panel.
To hide the bottom border for the current active tab, I use a negative margin-bottom and a border-bottom to hide the border for that tab.
* {
box-sizing: border-box;
}
#container {
width: 500px;
height: 200px;
border: 1px solid black;
background-color: lightgray;
}
#wrapper {
}
ul {
display: flex;
margin: 0;
padding: 2px 2px 0 2px;
border-bottom: 1px solid black;
}
li {
padding: 10px;
margin: 0 2px -1px 0;
list-style: none;
border-top: 1px solid black;
border-left: 1px solid black;
border-right: 1px solid black;
border-bottom: 0;
}
li.active {
border-bottom: 2px solid lightgray;
}
#content {
padding: 10px;
}
<div id="container">
<div id="wrapper">
<ul>
<li class="active">Tab 1 (active)</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div id="content">
My content
</div>
</div>
It works perfect.
The problem comes when I want to add more tabs, so it overflows the container. The solution that comes to my mind is using overflow-x: auto;. The problem is that this also adds a vertical scrollbar, and I am not sure why. I could overcome this by using overflow-y: hidden;. But the real problem is that it makes impossible to "delete" the black bottom border of the current active tab anymore.
You can run the snipped below, also you can uncomment the commented html li elements.
* {
box-sizing: border-box;
}
#container {
width: 500px;
height: 200px;
border: 1px solid black;
background-color: lightgray;
}
#wrapper {
}
ul {
display: flex;
margin: 0;
padding: 2px 2px 0 2px;
border-bottom: 1px solid black;
overflow-x: auto;
}
li {
padding: 10px;
margin: 0 2px -1px 0;
list-style: none;
border-top: 1px solid black;
border-left: 1px solid black;
border-right: 1px solid black;
border-bottom: 0;
white-space: nowrap;
}
li.active {
border-bottom: 2px solid lightgray;
}
#content {
padding: 10px;
}
<div id="container">
<div id="wrapper">
<ul>
<li class="active">Tab 1 (active)</li>
<li>Tab 2</li>
<li>Tab 3</li>
<li>Tab 4</li>
<li>Tab 5</li>
<li>Tab 6</li>
<li>Tab 7</li>
<!--<li>Tab 8</li>
<li>Tab 9</li>
<li>Tab 10</li>-->
</ul>
<div id="content">
My content
</div>
</div>
Does anyone has a solution? If not, what would be an alternate way to accomplish this?
What I really want is to keep hiding the bottom border of the active tab, and also have the possibility of showing an horizontal scroll bar when there is horizontal overflow.
Thank you.
To hide the bottom border for the current active tab, I use a negative
margin-bottom and a border-bottom to hide the border for that tab.
Instead, you can use box-shadow: 0 -1px black inset; for <ul> and box-shadow: 1px -1px lightgray inset; for li.active.
Once you have done all of this, you don't need negative margin-bottom anymore.
The problem is that this also adds a vertical scrollbar, and I am not
sure why. I could overcome this by using overflow-y: hidden;.
It adds a vertical scrollbar to ul because you added margin-bottom: -1px; to it's child (li) and it overflows Y axis.
I don't know how to fix horizontal scrollbar but i think you can fix it with a javascript carousel like owlcarousel, slick carousel etc.
Here is the example working:
* {
box-sizing: border-box;
}
#container {
width: 500px;
height: 200px;
border: 1px solid black;
background-color: lightgray;
}
#wrapper {
}
ul {
display: flex;
margin: 0;
padding: 2px 2px 0 2px;
/* border-bottom: 1px solid black; */
box-shadow: 0 -1px black inset;
overflow-x: auto;
}
li {
padding: 10px;
margin: 0 2px 0 0; /* you don't need to use bottom margin anymore. */
list-style: none;
border-top: 1px solid black;
border-left: 1px solid black;
border-right: 1px solid black;
border-bottom: 0;
white-space: nowrap;
}
li.active {
/* border-bottom: 2px solid lightgray; */
box-shadow: 1px -1px lightgray inset;
}
#content {
padding: 10px;
}
<div id="container">
<div id="wrapper">
<ul>
<li class="active">Tab 1 (active)</li>
<li>Tab 2</li>
<li>Tab 3</li>
<li>Tab 4</li>
<li>Tab 5</li>
<li>Tab 6</li>
<li>Tab 7</li>
<!--<li>Tab 8</li>
<li>Tab 9</li>
<li>Tab 10</li>-->
</ul>
</div>
<div id="content">
My content
</div>
</div>
"delete" the black bottom border of the current active tab
You can use border-bottom-color: transparent.
* {
box-sizing: border-box;
}
#container {
width: 500px;
height: 200px;
border: 1px solid black;
background-color: lightgray;
}
#wrapper {
}
ul {
display: flex;
margin: 0;
padding: 2px 2px 0 2px;
}
li {
padding: 10px;
margin: 0 2px 0 0;
list-style: none;
border: 1px solid black;
}
li.active {
border-bottom-color: transparent;
}
#content {
padding: 10px;
}
<div id="container">
<div id="wrapper">
<ul>
<li class="active">Tab 1 (active)</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div>
<div id="content">
My content
</div>
</div>
showing an horizontal scroll bar when there is horizontal overflow
I think you forgot to close one of your divs, and your content was inside .wrapper! So just fix that up, and stick on overflow: auto and a max width to make sure it doesn't expand.
* {
box-sizing: border-box;
}
#container {
width: 500px;
height: 200px;
border: 1px solid black;
background-color: lightgray;
}
#wrapper {
overflow-x: auto;
max-width: 100%;
}
ul {
display: flex;
margin: 0;
padding: 2px 2px 0 2px;
}
li {
padding: 10px;
margin: 0 2px 0 0;
list-style: none;
border: 1px solid black;
}
li.active {
border-bottom-color: transparent;
}
#content {
padding: 10px;
}
<div id="container">
<div id="wrapper">
<ul>
<li class="active">Tab 1 (active)</li>
<li>Tab 2</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
<li>Tab 3</li>
</ul>
</div>
<div id="content">
My content
</div>
</div>

CSS Cascade Menu: Position <div> relative to <li>

I want to build a cascade menu where at a certain <li> a new menu is opened. Here is the HTML code:
<div className='ux-dropdown-menu-container'>
<ul className='ux-dropdown-menu'>
<li className='ux-dropdown-menu-item'><a href='#'>Menu Item 1</a></li>
<li className='ux-dropdown-menu-item'><a href='#'>Menu Item 2</a></li>
<li className='ux-dropdown-menu-item'><a href='#'>Submenu</a></li>
<li className='ux-dropdown-menu-item'>
<div className='ux-dropdown-menu-container'>
<ul className='ux-dropdown-menu'>
<li className='ux-dropdown-menu-item'><a href='#'>SubMenu Item 1</a></li>
<li className='ux-dropdown-menu-item'><a href='#'>SubMenu Item 2</a></li>
<li className='ux-dropdown-menu-item'><a href='#'>SubMenu Item 3</a></li>
<li className='ux-dropdown-menu-item'>
</li>
</ul>
</div>
</li>
<li className='ux-dropdown-menu-item'><a href='#'>Menu Item 3</a></li>
</ul>
</div>
And my CSS classes:
.ux-dropdown-menu-container {
position: absolute;
display: block;
background-color: $ux-color-boxed-background;
border: solid;
border-color: $ux-color-border;
border-width: 1px;
border-radius: 4px;
box-shadow: 0px 2px 2px 0px $ux-color-border;
top: 105%;
text-align: left;
min-width: 100px;
}
.ux-dropdown-menu {
margin: 0px 0px 0px 0px;
list-style-type: none;
padding: 5px 5px 5px 5px; // top right botton left
z-index: 1;
}
.ux-dropdown-menu-item
{
white-space: nowrap;
position: relative;
}
.ux-dropdown-menu-item a {
display: inline-block;
text-decoration: none;
padding: 5px 5px 5px 5px;
color: $ux-color-text;
}
.ux-dropdown-menu-item:hover {
background-color: $ux-color-hover;
}
.ux-dropdown-menu-item:active {
background-color: $ux-color-click-background;
}
Even having a position: relative at my <li>, the new <div> for the submenu is not positioning there. Here is the result:
I expected the submenu to appear right at the side of the Submenu item.
I am now looking to:
(A) position the submenu right next to the Submenu item
(B) consider right or left opening, in case the menu is composed and the right side of the screen, where it then needs to open the menu to the left. I do not plan to use jQuery
body{
margin: 0; padding: 0;
}
.ux-dropdown-menu-container {
float: left;
}
.ux-dropdown-menu-containerItem {
position: absolute;
display: none;
background-color: $ux-color-boxed-background;
border: solid;
border-color: $ux-color-border;
border-width: 1px;
border-radius: 4px;
box-shadow: 0px 2px 2px 0px $ux-color-border;
top: 0;
text-align: left;
min-width: 100px;
left: 100%;
}
.ux-dropdown-menu-item:hover .ux-dropdown-menu-containerItem {
display: block;
}
.ux-dropdown-menu {
margin: 0px 0px 0px 0px;
list-style-type: none;
padding: 5px 5px 5px 5px; // top right botton left
z-index: 1;
}
.ux-dropdown-menu-item
{
white-space: nowrap;
position: relative;
border: 1px solid #ccc;
list-style: none;
}
.ux-dropdown-menu-item a {
display: inline-block;
text-decoration: none;
padding: 5px 5px 5px 5px;
color: $ux-color-text;
}
.ux-dropdown-menu-item:hover {
background-color: $ux-color-hover;
}
.ux-dropdown-menu-item:active {
background-color: $ux-color-click-background;
}
<div class="ux-dropdown-menu-container">
<ul class="ux-dropdown-menu">
<li class="ux-dropdown-menu-item">Menu Item 1</li>
<li class="ux-dropdown-menu-item">Menu Item 2</li>
<li class="ux-dropdown-menu-item">
Submenu
<div class="ux-dropdown-menu-containerItem">
<ul class="ux-dropdown-menu">
<li class="ux-dropdown-menu-item">SubMenu Item 1</li>
<li class="ux-dropdown-menu-item">SubMenu Item 2</li>
<li class="ux-dropdown-menu-item">SubMenu Item 3</li>
</ul>
</div>
</li>
<li class="ux-dropdown-menu-item">Menu Item 3</li>
</ul>
</div>

CSS - How to place absolute div correctly

I have the following code:
.menu{
border: solid red;
border-width: 1px 1px 0px 1px;
background-color:black;
color:white;
width: 60px;
}
.dropdown{
position:absolute;
background-color: grey;
width:100px;
}
.dropdown ul{
list-style:none;
padding:10px;
margin: 0;
}
.zoom{
zoom:300%;
}
<div class="menu zoom">
Click me
<div class="dropdown">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>
How can I place my dropdown menu to the same x position as the parent, without removing the border? I already tried 'box-sizing: border-box', but somehow it doesn't work.
Set position: relative on parent element and on child set position left to same negative value as left border width of parent element.
.menu {
border: solid red;
border-width: 1px 1px 0px 1px;
background-color: black;
color: white;
width: 60px;
position: relative;
}
.dropdown {
position: absolute;
background-color: grey;
width: 100px;
left: -1px;
}
.dropdown ul {
list-style: none;
padding: 10px;
margin: 0;
}
.zoom {
zoom: 300%;
}
<div class="menu zoom">
Click me
<div class="dropdown">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>
Keeping the parent as positon:relative and giving the child position:absolte with top:100%; and left:-1px ( where -1 is taken because the width of border is 1 from left)
Here is the working snippet:
.menu {
border: solid red;
border-width: 1px 1px 0px 1px;
background-color: black;
color: white;
width: 60px;
position: relative;
}
.dropdown {
position: absolute;
background-color: grey;
width: 100px;
left: -1px;
top:100%
}
.dropdown ul {
list-style: none;
padding: 10px;
margin: 0;
}
.zoom {
zoom: 300%;
}
<div class="menu zoom">
Click me
<div class="dropdown">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>

Change the height of a column line

So i was playing around with CSS and i found a way to make lines appear beetween my navigation tabs.
So for example it would be
Home | About etc etc
I wanted to know how i would change the size of the "|"
The way i have got it coded is
li+li {
border-left: 1px solid #00FFFF;
}
I have tried height etc but it does nothing to change the size of the actual line. It just stays the same. So anyway which changes the actual height would be great
You can use pseudo element :before or :after to create the line.
.nav li {
display: inline-block;
}
.nav li + li:before {
content: "";
display: inline-block;
vertical-align: middle;
border-left: 1px solid;
padding-left: 8px;
margin-left: 4px;
height: 8px;
}
<ul class="nav">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
You should surround the list elements with a div in the actual HTML and give that a border-left: 1px solid #00FFFF; with CSS.
The height on the border should work.
Examples
Compare the two nav listed below and check the height on the border.
<nav>
<li class="navlinks">Home</li>
<li class="navlinks">About</li>
<li class="navlinks">Contact</li>
</nav>
<br>
<br>
<nav>
<li class="navlinks2">Home</li>
<li class="navlinks2">About</li>
<li class="navlinks2">Contact</li>
</nav>
nav{
height:50px;
background-color: #9e9e9e;
width:100%;
}
li{
position:relative;
display: block;
float:left;
padding:15px 5px 5px 5px;
}
.navlinks{
border-right: 1px solid red;
height: 5px;
}
.navlinks2{
border-right: 1px solid red;
height: 30px;
}
http://codepen.io/Bespinoza10/pen/LGeyXe
nav{
height:50px;
background-color: #9e9e9e;
width:100%;
}
li{
position:relative;
display: block;
float:left;
padding:15px 5px 5px 5px;
}
.navlinks{
border-right: 1px solid red;
height: 5px;
}
.navlinks2{
border-right: 1px solid red;
height: 30px;
}
<nav>
<li class="navlinks">Home</li>
<li class="navlinks">About</li>
<li class="navlinks">Contact</li>
</nav>
<br>
<br>
<nav>
<li class="navlinks2">Home</li>
<li class="navlinks2">About</li>
<li class="navlinks2">Contact</li>
</nav>
I put the example on here just run the script and also on codepen.io

New list items shadowing previous items due to negative margin

I'm working on a step indicator which I implemented as a list:
<ol>
<li>Step 1</li>
<li class="active">Step 2</li>
<li>Step 3</li>
</ol>
Each list element has a rounded edge to it's right in order to indicate progress, so I have the following CSS:
li{
display: block; background-color: white; width: 33%; border: 1px solid #ddd; text-indent: 40px;
float: left;
margin: 0 0 0 -20px;
border-radius: 0 15px 15px 0;
}
My problem is that later elements are shadowing the earlier, thus the rounded edge are hidden. I've tried to set a decreasing z-index for each element, but it doesn't work (besides I couldn't use this solution anyway). I acheive the desired presentation by changing to float:right but that renders the list items in descending order...
Check this jsfiddle for details: http://jsfiddle.net/fMRbr/
You can use the :before
li{
display: inline-block;
width: 33%;
margin: 0 0 0 -20px;
border: 1px solid #ddd;
border-radius: 0 15px 15px 0;
background-color: white;
text-indent: 40px;
position: relative;
}
li.active{
background-color: red;
}
li:before{
content: '';
width: 15px;
height: 19px;
display: inline-block;
background: #fff;
border: 1px solid #ddd;
border-width: 0 1px 1px 0;
border-radius: 0 15px 15px 0;
position: absolute;
top: 0;
left: -3px;
}
li.afteractive:before {
content: '';
width: 15px;
height: 19px;
display: inline-block;
background: #f00;
border: 0;
border-radius: 0 15px 15px 0;
position: absolute;
top: 0;
left: -3px;
}
<ol>
<li class="active">Step 1</li>
<li class="afteractive">Step 2</li>
<li>Step 3</li>
</ol>
<br /><br />
<ol>
<li>Step 1</li>
<li class="active">Step 2</li>
<li class="afteractive">Step 3</li>
</ol>
<br /><br />
<ol>
<li>Step 1</li>
<li>Step 2</li>
<li class="active">Step 3</li>
</ol>
Instead of using border-radius and negative margin values, have you considered a Tbackground image at the top right of each <li> which looks like this:
The active (red) <li> would have a similar background but colored red. The result should look something like this:
Add a span tag to your li's with display: inline-block so they automatically grow to the right width:
html
<ol>
<li><span>Step 1</span></li>
<li class="active"><span>Step 2</span></li>
<li><span>Step 3</span></li>
</ol>
css
li {
display: block;
float: left;
width: 33%;
margin: 0 0 0 -20px;
background-color: white;
text-indent: 40px;
}
li.active {
}
li.active span {
background-color: red;
}
li span {
display: inline-block;
border: 1px solid #ddd;
border-radius: 0 15px 15px 0;
padding-right: 10px;
}
See a jsfiddle of this solution here:
http://jsfiddle.net/c4urself/HYQSJ/