Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align a DIV tag without knowing the width [duplicate]

Tags:

html

css

center

Possible Duplicate:
How can I center something if I don't know ahead of time what the width is?

I want to know how to align a div tag withought knowing a width. This is different to other questions as I would not mind using the <center> tag but it seems to be 'old' in the HTML groups view. Will the <center> tag still be working in the future?

Thanks

like image 786
William Burnside Avatar asked Feb 03 '26 15:02

William Burnside


2 Answers

I usually use width:auto or width:100% than margin:0 auto;

However you can see the details on the link below as its almost the same question as yours!

How can I center align a div without knowing the width?

like image 188
Code Lover Avatar answered Feb 05 '26 07:02

Code Lover


Blocks elements are centered by setting left and right margins to auto.

margin-left: auto;
margin-right: auto;

<center> work continue to work for the foreseeable future, so there is no technical reason not to use it, however in modern web development one should acknowledge the principle of "separation of presentation and content" and use HTML for semantics and CSS for layout.

like image 43
RoToRa Avatar answered Feb 05 '26 07:02

RoToRa



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!