【问题标题】:How do I fix or connect (checkbox) buttons together as to resist shifting when viewing on different browsers?在不同的浏览器上查看时,如何修复或连接(复选框)按钮以防止移动?
【发布时间】:2021-08-10 04:09:53
【问题描述】:

<td>
  <ul id="defects-pentagon">
  
    <li>
      <input type="checkbox" name="Defects" id="Taily" className="defect-taily" value="Taily"/>
       <label for="Taily">Taily</label>
       <div className="defect-taily-pentagon"></div>
    </li>
    
    <li>
      <input type="checkbox" name="Defects" id="Tapered" className="defect-tapered" value="Tapered"/>
      <label for="Tapered">Tapered</label>
      <div className="defect-tapered-pentagon"></div>
    </li>
    
    <li>
      <input type="checkbox" name="Defects" id="Curvy" className="defect-curvy" value="Curvy"/>
      <label for="Curvy">Curvy</label>
      <div className="defect-curvy-pentagon"></div>
    </li>
    
    <li>
      <input type="checkbox" name="Defects" id="Bumpy" className="defect-bumpy" value="Bumpy"/>
      <label for="Bumpy">Bumpy</label>
      <div className="defect-bumpy-pentagon"></div>
    </li>
    
    <li>
      <input type="checkbox" name="Defects" id="Irregular" className="defect-irregular" value="Irregular"/>
      <label for="Irregular">Irregular</label>
      <div className="defect-irregular-pentagon"></div>
    </li>
  </ul> 
</td>
.defect-taily-pentagon {
    width:.3rem;
    height:4.7rem;
    background:#d70022;

    position: relative;
    transform: rotate(56deg);
    top: -90%;
    left: 100%;
}

.defect-tapered-pentagon {
    width:.3rem;
    height:4.7rem;
    background:#d70022;

    position: relative;
    transform: rotate(-56deg);
    top: -90%;
    right: -50%
}

.defect-curvy-pentagon {
    width:.3rem;
    height:4.5rem;
    background:#d70022;

    position: relative;
    transform: rotate(-19deg);
    top: -100%;
    left: 85%;
}

.defect-bumpy-pentagon {
    width:.3rem;
    height:4.5rem;
    background:#d70022;

    position: relative;
    transform: rotate(19deg);
    top: -100%;
    right: -66%;
}

.defect-irregular-pentagon {
    width:.3rem;
    height:4.5rem;
    background:#d70022;

    position: relative;
    transform: rotate(90deg);
    top: -155%;
    left: 75%;
}

我正在尝试在 css 中创建一个五边形,其中每个边缘都是一个复选框按钮。我创建了 5 个按钮并将它们的大小更改为小而细的矩形。使用 rem 单位,我能够旋转和定位每个按钮,使它们形成五边形。但是,当缩小/扩大我的浏览器窗口时,按钮会左右移动。

我正在寻找一种可以将每个按钮连接在一起并将整个对象作为一个单元移动以将其放置在我的网页上的方法。我认为问题在于 rem 单位和 % 单位的使用,因为它们是相对于整个浏览器大小而不是它们所在的分隔线的大小。

每个按钮的代码都是相同的,除了 id/className/label 和页面上的相对位置(顶部/左侧)。

JavaScript

<li> 
    <input type="checkbox"
     id="Taily"
     className="defect-taily"/>
     
     <label for="Taily"> Taily </label>    
</li>

CSS

.defect-taily-pentagon {
  width:.3rem;
  height:4.7rem;
  background:#d70022;

  position: relative;
  transform: rotate(56deg);
  top: -90%;
  left: 100%;
}

附:我无法发布图片,因为这是我在 stackoverflow 上的第一篇文章。有空我会发图。

【问题讨论】:

  • 你说得对,以这种方式使用 % 是行不通的。改为使用 vmin 作为单位进行调查。
  • 你能在你的问题中添加一个工作片段吗?
  • 请包含您使用 sn-p 编辑器创建五边形的所有代码。

标签: javascript html css checkbox browser


【解决方案1】:

我认为您可能希望将所有按钮放在一个 div 中(如容器),并尝试使用 position: absolute; 相对于 div position: relative; 定位它们。这样,您只需设置 div 的样式以适应不同的设备。

这是一个代码sn-p,看看:

<html>
    <head>
        <style>
            html{width: 100%; font-size: 10px; padding: 0; margin: 0;}
            body{width: 100%; padding: 0; margin: 0;}
            .container{
                min-width: 250px; width: 100%; min-height: 200px; height: 100%; position: relative; padding: 0; margin: 0;
                background-image: radial-gradient(at 50% 50%, hsl(209, 64%, 61%), hsl(226, 100%, 13%));
                /* background-image: radial-gradient(at 35% -15%, var(--med ), var(--darker), var(--darkgris) 70%, var(--darkpurple)) */
            }
            .bg-black{
                border-radius: 5rem; height: 5rem; width: 5rem;
                background-image: radial-gradient(at -50% 100%, hsl(0, 0%, 100%), hsl(0, 0%, 0%));
            }
            .container>div:nth-child(1){position: absolute; left: calc(50% - 5rem /2); top: 0;}
            .container>div:nth-child(2){position: absolute; left: calc(100% - 5rem); top: calc(25% - 5rem /2);}
            .container>div:nth-child(3){position: absolute; left: calc(75% - 5rem /2); top: calc(100% - 5rem);}
            .container>div:nth-child(4){position: absolute; left: calc(25% - 5rem /2); top: calc(100% - 5rem);}
            .container>div:nth-child(5){position: absolute; left: 0; top: calc(25% - 5rem /2);}
        </style>
    </head>
    <body>
        <div class="container">
            <div class="bg-black"></div>
            <div class="bg-black"></div>
            <div class="bg-black"></div>
            <div class="bg-black"></div>
            <div class="bg-black"></div>
        </div>
    </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-16
    • 2016-11-29
    • 2021-03-27
    • 2011-08-31
    • 1970-01-01
    • 2015-12-24
    • 2013-08-01
    • 1970-01-01
    相关资源
    最近更新 更多