<!DOCTYPE html> <head> <style>#wrapper{width:800px;position:absolute;left:50%;margin-left: -400px;height:300px;border:1px solid red} </style> <body> <div id="wrapper"></div> </body></html>
The style of the body is: text-align:center;
The following div: width: 960px; margin:0 auto;
The style of the body is: text-align:center;
The following div: width:960px; margin:0 auto;
<!DOCTYPE html> <head> <style>#wrapper{width:800px;position:absolute;left:50%;margin-left: -400px;height:300px;border:1px solid red} </style> <body style="text-align:center;"> <div style="width:960px;margin:auto;"> <div id="wrapper"></div> <div>123</div> </div> </body></html>
Of course not~~~~123 is inside the wrapper. Of course it is wrong~~
Use float, clear
123 is outside the wrapper
The wrapper is absolutely positioned. If you want 123 to be directly below the wrapper, then 123 must also be positioned absolutely
Is this very confusing?
123 is outside the wrapper
The wrapper is absolutely positioned. If you want 123 to be directly below the wrapper, then 123 must also be absolutely positioned
Is this very confusing?
In order to facilitate observation, I set the height of this wrapper to be fixed. In actual application, the height of the wrapper is obviously adaptive.
So it is difficult~~~~
I feel that the style problem is not a problem, but I don’t understand what you mean now
How about you draw a rendering (simple and clear), the absolute positioning is not very reliable, and the resolution is different , will be misaligned
What’s so incomprehensible about this?
The style he mentioned is: what it looks like when you intercept the two areas of "reply to" and "I feel"
The former is a wrapper and the latter is 123
Since the wrapper is absolutely positioned, So 123 must also be positioned absolutely. That is, the upper left corner of 123 should coincide with the lower left corner of the wrapper
If the height of the wrapper is adaptive, then 123 must dynamically obtain the height of the wrapper to achieve positioning. This cannot be achieved without the participation of js
Of course, it is much simpler to use relative positioning or without div
Dear, you can take a look at this, I adjusted it a little
<!DOCTYPE html> <head> <style>#wrapper{width:800px;position:absolute;left:50%;margin-left: -400px;height:300px;border:1px solid red}#wrapper2{position:absolute;width:40px;height:40px;border:1px solid green;left:50%;top:310px} </style> <body><div id="wrapper"></div><div id="wrapper2">123</div> </body></html>
<!doctype html><html><head><style>* {padding:0px;margin:0px;}body {background:#ccc;}#page {width:802px;margin-left:auto;margin-right:auto;margin-top:10px;}#wrapper1 {width:800px;height:300px;border:1px solid red;background:white;}#wrapper2 {width:800px;height:300px;border:1px solid blue;background:white;}</style></head><body><div id="page"><div id="wrapper1">div1</div><div id="wrapper2">div2</div></div></body></html>