Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove margin from second div?

Tags:

jquery

css

i have one single class for margin and i am using this class to two different div but i want to margin 0 in second div, i dont want to change html because if i do that i will have work on many pages so i want to do that either jquery or css. i tried it to do that with child selector but it wont work for me.

<style>
.margn { margin-top:20px;}

</style>



<body>
<div class="margn">hii</div>

<div id="call" class="margn">bye</div>

</body>
like image 247
Jitender Avatar asked Mar 16 '26 07:03

Jitender


2 Answers

for the markup you have given try

$("div:eq(1)").removeClass('margn');

or if you want to remove margn from divs that have class margn

$(".margn:eq(1)").removeClass("margn");

DEMO

like image 189
Rafay Avatar answered Mar 19 '26 00:03

Rafay


you can use jQuery here as per your tag in the question

just right the below code. Remember you include jquery file.

$(document).ready( function() {

$("#call").css("margin-top", "0 !important"); // or 
$("#call").css("margin-top", "0");     

});

EDIT : Also if you want to use only CSS you can refer the answer by @sandeep below. remember CSS works sepquentially so write your css in proper sequence.

in CSS

.margn{margin-top:20px;} /* after this line write style for your div having id. */
#call {margin:0;}
like image 23
Murtaza Avatar answered Mar 18 '26 23:03

Murtaza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!