mardi 29 septembre 2020

CSS manipulation in jQuery with if statement

$(document).ready(function(){
  var width = $(window).width();
  $(function(){
    if ( width < 800 ) {
          $(".navbar-brand").css({'margin-left':'0'});
      }else{
          $(".navbar-brand").css({'margin-left':'100px'});
      }
  });
});

Hello, I know it's basic and I should not to ask about something so simple, but I have struggled by myself long enough. What I am trying to do is to remove margin-left in navbar when the viewport width is smaller than 800px, I can do it simply by adding a class, but I really want to learn how to manipulate css, with the jquery.

I appreciate all your advice, thank you.

Aucun commentaire:

Enregistrer un commentaire