I am trying to create a basic horizontal flyout menu that expands from left to right when hovering over a button. You can view the DEMO here.
.menu {
position: absolute;
right: 0;
height: 50px;
width: 50px;
color: white;
}
.menu li {
pointer-events: none;
position: relative;
display: inline-block;
vertical-align: middle;
list-style: none;
line-height: 100%;
transform: translateZ(0);
}
.menu a {
pointer-events: auto;
position: relative;
display: block;
min-width: 5em;
margin-bottom: .4em;
padding: .4em;
line-height: 100%;
font-size: 16px;
text-decoration: none;
color: white;
transition: background 0.3s;
}
.menu a:active, .menu a:focus {
background: #B44659;
}
.menu i {
display: block;
margin-bottom: .2em;
font-size: 2em;
}
.menu span {
font-size: .625em;
font-family: sans-serif;
text-transform: uppercase;
}
.menu li:hover ul {
transform: translateX(0);
background: #B44659;
}
.menu > li {
display: block;
}
.menu > li > a {
background: #7D294E;
}
.menu > li:hover {
z-index: 100;
}
.menu > li:hover a {
background: #B44659;
}
.menu > li a:hover {
background: #F56356;
}
.menu > li > a:after {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 100%;
width: 4px;
opacity: 0;
background: -moz-linear-gradient(left, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(0, 0, 0, 0.65)), color-stop(100%, rgba(0, 0, 0, 0)));
background: -webkit-linear-gradient(left, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
background: -o-linear-gradient(left, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
background: -ms-linear-gradient(left, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
background: linear-gradient(to right, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a6000000', endColorstr='#00000000',GradientType=1 );
transition: opacity 0.5s;
}
.menu > li:hover a:after {
opacity: 1;
}
.menu > li ul {
position: absolute;
z-index: -1;
top: 0;
right: 100%;
height: 100%;
width: auto;
white-space: nowrap;
transform: translateX(100%);
background: #B44659;
transition: 0.5s transform;
}
<ul class="menu">
<li>
<a href="#">
<span>ITEM 1</span>
</a>
<ul>
<li>
<a href="https://google.co.uk/" target="_blank">
<span>SUBITEM 1.1</span>
</a>
</li>
<li>
<a href="https://google.co.uk/" target="_blank">
<span>SUBITEM 1.2</span>
</a>
</li>
<li>
<a href="https://google.co.uk/" target="_blank">
<span>SUBITEM 1.3</span>
</a>
</li>
</ul>
</li>
</ul>
My challenge is to find a way to completely hide the options sliding out from the menu when hovering over an item, instead of just moving them back to their original position on the right. Is there a CSS-only solution for this?