绝对定位或者固定定位的元素能够用left、right、top、bottom四个属性指定,那么这四个属性与元素所处的位置还有元素的宽度和高度有什么关系呢?css
代码以下:
html和csshtml
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> main { position: fixed; left: 0; right: 100px; top: 100px; bottom: 100px; background-color: gray; } </style> </head> <body> <main> <article style="width:100px"></article> </main> </body> </html>
结果以下图:
能够看到元素的上下左右边界所处的位置分别由四个属性指定,宽度和高度是父元素的宽度和高度减去四个属性。web
main { position: fixed; right: 100px; top: 100px; bottom: 100px; background-color: gray; }
获得的效果以下图:
咱们能够发现,元素的宽度是100px,也就是左边的全部剩余空间都被分配到了left上,咱们能够假定这是left的默认值。svg