I would like to center some html elements in my html page, for example a label. I want to accomplish this by using jQuery and CSS. Unfortunately I'm not familiar with jQuery.
I just need a little help from you guys.
Thank you.
Presentation is NOT a task for jQuery.
CSS:
label {display:block;text-align:center}
Try this simple function:
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
//Use the above function as:
$(element).center();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With