I'm creating a vertical navigation where list-items are circles. Sub-menu items should fly out from its parent.
I have working code, but the code works only with a single sub-menu because it requires heavy use of the 'left' and 'top' properties to position submenu list-items. I bet this could look pretty with several more sub-menus, but it would require too much CSS customization per menu for my taste.
<nav>
<ul class="menu">
<li><a href="/">Home Page</a></li>
<li><a href="/">About</a>
<ul>
<li><a href="/">Our History</a></li>
<li><a href="/">Our Philosophy</a></li>
<li><a href="/">Our Mission</a></li>
</ul>
</li>
<li><a href="/">Services</a></li>
<li><a href="/">Our Team</a></li>
<li><a href="/">Contact Us</a></li>
</ul>
</nav>
CSS
/* Circle Menu */
nav {
width: 10em;
}
.menu a{
display: block;
padding:10px;
width: 100%;
height: 7.5em;
border-radius: 750px 750px 750px 750px;
-moz-border-radius: 750px 750px 750px 750px;
-webkit-border-radius: 750px 750px 750px 750px;
background-color: hsl(0, 100%, 72%);
text-align: center;
margin-bottom: 1em;
}
.menu li{
margin-bottom: 1em;
list-style: none;
}
.menu li ul{
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
opacity: 0;
padding: 0;
display: inline;
top: -8em;
position: fixed;
}
.menu li:hover ul{
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
padding: 0;
opacity: 1;
}
.menu ul li a{
width: 100%;
background-color: hsl(0, 60%, 72%);
}
.menu li ul li {
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
position:relative;
left:0;
}
.menu li:hover ul li {
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
position: relative;
left: 190px;
}
.menu li ul li:nth-child(1) {
top: 307px;
left: 0px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li:hover ul li:nth-child(1) {
top: 150px;
left: 160px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li ul li:nth-child(2) {
top: 153px;
left: 0;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li:hover ul li:nth-child(2) {
left: 240px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
top: 150px;
}
.menu li ul li:nth-child(3) {
top: -5px;
left: 0;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li:hover ul li:nth-child(3) {
top: 153px;
left: 160px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
Demo that breaks because there are 2 submenus.
<nav>
<ul class="menu">
<li><a href="/">Home Page</a></li>
<li><a href="/">About</a>
<ul>
<li><a href="/">Our History</a></li>
<li><a href="/">Our Philosophy</a></li>
<li><a href="/">Our Mission</a></li>
</ul>
</li>
<li><a href="/">Services</a></li>
<li><a href="/">Our Team</a>
<ul>
<li><a href="/">Jim</a></li>
<li><a href="/">Karla</a></li>
<li><a href="/">Manzanita</a></li>
</ul>
</li>
<li><a href="/">Contact Us</a></li>
</ul>
</nav>
CSS
/* Circle Menu */
nav {
width: 10em;
}
.menu a{
display: block;
padding:10px;
width: 100%;
height: 7.5em;
border-radius: 750px 750px 750px 750px;
-moz-border-radius: 750px 750px 750px 750px;
-webkit-border-radius: 750px 750px 750px 750px;
background-color: hsl(0, 100%, 72%);
text-align: center;
margin-bottom: 1em;
}
.menu li{
margin-bottom: 1em;
list-style: none;
}
.menu li ul{
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
opacity: 0;
padding: 0;
display: inline;
top: -8em;
position: fixed;
}
.menu li:hover ul{
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
padding: 0;
opacity: 1;
}
.menu ul li a{
width: 100%;
background-color: hsl(0, 60%, 72%);
}
.menu li ul li {
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
position:relative;
left:0;
}
.menu li:hover ul li {
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
position: relative;
left: 190px;
}
.menu li ul li:nth-child(1) {
top: 307px;
left: 0px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li:hover ul li:nth-child(1) {
top: 150px;
left: 160px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li ul li:nth-child(2) {
top: 153px;
left: 0;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li:hover ul li:nth-child(2) {
left: 240px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
top: 150px;
}
.menu li ul li:nth-child(3) {
top: -5px;
left: 0;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
.menu li:hover ul li:nth-child(3) {
top: 153px;
left: 160px;
-webkit-transition:all .35s ease-in;
-moz-transition:all .35s ease-in;
-o-transition:all .35s ease-in;
transition:all .35s ease-in;
}
Is it possible to create the effect I want for multiple submenus with only CSS but without needing to position each submenu item individually? Or will I need to employ JavaScript to 'automatically' position elements for me?
position:relative
, so that their then absolutely positioned child elements take them as orientation points … – CBroe