1. 程式人生 > 其它 >web前端:按鈕轉化變色,陰影box-shadow使用,動畫屬性transform:translate(-x,-y)居中樣式

web前端:按鈕轉化變色,陰影box-shadow使用,動畫屬性transform:translate(-x,-y)居中樣式

技術標籤:微信小程式csshtmlcss3jsless

1.less

* {
    margin: 0;
    padding: 0;
    body {
        a {
            //a標籤不可以設定寬高,需要display:inline-block
            display: inline-block;
            //未知寬高下居中使用trnasform:translate(x,y)
            width: 100px;
            height: 30px;
            //原本裝飾樣式decoration為none
            text-decoration
: none; position: absolute; background: skyblue; text-align: center; font: 20px/30px "微軟雅黑"; font-weight: bold; color: white; border: 1px solid darkcyan; //陰影:box-shadow:x-px , y-px ,模糊程度?px #color box-shadow
: 2px 2px 5px #4682B4; /** 新居中方法 1. top、height:百分比參照包含塊的高度 2. lefe、margin、padding、width:百分比參照包含塊的寬度 3. translate(-50%,-50%):百分比參照自身元素的寬高 4. background、position:百分比參照,圖片區域--》圖片點陣圖的畫素值 */ top
: 50%; left: 50%; //定位點在元素自身的寬高--》相容性不高 transform: translate(-50%, -50%); margin: auto; transition: 1.5s; } &:hover a { color: white; background: steelblue; } } }

2.css

* {
  margin: 0;
  padding: 0;
}
* body a {
  display: inline-block;
  width: 100px;
  height: 30px;
  text-decoration: none;
  position: absolute;
  background: skyblue;
  text-align: center;
  font: 20px/30px "微軟雅黑";
  font-weight: bold;
  color: white;
  border: 1px solid darkcyan;
  box-shadow: 2px 2px 5px #4682B4;
  /**
                                        新居中方法
             1. top、height:百分比參照包含塊的高度
             2. lefe、margin、padding、width:百分比參照包含塊的寬度
             3. translate(-50%,-50%):百分比參照自身元素的寬高
             4. background、position:百分比參照,圖片區域--》圖片點陣圖的畫素值
             */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: auto;
  transition: 1.5s;
}
* body:hover a {
  color: white;
  background: steelblue;
}

3.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>light button高亮按鈕</title>
	</head>
	<body>
		<a href="javascript:;">Home</a>
	</body>
	<link rel="stylesheet" href="css/less024.css" />
</html>

4.效果圖

cevent