RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1162096
Accepted
Ivy
Ivy
Asked:2020-08-04 23:38:28 +0000 UTC2020-08-04 23:38:28 +0000 UTC 2020-08-04 23:38:28 +0000 UTC

如何为 CSS 单选输入制作带有圆角的自定义复选框

  • 772

如何在图片中打勾(左上角优先),但有圆角?

在此处输入图像描述

<input type='radio' />

是圆的圆。

css
  • 4 4 个回答
  • 10 Views

4 个回答

  • Voted
  1. OPTIMUS PRIME
    2020-08-05T01:59:47Z2020-08-05T01:59:47Z

    从两个复合圆角矩形+以合适的角度组装它会更容易transform: rotate()......通过眼睛拿起数字:

    .radio {
      display: none;
    }
    
    .pseudo-radio {
      font-size: 100px;
      /* Что прикольно, всё остальное будет регулироваться относительно этого размера */
      
      display: inline-block;
      position: relative;
      
      width: 1em;
      height: 1em;
      
      border: 2px solid #929;
      cursor: pointer;
    }
    
    .radio:checked + .pseudo-radio::before,
    .radio:checked + .pseudo-radio::after {
      display: block;
    }
    
    .pseudo-radio::before,
    .pseudo-radio::after {
      content: "";
      position: absolute;
      display: none;
      
      bottom: 0.28em;
      left: 0.05em;
      transform: rotate(40deg);
      
      width: 0.6em;
      height: 0.2em;
      
      background-color: #f80;
      border-radius: 1em;
    }
    .pseudo-radio::after {  
      bottom: 0.4em;
      left: 0.28em;
      transform: rotate(-60deg);
      
      width: 0.8em;
      height: 0.2em;
    }
    <label>
      <input type="radio" class="radio" name="bubu" checked>
      <span class="pseudo-radio"></span>
    </label>
      
    <label>
      <input type="radio" class="radio" name="bubu">
      <span class="pseudo-radio"></span>
    </label>
    
    <label>
      <input type="radio" class="radio" name="bubu">
      <span class="pseudo-radio"></span>
    </label>

    • 6
  2. Best Answer
    Vasily
    2020-08-04T23:53:33Z2020-08-04T23:53:33Z

    要将这样的元素设置为input,无论其类型如何,首先需要重置浏览器可以添加的默认样式。

    然后有几个选项可以解决您的问题,我的选择是使用单个伪元素并将其可见区域限制为父元素的大小,使用值为 hidden的溢出属性。

    原则上,这都是针对具有平滑边缘的输入'a。

    使复选标记变圆会有点困难,这里线性和径向渐变函数将帮助我们。

    这是发生的事情:

    在此处输入图像描述

    您可以在下面看到一个实时示例:

    body {
      font-family: "Roboto", sans-serif;
    }
    
    div {
      display: grid;
      grid-template-columns: min-content, max-content;
      align-items: center;
      justify-content: start;
      grid-column-gap: 30px;
      grid-row-gap: 30px;
      margin: 30px;
    }
    
    div > input {
      grid-column: 1 / 1;
      overflow: hidden;
      position: relative;
      display: block;
      width: 46px;
      height: 46px;
      font: inherit;
      letter-spacing: unset;
      word-spacing: unset;
      line-height: 1;
      text-shadow: none;
      text-align: unset;
      writing-mode: unset;
      text-rendering: unset;
      text-indent: 0;
      color: inherit;
      text-transform: none;
      background-color: unset;
      padding: 0;
      border: 3px solid black;
      border-radius: 0;
      box-sizing: unset;
      box-shadow: none;
      outline: none;
      margin: 0;
      -webkit-appearance: none;
      appearance: none;
      cursor: pointer;
    }
    
    div > input:nth-of-type(2) {
      border-radius: 10px;
    }
    
    div > input::after {
      content: "";
      display: none;
      position: absolute;
      top: 50%;
      left: 50%;
    }
    
    div > input:first-child::after {
      width: 20px;
      height: 28px;
      border-right: 3px solid black;
      border-bottom: 3px solid black;
      box-sizing: border-box;
      margin-top: -5px;
      transform: translate(-50%, -50%) rotate(45deg);
    }
    
    div > input:nth-of-type(2)::after {
      --color: black;
      --width: 70px;
      --height: 50px;
      --thick: 9px;
      --radius: 10px; 
      height: var(--height);
      width: var(--width);
      border-bottom-left-radius: var(--radius);
      background: 
         radial-gradient(farthest-side at top right, transparent 97%, var(--color) 100%) bottom calc(var(--thick) - 0.5px) left calc(var(--thick) - 0.5px) / calc(var(--thick) * 0.8) calc(var(--thick) * 0.8), 
         radial-gradient(farthest-side, var(--color) 99%, transparent 100%) top left / var(--thick) var(--thick), 
         radial-gradient(farthest-side, var(--color) 99%, transparent 100%) bottom right / var(--thick) var(--thick), 
         linear-gradient(var(--color), var(--color)) left bottom / var(--thick) calc(100% - var(--thick) / 2), 
         linear-gradient(var(--color), var(--color)) left bottom/calc(100% - var(--thick) / 2) var(--thick);
      background-repeat: no-repeat;
      margin-top: -4px;
      transform: translate(-50%, -50%) rotate(-45deg) scale(0.4);
    }
    
    div > input:checked::after {
      display: block;
    }
    
    div > p {
      grid-column: 2 / 2;
      font-size: 18px;
    }
    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    
    <div>
      <input type="radio" name="test" />
      <p>Ровные края</p>
      <input type="radio" name="test" />
      <p>Закругленные края</p>
    </div>

    • 5
  3. dmitriy_vlz
    2020-08-04T23:46:21Z2020-08-04T23:46:21Z

    颜色如果正确。

    /* Customize the label (the container) */
    .container {
      display: block;
      position: relative;
      padding-left: 35px;
      margin-bottom: 12px;
      cursor: pointer;
      font-size: 22px;
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
    }
    
    /* Hide the browser's default checkbox */
    .container input {
      position: absolute;
      opacity: 0;
      cursor: pointer;
      height: 0;
      width: 0;
    }
    
    /* Create a custom checkbox */
    .checkmark {
      position: absolute;
      top: 0;
      left: 0;
      border: 1px solid grey;
      border-radius: 5px;
      height: 25px;
      width: 25px;
      background-color: #eee;
    }
    
    /* On mouse-over, add a grey background color */
    .container:hover input ~ .checkmark {
      background-color: #ccc;
    }
    
    /* When the checkbox is checked, add a blue background */
    .container input:checked ~ .checkmark {
      background-color: #fff;
    }
    
    /* Create the checkmark/indicator (hidden when not checked) */
    .checkmark:after {
      content: "";
      position: absolute;
      display: none;
    }
    
    /* Show the checkmark when checked */
    .container input:checked ~ .checkmark:after {
      display: block;
    }
    
    /* Style the checkmark/indicator */
    .container .checkmark:after {
      left: 9px;
      top: 5px;
      width: 5px;
      height: 10px;
      border: solid #2196F3;
      border-width: 0 3px 3px 0;
      -webkit-transform: rotate(45deg);
      -ms-transform: rotate(45deg);
      transform: rotate(45deg);
    }
    <label class="container">INput
      <input type="checkbox">
      <span class="checkmark"></span>
    </label>

    • 2
  4. De.Minov
    2020-08-05T02:22:00Z2020-08-05T02:22:00Z

    纯 CSS 选项

    .input-radio {
      display: inline-block;
    }
    
    .input-radio input[type="radio"] {
      display: none;
    }
    
    .input-radio .-custom {
      display: block;
      width: 40px;
      height: 40px;
      border: 2px solid #cacaca;
      box-sizing: border-box;
      cursor: pointer;
      position: relative;
    }
    
    .input-radio .-custom::before {
      content: '';
      display: block;
      width: calc(100% - 16px);
      height: calc(100% - 16px);
      background: #3c8dbc;
      margin: 8px;
    }
    
    .input-radio input[type="radio"]:checked ~ .-custom::before {
      content: '';
      display: block;
      height: 10px;
      background: transparent !important;
      border: 6px solid #3c8dbc;
      border-top: 0;
      border-right: 0;
      margin: 0;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -75%) rotate(-45deg);
    }
    
    .input-radio .-custom:hover,
    .input-radio input[type="radio"]:checked ~ .-custom:hover::before {
      border-color: #0076c3;
    }
    
    .input-radio .-custom:hover::before  {
      background: #0076c3;
    }
    
    .input-radio.--border-radius .-custom {
      border-radius: 10px;
    }
    
    .input-radio.--border-radius-v2 .-custom {
      border-radius: 10px;
    }
    
    .input-radio.--border-radius-v2 input[type="radio"]:not(:checked) ~ .-custom::before {
      border-radius: 6px;
    }
    .input-radio.--circle .-custom,
    .input-radio.--circle input[type="radio"]:not(:checked) ~ .-custom::before {
      border-radius: 50%;
    }
    <label for="input00" class="input-radio">
      <input id="input00" type="radio" name="i0[]">
      <div class="-custom"></div>
    </label>
    
    <label for="input01" class="input-radio">
      <input id="input01" type="radio" name="i0[]" checked>
      <div class="-custom"></div>
    </label>
    <br>
    <label for="input10" class="input-radio --border-radius">
      <input id="input10" type="radio" name="i1[]">
      <div class="-custom"></div>
    </label>
    
    <label for="input11" class="input-radio --border-radius">
      <input id="input11" type="radio" name="i1[]" checked>
      <div class="-custom"></div>
    </label>
    <br>
    <label for="input20" class="input-radio --border-radius-v2">
      <input id="input20" type="radio" name="i2[]">
      <div class="-custom"></div>
    </label>
    
    <label for="input21" class="input-radio --border-radius-v2">
      <input id="input21" type="radio" name="i2[]" checked>
      <div class="-custom"></div>
    </label>
    <br>
    <label for="input30" class="input-radio --circle">
      <input id="input30" type="radio" name="i3[]">
      <div class="-custom"></div>
    </label>
    
    <label for="input31" class="input-radio --circle">
      <input id="input31" type="radio" name="i3[]" checked>
      <div class="-custom"></div>
    </label>

    UPD:出于某种原因,我当时没有检查它的性能。
    该 ID 不是唯一的,因此无法正常工作。

    • 0

相关问题

  • 几何形状的阴影

  • 如何制作这样的人物组合?

  • 如何在css中制作一个图形

  • 如何制作阴影(投影)渐变

  • 网格项目传输不起作用

  • 更改屏幕宽度时换行。引导程序

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    如何从列表中打印最大元素(str 类型)的长度?

    • 2 个回答
  • Marko Smith

    如何在 PyQT5 中清除 QFrame 的内容

    • 1 个回答
  • Marko Smith

    如何将具有特定字符的字符串拆分为两个不同的列表?

    • 2 个回答
  • Marko Smith

    导航栏活动元素

    • 1 个回答
  • Marko Smith

    是否可以将文本放入数组中?[关闭]

    • 1 个回答
  • Marko Smith

    如何一次用多个分隔符拆分字符串?

    • 1 个回答
  • Marko Smith

    如何通过 ClassPath 创建 InputStream?

    • 2 个回答
  • Marko Smith

    在一个查询中连接多个表

    • 1 个回答
  • Marko Smith

    对列表列表中的所有值求和

    • 3 个回答
  • Marko Smith

    如何对齐 string.Format 中的列?

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5