【问题标题】:How to style a radio button to look like a regular Learn More Button如何设置单选按钮的样式,使其看起来像普通的“了解更多”按钮
【发布时间】:2020-12-08 20:17:14
【问题描述】:

我正在 Unqork 中设计一个应用程序。我遇到的问题是如何使单选按钮看起来像常规的“了解更多”按钮。我只打算设置单选按钮的样式,而不是使其成为多项选择。

常规按钮的样式是

.abc-quote-option-cta {
    bottom: 38px;
    left: 0;
    right: 0;
    padding-top: 24px;
    position: absolute; }

.abc-quote-option-cta:before {
    background-color: #979797;
    content: '';
    display: block;
    height: 1px;
    left: 62px;
    opacity: .36;
    position: absolute;
    right: 56px;
    top: 0;
}

.abc-quote-option-cta .btn.btn-primary {
    border-radius: 6px;
    border: solid 2px #01a7e1;
    background-color: #FFFFFF;
    border-radius: 6px;
    color: #01a7e1;
    display: block;
    font-size: 1.8rem;
    line-height: 1.44;
    margin: 0 auto;
    padding: 10px;
    text-align: center;
    transition: background-color .25s ease, width .13s ease-in, color .18s ease-out ;
    width: 188px;
}

.abc-quote-option-cta .btn.btn-primary:hover,
.abc-quote-option-cta .btn.btn-primary:focus {
    background-color: #0099cc;
    color: #FFFFFF;
    width: 251px;
}

非常感谢您的帮助。谢谢!

【问题讨论】:

  • 这能回答你的问题吗? How to style a checkbox using CSS
  • 嗨@djangotic,真的没有。这是一个复选框,但我只是希望将单选按钮的样式与常规的“了解更多”按钮完全一样。
  • 如果您不使用收音机在多个选项之间进行选择(“...而不是将其变成多项选择...”),为什么还要使用收音机呢?为什么不选择使用标准的button,这样设置样式可能会容易得多?
  • @esqew 是的,我同意,但是常规按钮的问题是它不能跳转到另一个页面。现在单击了解更多按钮后,它只会显示一条成功消息。
  • @SkipperLin 您能否详细说明您是如何得出“按钮...不能跳转到另一页”的结论的?这无疑是可以实现的,一个粗略的例子是:<button onclick='window.location = "https://google.com"'>Go to Google</button>

标签: html css unqork


【解决方案1】:

希望对你有帮助。

HTML:-

<form>
  <div class="radiobtn">
    <input type="radio" id="huey" name="drone" value="huey" checked />
    <label for="huey">Learn More</label>
  </div>
  <div class="radiobtn">
    <input type="radio" id="dewey" name="drone" value="dewey" />
    <label for="dewey">Learn More</label>
  </div>
</form>

CSS :-

form {
    max-width: 250px;
    position: relative;
    margin: 50px auto 0;
    font-size: 15px;
}
.radiobtn {
    position: relative;
    display: block;
}
.radiobtn label {
    display: block;
    background: rgba(0, 0, 0, 0.2);
    color: #000;
    border-radius: 5px;
    padding: 10px 20px;
    border: 2px solid grey;
    margin-bottom: 5px;
    cursor: pointer;
}
.radiobtn label:after, .radiobtn label:before {
    content: "";
    position: absolute;
    right: 11px;
    top: 11px;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    background:grey;
}
.radiobtn label:before {
    background: transparent;
    transition: 0.1s width cubic-bezier(0.075, 0.82, 0.165, 1) 0s, 0.3s height cubic-bezier(0.075, 0.82, 0.165, 2) 0.1s;
    z-index: 2;
    overflow: hidden;
    background-repeat: no-repeat;
    background-size: 13px;
    background-position: center;
    width: 0;
    height: 0;
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNS4zIDEzLjIiPiAgPHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE0LjcuOGwtLjQtLjRhMS43IDEuNyAwIDAgMC0yLjMuMUw1LjIgOC4yIDMgNi40YTEuNyAxLjcgMCAwIDAtMi4zLjFMLjQgN2ExLjcgMS43IDAgMCAwIC4xIDIuM2wzLjggMy41YTEuNyAxLjcgMCAwIDAgMi40LS4xTDE1IDMuMWExLjcgMS43IDAgMCAwLS4yLTIuM3oiIGRhdGEtbmFtZT0iUGZhZCA0Ii8+PC9zdmc+);
}
input[type="radio"] {
    display: none;
    position: absolute;
    width: 100%;
    appearance: none;
}
input[type="radio"]:checked + label {
    background:grey;
    animation-name: blink;
    animation-duration: 1s;
 border-color: $accentcolor;
}
input[type="radio"]:checked + label:after {
 background: $accentcolor;
}
input[type="radio"]:checked + label:before {
    width: 20px;
    height: 20px;
}

【讨论】:

    【解决方案2】:

    我希望这个 sn-p 对你有帮助。

    form {
        max-width: 250px;
        position: relative;
        margin: 50px auto 0;
        font-size: 15px;
    }
    .radiobtn {
        position: relative;
        display: block;
    }
    .radiobtn label {
        display: block;
        background: rgba(0, 0, 0, 0.2);
        color: #000;
        border-radius: 5px;
        padding: 10px 20px;
        border: 2px solid grey;
        margin-bottom: 5px;
        cursor: pointer;
    }
    .radiobtn label:after, .radiobtn label:before {
        content: "";
        position: absolute;
        right: 11px;
        top: 11px;
        width: 20px;
        height: 20px;
        border-radius: 3px;
        background:grey;
    }
    .radiobtn label:before {
        background: transparent;
        transition: 0.1s width cubic-bezier(0.075, 0.82, 0.165, 1) 0s, 0.3s height cubic-bezier(0.075, 0.82, 0.165, 2) 0.1s;
        z-index: 2;
        overflow: hidden;
        background-repeat: no-repeat;
        background-size: 13px;
        background-position: center;
        width: 0;
        height: 0;
        background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNS4zIDEzLjIiPiAgPHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE0LjcuOGwtLjQtLjRhMS43IDEuNyAwIDAgMC0yLjMuMUw1LjIgOC4yIDMgNi40YTEuNyAxLjcgMCAwIDAtMi4zLjFMLjQgN2ExLjcgMS43IDAgMCAwIC4xIDIuM2wzLjggMy41YTEuNyAxLjcgMCAwIDAgMi40LS4xTDE1IDMuMWExLjcgMS43IDAgMCAwLS4yLTIuM3oiIGRhdGEtbmFtZT0iUGZhZCA0Ii8+PC9zdmc+);
    }
    input[type="radio"] {
        display: none;
        position: absolute;
        width: 100%;
        appearance: none;
    }
    input[type="radio"]:checked + label {
        background:grey;
        animation-name: blink;
        animation-duration: 1s;
     border-color: $accentcolor;
    }
    input[type="radio"]:checked + label:after {
     background: $accentcolor;
    }
    input[type="radio"]:checked + label:before {
        width: 20px;
        height: 20px;
    }
    <form>
      <div class="radiobtn">
        <input type="radio" id="huey"
                         name="drone" value="huey" checked />
        <label for="huey">Learn More</label>
      </div>
      <div class="radiobtn">
        <input type="radio" id="dewey"
                         name="drone" value="dewey" />
        <label for="dewey">Learn More</label>
      </div>
    </form>

    【讨论】:

    • 嗨,Priya,这绝对有帮助。太感谢了。但是,有没有办法只制作一个单选按钮?这就像一个只有问题但没有选择的多项选择。
    • @SkipperLin 如果你想使用一个单选按钮。仅使用一个单选按钮。有什么困惑?
    • 对此感到抱歉。我对 CSS 不是很熟悉。还有一个问题,有没有办法让“了解更多”单选按钮不带复选标记?
    • 是的,如果你愿意,我可以附加另一个不带复选标记的 sn-p。
    • 那可能很棒!太感谢了。我的目标是使单选按钮看起来与常规按钮完全一样。
    【解决方案3】:

    没有复选标记的自定义单选按钮。

    form {
        max-width: 200px;
        position: relative;
        margin: 50px auto 0;
        font-size: 15px;
    }
    .radiobtn {
        position: relative;
        display: block;
        text-align:center;
    }
    .radiobtn label {
        display: block;
        background:none;
        color:#01a7e1;
        border-radius: 5px;
        padding: 10px 20px;
        border: 2px solid #01a7e1;
        margin-bottom: 5px;
        cursor: pointer;
        font-family:Arial, Helvetica, sans-serif;
    }
    input[type="radio"] {
        display: none;
        position: absolute;
        width: 100%;
        appearance: none;
    }
    input[type="radio"]:checked + label {
        background:#01a7e1;
        color:#fff;
    }
    <form>
      <div class="radiobtn">
        <input type="radio" id="huey"
                         name="drone" value="huey" checked />
        <label for="huey">Learn More</label>
      </div>
      <div class="radiobtn">
        <input type="radio" id="dewey"
                         name="drone" value="dewey" />
        <label for="dewey">Learn More</label>
      </div>
    </form>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 2014-10-01
      • 1970-01-01
      • 2011-07-28
      • 2014-05-29
      相关资源
      最近更新 更多