css一些小技巧

时间:2022-10-06 02:43:34

1.元素的垂直水平居中

<style>
.father{
   position: relative;
}
.sun{
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}
</style>
<div class="father">
   <div class="sun"></div>
</div>

2.强制禁止换行

 white-space:nowrap;

3.超出出现滚动条

<style>
   .slide{
         overflow: auto;
         width: 100%;
    }
</style>
<div class="slide">
</div>