在按钮内对齐内容

时间:2019-03-16 11:19:51

标签: html css bootstrap-4

我已经使用Google材质图标在按钮中的文本之前添加了“播放”徽标。但是,插入图标后,文本和图标都将略微移出其位置,并且不会保持其中心对齐。如何保持对齐?

.play{
    border: 1px solid black;
    border-radius: 20px;
    padding: 5px 25px;
    text-transform: uppercase;
    margin: 10px;
    background-color: transparent;
    color: black;
}

.play::before{
    font-family: 'Material Icons';
    content: 'play_circle_filled';
    position: relative;
    text-transform: lowercase;
    font-size: 18px;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="container d-flex flex-row justify-content-center buttons" style="font-size: 12px;">
                    
                   
<button type="button" class="play"><span class="playicon"></span>Play into video</button>
                </div>

2 个答案:

答案 0 :(得分:2)

只需添加align-items-center并同时使按钮d-flex ...

<div class="container d-flex align-items-center justify-content-center buttons">
    <button type="button" class="play d-flex align-items-center"><span class="playicon"></span> Play into video</button>
</div>

https://www.codeply.com/go/iOqyT71QKy

注意:您不需要flex-row,因为默认是flex-direction:row。

答案 1 :(得分:0)

这是一种更改伪元素的字体大小的方法。

.play::before{
  font-family: 'Material Icons';
  content: 'play_circle_filled';
  position: relative;
  text-transform: lowercase;
  font-size: inherit;
  top:1px;
  left:-4px;
}

不知道它是否对您有用。这只是一个尝试。 谢谢。

.play{
  border: 1px solid black;
  border-radius: 20px;
  padding: 5px 25px;
  text-transform: uppercase;
  margin: 10px;
  background-color: transparent;
  color: black;
}

.play::before{
  font-family: 'Material Icons';
  content: 'play_circle_filled';
  position: relative;
  text-transform: lowercase;
  font-size: inherit;
  top:1px;
  left:-4px;
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
  </head>
  <body>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <div class="container d-flex flex-row justify-content-center buttons" style="font-size: 12px;">
      <button type="button" class="play"><span class="playicon"></span>Play into video</button>
    </div>
  </body>
</html>