I often see on sites how their content is in the center in a block, and the block is always (at different scales and screen resolutions) in the center of the page. I have already tried <center></ceter> and <div align="center"></div> and #ид дива{margin/padding:50%;} but still, if inside diva make position:absolute; then everything is not in the center, but as spelled in left/right: and top/bottom:

Help, how to make a block, always located in the middle of the page / another block, preferably without Css3. And one more question: to make the width to the end of the page: width: 100%, but how to make the height from the current position to the end of the page?

  • if you write position: absolute to the block, then such a block will go to the upper corner of the screen so that it is with your wrapper, you need to set position: relative to this wrapper and then the absolutely positioned block will be inside the wrapper, maybe you have a centering problem ? As you have already been told, margin: 0 auto and fixed width 100% working example - makregistr

2 answers 2

horizontal centering block fixed width

 div{ width: 150px; margin: 0 auto; } 

horizontal centering of the floating width block

to set the height of the block equal to 100% of the height of the visible part of the page of the same ( width:100% ), you must also set the html tag and the body tag

  • Does not work! - Rules
  • then there are styles that affect the target block - look for them. This is the working code that I used repeatedly. - qnub
 postion: absolute 

does not affect the centering of the element. using this property you can absolutely position it relative to the parent element. that is, you strictly indicate where the element should be located. therefore, at different resolutions, the element itself will move. The previous advice is the most effective way. I always use it too. there is another way: specify a negative value of the left margin equal to half the width of the parent element. In combination, these two methods give practically accurate centering of the element on the page.