css - React component find last-of-type class with JQuery -
i have accordion contain selected medication. there 3 types (current, prescribed , recommended)
i want have 15px bottom margin between types.
i have them identified in classes panel-head-color1
, panel-head-color2
, panel-head-color3
, done color-code different types.
but on spacing, want last element of each class have margin-bottom:15px
ive tried in css
,
div.panel-head-color1:last-of-type, div.panel-head-color2:last-of-type, div.panel-head-color3:last-of-type{ margin-bottom: 15px !important; }
but not work. im thinking jquery, im unsure how in react component.
this im after.
current css
.panel-head-color1 > .panel-heading{ background-color: #5cb85c; color: #ffffff; } .panel-head-color2 > .panel-heading{ background-color: #f0ad4e; color: #222222; } .panel-head-color3 > .panel-heading{ background-color: #5bc0de; color: #222222; } .panel-head-color1, .panel-head-color2, .panel-head-color3{ margin-top: 0 !important; } .last-of-type { margin-bottom: 15px !important; }
solution
componentdidmount: function() { $('.panel-head-color1').last().addclass('last-of-type'); $('.panel-head-color2').last().addclass('last-of-type'); $('.panel-head-color3').last().addclass('last-of-type'); },
css
.last-of-type { margin-bottom: 15px !important; }
you can count element last-of-type in react , put there appropriate class .last-of-type
but if dont want complicate react javascript code external javascript or jquery code not bad idea. recommend vanila js because of speed, if using jquery doesn't matter.
vanila js:
var elements = document.getelementsbyclassname('panel-head-color2'); elements[elements.length-1].classlist.add('last-of-type');
jquery:
$('.panel-head-color2').last().addclass('last-of-type');
Comments
Post a Comment