Home > front end >  inside flex box not able align at end for label with pseudo elements
inside flex box not able align at end for label with pseudo elements

Time:04-27

In below snippet i have the tool name and same row one radio button also, But even though i have given space-between but the radio button is not at the end.

How can i align the radio button to the end of right side like how normally the space-between works

.container-section-column-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

input[type='radio'] {
  display: none;
}

label {
  cursor: pointer;
  position: relative;
  font-size: 4rem;
}

label::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background-color: transparent;
  border: 2px solid grey;
  border-radius: 50%;
  top: 50%;
  left: -5rem;
  transform: translateY(-50%);
  transition: border-color 400ms ease;
}

label::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background-color: red;
  border: 2px solid red;
  border-radius: 50%;
  top: 50%;
  left: -5rem;
  transform: translateY(-50%) scale(0);
  transition: transform 400ms ease;
}

input[type='radio']:checked label::before {
  border-color: red;
}

input[type='radio']:checked label::after {
  transform: translateY(-50%) scale(0.55);
}
<div class='container-section'>
  <div class='container-section-column-wrapper'>
    <div class='column-one'>
      <div class='tool-name'>Tool one</div>
    </div>
    <div class='column-two'>
      <input type='radio' id='tool-one' name='tool-pick-group' />
      <label for='tool-one' />
    </div>
  </div>

CodePudding user response:

It's because your pseudo-elements :before and :after are absolutely positioned in a relatively positioned parent (label). You are specifying left: -5rem; to try and align back further left which is causing the spacing you see. Instead, just use right: 0;.

.container-section-column-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

input[type='radio'] {
  display: none;
}

label {
  cursor: pointer;
  position: relative;
  font-size: 4rem;
}

label::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background-color: transparent;
  border: 2px solid grey;
  border-radius: 50%;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  transition: border-color 400ms ease;
}

label::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background-color: red;
  border: 2px solid red;
  border-radius: 50%;
  top: 50%;
  right: 0;
  transform: translateY(-50%) scale(0);
  transition: transform 400ms ease;
}

input[type='radio']:checked label::before {
  border-color: red;
}

input[type='radio']:checked label::after {
  transform: translateY(-50%) scale(0.55);
}
<div class='container-section'>
  <div class='container-section-column-wrapper'>
    <div class='column-one'>
      <div class='tool-name'>Tool one</div>
    </div>
    <div class='column-two'>
      <input type='radio' id='tool-one' name='tool-pick-group' />
      <label for='tool-one' />
    </div>
  </div>

  • Related