Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add border-radius to dropdown menu

I'm unable to add border-radius to entire dropdown menu, If I add border-radius to click-nav ul li then radius applying to list items. I have added border-radius to .click-nav ul but radius not applied to entire dropdown menu.

$(function () {
  $('.click-nav > ul').toggleClass('no-js js');
  $('.click-nav .js ul').hide();
  $('.click-nav .js').click(function(e) {
    $('.click-nav .js ul').slideToggle(200);
    $('.clicker').toggleClass('active');
    e.stopPropagation();
  });
  $(document).click(function() {
    if ($('.click-nav .js ul').is(':visible')) {
      $('.click-nav .js ul', this).slideUp();
      $('.clicker').removeClass('active');
    }
  });
});
body{background:#000}

.click-nav {width:200px;}

.click-nav ul {position:relative;}

.click-nav ul li {position:relative;list-style:none;cursor:pointer;}

.click-nav ul li ul {position:absolute;left:0;right:0;margin:5px 0px 0px -40px;}

.arrow-up {
	width: 0; 
	height: 0; 
	border-left: 10px solid transparent;
	border-right: 10px solid transparent;
	border-bottom: 10px solid white;
  margin-left:30px;
  }


.click-nav ul .clicker {position:relative;border:2px solid #fff;color:#fff;border-radius:6px;background-color: rgba(255,255,255,0);width:70px;}

.click-nav ul .clicker:hover,.click-nav ul .active {background-color: rgba(255,255,255,0.2);width:70px;}


.click-nav ul li a {
  background:#fff;transition:background-color 0.2s ease-in-out;
-webkit-transition:background-color 0.2s ease-in-out;
-moz-transition:background-color 0.2s ease-in-out;
  display:block;
  padding:6px 10px 6px 10px;color:#333;text-decoration:none;}

.click-nav ul li a:hover {background-color: rgba(214,247,255,1); }
.click-nav .no-js ul {display:none;}
.click-nav .no-js:hover ul {display:block;}
<script src="https://code.jquery.com/jquery-1.8.3.js"></script><div class="click-nav">
  <ul class="no-js">
    <li>
      <a href="#" class="clicker">Categories</a>
      <ul>
        <li><div class="arrow-up"></div></li>
        <li><a href="#">Dashboard</a></li>
        <li><a href="#">Settings</a></li>
        <li><a href="#">Privacy</a></li>
        <li><a href="#">Help</a></li>
        <li><a href="#">Sign out</a></li>
      </ul>
    </li>
  </ul>
</div>
like image 392
Prime Avatar asked Aug 08 '15 20:08

Prime


2 Answers

Try adding a class to the first and last list elements...

css

.first a {
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

.last a{
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}

html

  <ul>
    <li><div class="arrow-up"></div></li>
    <li class="first"><a href="#">Dashboard</a></li>
    <li><a href="#">Settings</a></li>
    <li><a href="#">Privacy</a></li>
    <li><a href="#">Help</a></li>
    <li class="last"><a href="#">Sign out</a></li>
  </ul>

Demo: http://jsfiddle.net/vp9eykne

like image 124
Bruffstar Avatar answered Sep 24 '22 19:09

Bruffstar


Your border-radius is being set, just now shown properly. If you take a look at this code, I have added the radius and set the background-color: red;. Here you will see the positioning of the second ul and how the radius is being displayed.

To get around the issue, you could add classes or pseudo-classes for the first (well, second technically) and last elements of the list.

.click-nav ul li ul li:nth-child(2) a {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.click-nav ul li ul li:last-child a {
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
}

Here is a link to the working version. If you'd rather not use the pseudo-classes, recode your dropdown as to not have the top arrow part of the inside ul and the margin not pushed so far over.

like image 36
RhapX Avatar answered Sep 24 '22 19:09

RhapX