盒子進行水平垂直居中transform+position,input框的下拉按鈕的設計,transform的2D轉換以及transition過渡效果應用
阿新 • • 發佈:2021-01-31
效果如圖:
程式碼展示:
<style>
* {
margin: 0;
padding: 0;
}
.box {
position: relative;
width: 800px;
height: 800px;
background-color: #999999;
}
.text {
position : absolute;
top: 50%;
left: 50%;
height: 25px;
width: 200px;
border: 1px solid #333333;
/*
相對於自身寬或者高的移動,距離為:寬/2、高/2,
可以讓盒子進行水平垂直居中,
不用設定margin-left或者margin-right.
*/
transform : translate(-50%, -50%);
}
.text::after {
content: "";
position: absolute;
top: 8px;
right: 11px;
width: 8px;
height: 8px;
cursor: pointer;
/* 三角設計 */
border-bottom: 1px solid #030303;
border-right: 1px solid #030303;
/* 讓三角進行旋轉45度,下拉模式 */
transform: rotate(45deg);
/* 過渡效果 */
transition: all .3s ease;
/* 設定旋轉中心 */
transform-origin: center;
}
.text:hover::after {
/* 滑鼠放在三角時旋轉,進而呈現上拉模式 */
transform: rotate(225deg);
}
</style>
</head>
<body>
<div class="box">
<div class="text"></div>
</div>
</body>
如有不懂得或者想要和小編進行探討相關問題的大佬,可以在下面討論哈~