提问者:小点点

删除开关无序列表中的项目符号


我试图在一个无序列表中显示多个舍入开关。 它看起来是这样的:https://imgur.com/a/ecipoal
现在我注意到无序列表的项目符号仍然存在,我尝试用list-style-type:none;删除它们。 然而,这会使整个列表崩溃,开关重叠。 我刚开始HTML/CSS,所以我不知道那里发生了什么。
HTML

null

.switches{
    border: 1px solid white;
    float: right;
    margin-right: 40px;
    width: 200px;
}

/*
.switches ul{
    list-style-type: none; not working
}
*/

.switches ul li{
    margin: 13px;
  
}

.switch {
    position: absolute;
    display: inline-flex;
    right: 20%;
    width: 40px;
    height: 23px;
    float: right;
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.switch span{
    color: #cdcbcb;
    text-shadow: 1px 1px 2px #1a1919;
    margin-left: 47px;
    margin-top: 4px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 17px;
  width: 17px;
  left: 4px;
  bottom: 3px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(17px);
  -ms-transform: translateX(17px);
  transform: translateX(17px);
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="switches">
    <ul>
        <li>
            <label class="switch">
                <input type="checkbox" checked>
                <div class="slider round"></div>
                <span>Test</span>
            </label>
        </li>
        <li>
            <label class="switch">
                <input type="checkbox" checked>
                <div class="slider round"></div>
                <span>Test2</span>
            </label>
        </li>
    </ul>
</div>
</body>
</html>

null


共3个答案

匿名用户

这是我的建议:

https://jsfiddle.net/sheriffderek/a5nuqtkl/

您将需要确定复选框样式(https://codepen.io/sheriffderek/pen/bgeqedb)--但以下是布局位的工作方式。 确保你逐步增强这些功能--而不是创建一些不可访问的东西。 (您需要官方标签等)

null

* { /* https://www.paulirish.com/2012/box-sizing-border-box-ftw/ */
  box-sizing: border-box;
}

.field-list {
  list-style: none;
  margin: 0;
  padding: auto;
}

.field-list input, .field-list label {
  display: block; /* inline by default */
}

.field-list .field {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.field-list label {
  padding: 5px 10px;
}
<ul class="field-list">

  <li class='field'>
    <input id="one" type="checkbox">
    <label for="one">Thing one</label>
  </li>
  
  <li class='field'>
    <input id="two" type="checkbox">
    <label for="two">Thing two</label>
  </li>

</ul>

匿名用户

“拼贴”问题是由于您在.switch样式中的位置:绝对

list-style-type:none;每个.li中没有内容。 因此.li不会占用任何空间。

我对.switch样式做了一些更改:

.switch {
    /* position: absolute; */ 
    position: relative;
    display: inline-flex;
    right: 20%;
    width: 40px;
    height: 23px;
    /* float: right; <-- you don't need this when `relative`. Otherwise items will still "collpased". */
}

对于列表样式:

.switches ul{
    list-style-type: none;
}

以下片段是修改后的版本:

null

.switches{
    border: 1px solid white;
    float: right;
    margin-right: 40px;
    width: 200px;
}

.switches ul{
    list-style-type: none;
}

.switches ul li{
    margin: 13px;
  
}

.switch {
    position: relative;
    display: inline-flex;
    right: 20%;
    width: 40px;
    height: 23px;
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.switch span{
    color: #cdcbcb;
    text-shadow: 1px 1px 2px #1a1919;
    margin-left: 47px;
    margin-top: 4px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 17px;
  width: 17px;
  left: 4px;
  bottom: 3px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(17px);
  -ms-transform: translateX(17px);
  transform: translateX(17px);
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="switches">
    <ul>
        <li>
            <label class="switch">
                <input type="checkbox" checked>
                <div class="slider round"></div>
                <span>Test</span>
            </label>
        </li>
        <li>
            <label class="switch">
                <input type="checkbox" checked>
                <div class="slider round"></div>
                <span>Test2</span>
            </label>
        </li>
    </ul>
</div>
</body>
</html>

匿名用户

list-style:none;list-style-type:none;display:flex;flex-direction:column;一起使用,以避免项目重叠。

null

ul{
    list-style-type: none;
    display: flex;
    flex-direction: column;
}

.switches{
    border: 1px solid white;
    float: right;
    margin-right: 40px;
    width: 200px;
}

/*
.switches ul{
    list-style-type: none; not working
}
*/

.switches ul li{
    margin: 13px;
  
}

.switch {
    position: absolute;
    display: inline-flex;
    right: 20%;
    width: 40px;
    height: 23px;
    float: right;
}

/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.switch span{
    color: #cdcbcb;
    text-shadow: 1px 1px 2px #1a1919;
    margin-left: 47px;
    margin-top: 4px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 17px;
  width: 17px;
  left: 4px;
  bottom: 3px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(17px);
  -ms-transform: translateX(17px);
  transform: translateX(17px);
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="switches">
    <ul>
        <li>
            <label class="switch">
                <input type="checkbox" checked>
                <div class="slider round"></div>
                <span>Test</span>
            </label>
        </li>
        <li>
            <label class="switch">
                <input type="checkbox" checked>
                <div class="slider round"></div>
                <span>Test2</span>
            </label>
        </li>
    </ul>
</div>
</body>
</html>