CSS
让div在另一个div里居中的方法
关键在于transform: translate(-50%, -50%);
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
background-attachment:fixed, background-size:cover
这两个背景图CSS样式很有用:
background-attachment:fixed, background-size:cover
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_parallax_percent
https://www.w3schools.com/CSSref/css3_pr_background-size.asp
CSS函数calc
width: calc(100% - 100px);
如何使用CSS使两个元素始终处于同一个位置
为了便于观察,我把边框尺寸做成不一样。
<div style="position:relative">
<div style="width:100px;height:100px;border:3px solid #f00"> </div><div style="width:100px;height:100px;border:1px solid #00f;position:absolute;top:0;left:0"> </div>
</div>