Urara-Blog/urara/margin/+page.md
2022-09-07 23:29:18 +08:00

34 lines
659 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: CSS · Add margin to buttons
slug: css-margin
tags:
- CSS Trick
- CSS
created: 2022-01-13T10:04:21.000Z
summary: 用helper class为单个按钮加margin防止元素复用时产生不必要的margin
lastmod: 2022-05-07T05:32:49.156Z
---
用 helper class 为单个按钮加 margin防止元素复用时产生不必要的 margin
## HTML
```html
<button class="btn helper">Text</button>
```
## CSS
```css
.helper {
margin-right: 1.6rem;
}
```
## 为按钮增加内边距
如果设置 border 数值为负,周边空间则会收到影响,但用 box-shadow 就不会:
所以可以这样设置:
`box-shadow: inset 0 0 0 3px #fff;`