1
votes

Suppression de la puce dans la liste non ordonnée pour les commutateurs

J'essaie d'afficher plusieurs commutateurs arrondis dans une liste non ordonnée. Cela ressemble à ceci: https://imgur.com/a/ECIpoAL
Maintenant, j'ai remarqué que les puces de la liste non ordonnée sont toujours là et j'ai essayé de les supprimer avec list-style-type: none; . Cependant, cela réduirait un peu la liste entière et les commutateurs se chevauchent. Je viens de commencer html / css donc je ne sais pas vraiment ce qui se passe là-bas.
HTML

<!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>
.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);
}


0 commentaires

3 Réponses :


1
votes

Voici ce que je suggère:

https://jsfiddle.net/sheriffderek/a5nuqtkL/

Vous devrez définir le style de la case à cocher ( https: / /codepen.io/sheriffderek/pen/bGEqEdB ) - mais voici comment les bits de mise en page devraient fonctionner. Assurez-vous de les améliorer progressivement - au lieu de créer quelque chose qui n'est pas accessible. (vous avez besoin d'étiquettes officielles, etc.)

<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>
* { /* 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;
}


0 commentaires

1
votes

Utilisez list-style: none; ou list-style-type: none; avec display: flex; et flex -direction: column; pour éviter le chevauchement des éléments.

<!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>
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);
}


0 commentaires

1
votes

Le problème du "collpasing" est dû à votre position: absolue dans les styles de .switch .

Quand list-style-type: aucun; aucun contenu n'est à l'intérieur de chaque .li . Et donc .li n'occupera aucun espace.

J'ai fait quelques changements sur les styles .switch : p >

<!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>

Pour le style de votre liste:

.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);
}

L'extrait suivant est la version modifiée:

p >

.switches ul{
    list-style-type: none;
}
.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". */
}

J'espère que cela vous aidera.


1 commentaires

Merci beaucoup! C'était ça: D