Search code examples
htmlcssbuttonfont-awesomefont-awesome-5

How to have red cross on button?


I need a red cross (font awesome icon) on the button.

The code I tried is at JSFiddle.

But I need:

expected image


UPDATE

I thought having a solution with a small code will help to execute on all codes related to it and therefore accepted Kiranvj's answer earlier.

But while changing codes as per Kiranvj's answer to the main code I couldn't achieve the expected results.

Full Code:

.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 with different answers:


Solution

  • .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>