Как сделать красный крестик на кнопке? - PullRequest
0 голосов
/ 02 мая 2018

Мне нужен красный крестик (шрифт потрясающий значок) на кнопке.

Код, который я пробовал: JSFiddle .

Но мне нужно:

expected image


UPDATE

Я думал, что решение с небольшим кодом поможет выполнить все коды, связанные с ним, и поэтому принял ответ Киранвжа ранее.

Но при изменении кодов согласно Киранджи отвечает на основной код, я не смог достичь ожидаемых результатов.

Полный код:

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

Мне нужен этот крестик на всех синих цветных кнопках. (иногда все, иногда 1 или 2. Поэтому div или i должны быть отдельными для каждой кнопки)


Примечание: Расположение кнопок может быть где угодно, старайтесь избегать left, right с экрана .

JSFiddle с разными ответами:

Ответы [ 5 ]

0 голосов
/ 02 мая 2018

Попробуйте это

.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>
0 голосов
/ 02 мая 2018

.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>
0 голосов
/ 02 мая 2018

Вы можете использовать position: relative и position: 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;
}
0 голосов
/ 02 мая 2018

.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>
0 голосов
/ 02 мая 2018

Если добавить значок внутри кнопки и назначить position: relative для кнопки и position: absolute для значка, то он должен работать. Затем вы можете расположить его с помощью left, right и transform:

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