小编jul*_*ude的帖子

中心CSS按钮,宽度为auto

我想有一个按钮width:auto;display:block;.此按钮应居中margin:0 auto.但如果我把所有人放在一起,它就行不通.

我究竟做错了什么?

码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asd</title>
</head>
<body>
I am an example content and I should be above the button. I want to have an auto width and being centered
<style type="text/css">
    .btn{
            color:black;
            font-size: 14px;
            line-height:14px;
            text-align: center;
            font-weight: bold;
            margin:0 auto;
            height:14px;
            display:block;
            cursor: pointer;
            background-color:red;
            padding:15px;
            text-decoration:none;   
    }
</style>
<a class="btn">helloworld</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

css center button

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

button ×1

center ×1

css ×1