怎么通过css样式制作一个正方形的叉子按钮?

代码如下:


    <style>

        .cancel-btn {

            background: #ccc;

            color: white;

            padding: 1em;

        }

    </style>

</head>

<body>

    <h1>Testing</h1>


    <span class='cancel-btn'></span>


</body>

图片效果是这样的,高度总是要比宽度大一点儿,请问应该怎么制作正方形的按钮呢?谢谢大佬T_T

https://img4.mukewang.com/5ca815c10001406a03470191.jpg

炎炎设计
浏览 570回答 2
2回答

GCT1015

.cancel&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; width: 100px;&nbsp; &nbsp; &nbsp; &nbsp; height: 100px;&nbsp; &nbsp; &nbsp; &nbsp; background-color: #333333;&nbsp; &nbsp; &nbsp; &nbsp; position: relative;&nbsp; &nbsp; }&nbsp; &nbsp; .cancel::before&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; content: '';&nbsp; &nbsp; &nbsp; &nbsp; position: absolute;&nbsp; &nbsp; &nbsp; &nbsp; top: 50%;&nbsp; &nbsp; &nbsp; &nbsp; left: 50%;&nbsp; &nbsp; &nbsp; &nbsp; width: 50px;&nbsp; &nbsp; &nbsp; &nbsp; height: 10px;&nbsp; &nbsp; &nbsp; &nbsp; background-color: #ffffff;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; transform: translateX(-50%) translateY(-50%) rotate(45deg);&nbsp; &nbsp; }&nbsp; &nbsp; .cancel::after&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; content: '';&nbsp; &nbsp; &nbsp; &nbsp; position: absolute;&nbsp; &nbsp; &nbsp; &nbsp; top: 50%;&nbsp; &nbsp; &nbsp; &nbsp; left: 50%;&nbsp; &nbsp; &nbsp; &nbsp; width: 50px;&nbsp; &nbsp; &nbsp; &nbsp; height: 10px;&nbsp; &nbsp; &nbsp; &nbsp; background-color: #ffffff;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; transform: translateX(-50%) translateY(-50%) rotate(-45deg);&nbsp; &nbsp; }<div class="cancel">&nbsp; &nbsp; </div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript