单选按钮文本涵盖以下选项

Radio button text covers options below

我正在使用这个单选按钮效果 - https://codepen.io/tomma5o/pen/grJyzL/ 工作正常,但现在我 运行 遇到了问题,我的一些选项是较长的文本并且它越过底部选项(因为那里在 li 上是 30px 高度)。

这是示例 - https://codepen.io/BrixyX/pen/OJMwjrN。有什么简单的解决方法吗,因为无论我尝试什么,都会弄乱效果?

@import url(https://fonts.googleapis.com/css?family=Roboto:400,300,500,700);
 ::selection {
  background: none;
}

body {
  background: #BADA55;
  font-family: 'Roboto';
  font-weight: 500;
  text-transform: uppercase;
  color: #2E8612;
  overflow: hidden;
  height: 100%;
}

h1 {
  font-weight: 100;
  text-align: center;
  margin: 0;
  padding: 0;
  font-size: 50px;
}

h4 {
  font-weight: 400;
  text-align: center;
  margin: 0;
  padding: 0;
  margin-bottom: 50px;
}

.continput {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 500px;
  height: 270px;
  padding: 16px;
  box-sizing: border-box;
}

ul {
  list-style-type: none;
  width: 220px;
  margin: auto;
}

li {
  position: relative;
  padding: 10px;
  padding-left: 40px;
  height: 30px;
}

label:before {
  content: "";
  width: 15px;
  height: 15px;
  background: #fff;
  position: absolute;
  left: 7px;
  top: calc(50% - 13px);
  box-sizing: border-box;
  border-radius: 50%;
}

input[type="radio"] {
  opacity: 0;
  -webkit-appearance: none;
  display: inline-block;
  vertical-align: middle;
  z-index: 100;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 30px;
  position: absolute;
  left: 0;
  top: calc(50% - 15px);
  cursor: pointer;
}

.bullet {
  position: relative;
  width: 25px;
  height: 25px;
  left: -3px;
  top: 2px;
  border: 5px solid #fff;
  opacity: 0;
  border-radius: 50%;
}

input[type="radio"]:checked~.bullet {
  position: absolute;
  opacity: 1;
  animation-name: explode;
  animation-duration: 0.350s;
}

.line {
  position: absolute;
  width: 10px;
  height: 2px;
  background-color: #fff;
  opacity: 0;
}

.line.zero {
  left: 11px;
  top: -21px;
  transform: translateY(20px);
  width: 2px;
  height: 10px;
}

.line.one {
  right: -7px;
  top: -11px;
  transform: rotate(-55deg) translate(-9px);
}

.line.two {
  right: -20px;
  top: 11px;
  transform: translate(-9px);
}

.line.three {
  right: -8px;
  top: 35px;
  transform: rotate(55deg) translate(-9px);
}

.line.four {
  left: -8px;
  top: -11px;
  transform: rotate(55deg) translate(9px);
}

.line.five {
  left: -20px;
  top: 11px;
  transform: translate(9px);
}

.line.six {
  left: -8px;
  top: 35px;
  transform: rotate(-55deg) translate(9px);
}

.line.seven {
  left: 11px;
  bottom: -21px;
  transform: translateY(-20px);
  width: 2px;
  height: 10px;
}

input[type="radio"]:checked~.bullet .line.zero {
  animation-name: drop-zero;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

input[type="radio"]:checked~.bullet .line.one {
  animation-name: drop-one;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

input[type="radio"]:checked~.bullet .line.two {
  animation-name: drop-two;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

input[type="radio"]:checked~.bullet .line.three {
  animation-name: drop-three;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

input[type="radio"]:checked~.bullet .line.four {
  animation-name: drop-four;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

input[type="radio"]:checked~.bullet .line.five {
  animation-name: drop-five;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

input[type="radio"]:checked~.bullet .line.six {
  animation-name: drop-six;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

input[type="radio"]:checked~.bullet .line.seven {
  animation-name: drop-seven;
  animation-delay: 0.100s;
  animation-duration: 0.9s;
  animation-fill-mode: forwards;
}

@keyframes explode {
  0% {
    opacity: 0;
    transform: scale(10);
  }
  60% {
    opacity: 1;
    transform: scale(0.5);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes drop-zero {
  0% {
    opacity: 0;
    transform: translateY(20px);
    height: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translateY(-2px);
    height: 0px;
    opacity: 0;
  }
}

@keyframes drop-one {
  0% {
    opacity: 0;
    transform: rotate(-55deg) translate(-20px);
    width: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: rotate(-55deg) translate(9px);
    width: 0px;
    opacity: 0;
  }
}

@keyframes drop-two {
  0% {
    opacity: 0;
    transform: translate(-20px);
    width: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translate(9px);
    width: 0px;
    opacity: 0;
  }
}

@keyframes drop-three {
  0% {
    opacity: 0;
    transform: rotate(55deg) translate(-20px);
    width: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: rotate(55deg) translate(9px);
    width: 0px;
    opacity: 0;
  }
}

@keyframes drop-four {
  0% {
    opacity: 0;
    transform: rotate(55deg) translate(20px);
    width: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: rotate(55deg) translate(-9px);
    width: 0px;
    opacity: 0;
  }
}

@keyframes drop-five {
  0% {
    opacity: 0;
    transform: translate(20px);
    width: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translate(-9px);
    width: 0px;
    opacity: 0;
  }
}

@keyframes drop-six {
  0% {
    opacity: 0;
    transform: rotate(-55deg) translate(20px);
    width: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: rotate(-55deg) translate(-9px);
    width: 0px;
    opacity: 0;
  }
}

@keyframes drop-seven {
  0% {
    opacity: 0;
    transform: translateY(-20px);
    height: 10px;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translateY(2px);
    height: 0px;
    opacity: 0;
  }
}
<div class="continput">
  <h1>Jelly Radio btn</h1>
  <h4>I hope you enjoyed it</h4>
  <ul>
    <li>
      <input checked type="radio" name="1">
      <label>OMG a radio! Longer option text Longer option text Longer option text Longer option text Longer option text Longer option text Longer option text Longer option ...</label>
      <div class="bullet">
        <div class="line zero"></div>
        <div class="line one"></div>
        <div class="line two"></div>
        <div class="line three"></div>
        <div class="line four"></div>
        <div class="line five"></div>
        <div class="line six"></div>
        <div class="line seven"></div>
      </div>
    </li>
    <li>
      <input type="radio" name="1">
      <label>Uuuuh radio</label>
      <div class="bullet">
        <div class="line zero"></div>
        <div class="line one"></div>
        <div class="line two"></div>
        <div class="line three"></div>
        <div class="line four"></div>
        <div class="line five"></div>
        <div class="line six"></div>
        <div class="line seven"></div>
      </div>
    </li>
    <li>
      <input type="radio" name="1">
      <label>radio everywhere</label>
      <div class="bullet">
        <div class="line zero"></div>
        <div class="line one"></div>
        <div class="line two"></div>
        <div class="line three"></div>
        <div class="line four"></div>
        <div class="line five"></div>
        <div class="line six"></div>
        <div class="line seven"></div>
      </div>
    </li>
  </ul>
</div>

有多种方法可以解决长选项文本覆盖其余选项的问题。

第一个选项 是将连续输入 class 的宽度更改为更高的值,以便标签内可以容纳更多文本。标签受到列表启用的边距和填充的限制,单选按钮放在其中的列表项。因此,更宽的宽度意味着可以整齐地显示更多的选项文本。

第二个选项是将列表项的溢出属性设置为隐藏,像这样(定义底部的新属性 ):

li {
  position: relative;
  padding: 10px;
  padding-left: 40px;
  height: 30px;
  overflow: hidden;
}

这样,如果不从列表项中溢出就无法显示的文本将被隐藏,并且不会覆盖属于单选按钮的文本。溢出设置也有更多选项; Mozilla MDN 网络文档有一篇关于 属性 的短文:https://developer.mozilla.org/en-US/docs/Web/CSS/overflow

第三个选项是上面这些选项的组合。这应该会产生符合您需要的外观和工作方式。如果您还没有开始使用 Google Chrome 的 Inspect 功能检查和试验您自己的内容,我建议您阅读适用于您正在使用的浏览器的教程。 Zapier 有一个针对 Google Chrome here 的深入教程,我看到微软已经将 Google Chrome 中可用的相同工具合并到他们的更新中Microsoft Edge(带有蓝色和绿色徽标)。

我已经清理了一些东西并用你的笔 here 创建了一个新的 fiddle。

首先,我尝试删除在很多地方使用的 absolute 定位。 我还利用了 label 元素提供的与输入元素交互的功能。

我已将您的 radio 元素移到标签内,并相应地移动了项目符号动画。

总的来说,label 元素现在用作其中所有元素的包装器,因此这些元素将根据其父元素的大小自行对齐。

P.S.,因为我想快速总结一下,所以我使用 translate(-50%) hack 将项目符号居中对齐在您的标签内。还有其他更简洁的方法可以做到这一点,但目前这只是一种更快捷的方法。