CSS 实现一个居中的按钮

代码源自网易的一个页面 : http://dhxy.163.com/m/2017/xinfu7/
<html>
<head>

<style type="text/css">
	
	html {
		font-size: 1000%;
	}

	.tips {
		height: 1rem;
		border: 1px solid black;
	}
	
	.tips a {  
	    background: url(https://img-blog.csdn.net/20180104001341736) 0 0 no-repeat;  
	    background-size: 100% 100%;  
	    width: 1.82rem;  
	    height: .55rem;  
	    margin: .2rem auto 0;  
	    text-align: center;  
	    line-height: .46rem;  
	    font-size: .26rem;  
	    font-weight: 700;  
	    color: #fff9e5;  
	    display: block;  
	    text-decoration: none;
	}  
</style>
</head>
<body>

<div class="tips">  
     <a href="javascript:;" bind="#pop-rules1">活动规则</a>  
</div>  

</body>
</html>
背景图片在博客里保存一下:



1. 使用 display:block 将a标签设置为块级元素。
2. 设置按钮的 height, width 以及 margin. 其中 margin-left 和 margin-right 设置为auto实现了按钮在父元素中水平居中。
3. 使用 background-size: 100% 100% 来填充一个按钮背景。
4. 使用 text-align: center 实现文字的水平居中, 使用 line-height 实现文字的垂直居中。

效果图如下: 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值