部分项目案列总结:
背景色与背景图共存问题:
<style>
.box{
width: 400px;
height: 400px;
border: 1px solid #f40;
margin: 100px auto;
position: relative;
background: linear-gradient(to right top,#000,rgb(143, 0, 76));
}
.box::after{
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url("./bs.png") center ;
}
</style>
<body>
<div class="box"> </div>
</body>
元素在盒子里面居中
<style>
.father{
width: 500px;
height: 500px;
border: 1px solid #f40;
margin: 100px auto;
position: relative;
}
.son{
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top: 50%;
left: 50%;
margin-left: -50px;
margin-top: -50px;
}
</style>
<div class="father">
<div class="son"></div>
</div>
<style>
.father{
width: 500px;
height: 500px;
border: 1px solid #f40;
margin: 100px auto;
position: relative;
}
.son{
width: 100px;
height: 100px;
background-color: red;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
</style>
<div class="father">
<div class="son"></div>
</div>
<style>
.father{
width: 500px;
height: 500px;
border: 1px solid #f40;
margin: 100px auto;
display: flex;
justify-content: center;
align-items: center;
}
.son{
width: 100px;
height: 100px;
background-color: red;
}
</style>
<div class="father">
<div class="son"></div>
</div>