css calc()函数 长度运算
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>菜鸟教程(runoob.com)</title> 6 <style> 7 #div1 { 8 position: absolute; 9 left: 50px; 10 width: calc(100% - 6rem); 11 border: 1px solid black; 12 background-color: yellow; 13 padding: 5px; 14 text-align: center; 15 } 16 </style> 17 </head> 18 19 <body> 20 <p>创建一个横跨屏幕的div,div 两边有 50px 的间隙:</p> 21 <div id="div1">一些文本...</div> 22 </body> 23 </html>
附:1rem=10px