+ 3

I can not align the block

Хочу выровнять по центру страницы отдельно взятый блок. Но через <div align="center" class="section"> выравнивается непосредственно текст в блоке, а не сам блок. Что делать? I want to align an individual block on the center of the page. But the <div align = "center" class = "section"> aligns the text directly in the block, not the block itself. What to do?

3rd Nov 2017, 8:08 AM
Павел Терюхов
Павел Терюхов - avatar
5 ответов
+ 11
<!--have you tried using margin-left: auto; margin-right: auto; --> <!--@Vengat let's assume he closed the div... --> <body> <div id="center_align"></div> <style> div{ margin-left: auto; margin-right: auto; background-color: rebeccapurple; width: 200px; height:400px; } </style> </body>
3rd Nov 2017, 10:20 AM
Lord Krishna
Lord Krishna - avatar
+ 5
Where is your closing tag? Blocks without closing tags won't align
3rd Nov 2017, 8:59 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
'align' attribute is deprecated in Html5, and should be auto-corrected as 'text-align' css property wich apply on element content... <div> is container of type block, so it take the whole width available: centering it as is have no really sense (by the way, it's still and always centered)... Anyway, you can center a block by different ways... I could enumerate some, but it would be more efficient if you would provide your whole code to help you with a good suited solution ^^
3rd Nov 2017, 10:11 AM
visph
visph - avatar
+ 1
I think, that problem not this. I have closing tag.
3rd Nov 2017, 9:30 AM
Павел Терюхов
Павел Терюхов - avatar
0
Lord Krishna, instead of 2 margin rules, you could shorten to a single rule : div { width: 800px; border : 1px solid gray ; margin: 0 auto; }
4th Nov 2017, 2:31 AM
Alex Maday
Alex Maday  - avatar