如何在按钮上打红叉?

How to have red cross on button?

我需要在按钮上打一个红叉(字体很棒的图标)。

我试过的代码在 JSFiddle.

但我需要:


更新

我认为有一个小代码的解决方案将有助于执行与其相关的所有代码,因此更早地接受了

但是按照 将代码更改为主代码时,我无法达到预期的结果。

完整代码:

.button_cstm_quit {
  background-color: red;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
}

.button_cstm_quit:hover {
  color: red;
  font-weight: bold;
  background: none;
  border: 2px solid red;
}

.button_cstm_ll {
  background-color: blue;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
}

.button_cstm_ll:hover {
  color: blue;
  font-weight: bold;
  background: none;
  border: 2px solid blue;
}

.button_cstm_time {
  background-color: #FF8C00;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
}

.button_cstm_time:hover {
  color: #FF8C00;
  font-weight: bold;
  background: none;
  border: 2px solid #FF8C00;
}

#container_cstm {
  width: 100%;
}

#left_cstm {
  float: left;
  width: 100px;
}

#right_cstm {
  float: right;
  width: 100px;
}

#center_cstm {
  margin: 0 auto;
  width: 100px;
}

#play_head {
  display: flex;
  /* establish flex container */
  flex-direction: row;
  /* default value; can be omitted */
  flex-wrap: nowrap;
  /* default value; can be omitted */
  justify-content: space-between;
  /* switched from default (flex-start, see below) */
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">

<body bgcolor="Aqua">
  <div id="play_head">
    <div>
      <button class="button_cstm_quit"><i class="fas fa-sign-out-alt"></i></button>
    </div>
    <div>
      <button class="button_cstm_ll" style='margin-right:45px'>50</button>
      <button class="button_cstm_ll" style='margin-right:45px'>x2</button>
      <button class="button_cstm_ll" style='margin-right:45px'><i class="fas fa-sync"></i></button>
    </div>
    <div>
      <button class="button_cstm_time"><i class="fas fa-sync"></i></button>
    </div>
  </div>
</body>

I need that cross on all blue color buttons. (Sometimes all, sometimes 1 or 2. So div or i should be separate for each button)


Note: Placements of buttons can be anywhere, try to avoid left, right from the screen.

JSFiddle 不同答案:

如果您在按钮中添加图标并将 position: relative 分配给按钮,将 position: absolute 分配给图标,那么它应该可以工作。然后你可以用 left, righttransform:

定位它

.button_cstm_ll {
      background-color: blue;
      border: none;
      color: white;
      padding: 10px;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 35px;
      margin: 4px 2px;
      cursor: pointer;
      border-radius: 50%;
      position: relative;
}

.button_cstm_ll i {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      font-size: 2.5em;
}

.button_cstm_ll:hover {
      color: blue;
      font-weight: bold;
      background: none;
      border: 2px solid blue;
}
<body bgcolor="Aqua">
<link href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" rel="stylesheet" />
<button class="button_cstm_ll" style='margin-right:45px'><i id="cmplt" class="fas fa-times" style="color: red;"></i>50</button>
</body>

您可以使用 position: relativeposition: absolute 来获得所需的结果。试试这个代码。

<body bgcolor="Aqua">
  <link href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" rel="stylesheet" />
  <button class="button_cstm_ll" style='margin-right:45px'><i id="cmplt" class="fas fa-times" style="color: red;"></i>50</button>
</body>

.button_cstm_ll {
  background-color: blue;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
  height: 100px;
  width: 100px;
  position: relative;
}

.button_cstm_ll:hover {
  color: blue;
  font-weight: bold;
  background: none;
  border: 2px solid blue;
}
.button_cstm_ll .fas {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 150px;
  line-height: 0.7;
}

.button_cstm_quit {
  background-color: red;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
}

.button_cstm_quit:hover {
  color: red;
  font-weight: bold;
  background: none;
  border: 2px solid red;
}

.button_cstm_ll {
  background-color: blue;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
  position: relative;
}

.button_cstm_ll:hover {
  color: blue;
  font-weight: bold;
  background: none;
  border: 2px solid blue;
}

.button_cstm_time {
  background-color: #FF8C00;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
}

.button_cstm_time:hover {
  color: #FF8C00;
  font-weight: bold;
  background: none;
  border: 2px solid #FF8C00;
}

#container_cstm {
  width: 100%;
}

#left_cstm {
  float: left;
  width: 100px;
}

#right_cstm {
  float: right;
  width: 100px;
}

#center_cstm {
  margin: 0 auto;
  width: 100px;
}

#play_head {
  display: flex;
  /* establish flex container */
  flex-direction: row;
  /* default value; can be omitted */
  flex-wrap: nowrap;
  /* default value; can be omitted */
  justify-content: space-between;
  /* switched from default (flex-start, see below) */
}

.button_cstm_ll:before, .button_cstm_ll:after {
  position:absolute;
  content: '';
  top: -5px;
  bottom: -5px;
  width: 5px;
  background: #ff0000;
  left: 0;
  right: 0;
  margin: 0 auto;
  
}
.button_cstm_ll:before {
transform: skew(30deg);
}
.button_cstm_ll:after {
transform: skew(-30deg);
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">

<body bgcolor="Aqua">
  <div id="play_head">
    <div>
      <button class="button_cstm_quit"><i class="fas fa-sign-out-alt"></i></button>
    </div>
    <div>
      <button class="button_cstm_ll" style='margin-right:45px'>50</button>
      <button class="button_cstm_ll" style='margin-right:45px'>x2</button>
      <button class="button_cstm_ll" style='margin-right:45px'><i class="fas fa-sync"></i></button>
    </div>
    <div>
      <button class="button_cstm_time"><i class="fas fa-sync"></i></button>
    </div>
  </div>
</body>

.button_cstm_ll {
  background-color: blue;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
}

.button_cstm_ll:hover {
  color: blue;
  font-weight: bold;
  background: none;
  border: 2px solid blue;
}

#cmplt:before {
  position: absolute;
  left: 14px;
  top: 22px;
}
<body bgcolor="Aqua">
  <link href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" rel="stylesheet" />
  <i id="cmplt" class="fas fa-times" style="color: red;font-size:70px;"><button class="button_cstm_ll" style='margin-right:45px'>50</button></i>
</body>

试试这个

.button_cstm_ll {
  background-color: blue;
  border: none;
  color: white;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 35px;
  margin: 4px 2px;
  cursor: pointer;
  border-radius: 50%;
}

.button_cstm_ll:hover {
  color: blue;
  font-weight: bold;
  background: none;
  border: 2px solid blue;
}

i#cmplt:before {
position: absolute;
font-size: 1.5em;
left: 10px;
}
<body bgcolor="Aqua">
  <link href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" rel="stylesheet" />
  <i id="cmplt" class="fas fa-times fa-3x" style="color: red;"><button class="button_cstm_ll" style='margin-right:45px'>50</button></i>
</body>