Make a really responsive menu

1

I have a menu with several divs in it with content, this site I'm developing the client will have access to edit and delete elements you want from the site, so these items from the menu must always be in the middle, but I can not do the jQuery manage this, eg if there is a div only the css class should change, if it is two, it should be other properties, follow my current code:

 var numCells = $("div.secondMenuButtonsCell").length;
  alert(numCells);
  if(numCells == 1){
$(".secondMenuButtonsCell").css({
  "width": "50% !important",         
  "margin-right": "auto !important",
  "margin-left": "auto !important"
  "border-right":"1px solid #CCCCCC !important",
  "height": "71px !important",
  "padding": "14px !important",
  "display": "inline-grid !important"
         });
              $("a.btnContentRow").css({
             "display": "inline-block !important",
              "text-align": "left !important"
                    }); };

But this code is not changing the class, did I do something wrong?

    
asked by anonymous 12.05.2016 / 21:16

1 answer

1

I'm not seeing code to change class in your script.

I advise you to create a class in css for the specified style such as:

 .meu-estilo1{
      width: 50% !important;         
      margin-right: auto !important;
      margin-left: auto !important;
      border-right:1px solid #CCCCCC !important;
      height: 71px !important;
      padding: 14px !important;
      display: inline-grid !important;
             }

To count the div you will need a # or selector. accompanied by a name to capture in jquery.

example in HTML:

 <div class="teste"></div>

In jQuery you check as follows:

var $div = $('.teste');
var num_div = $div.size();

if (num_div == 1) {

   $div.removeClass('outras classes de estilo');
   $div.addClass('meu-estilo1');
}
    
13.05.2016 / 14:08