Как машинопись может изменить содержимое (вкл / выкл) в файле s css - PullRequest
0 голосов
/ 25 марта 2020

У меня есть такой выключатель. enter image description here

enter image description here

Теперь я хочу изменить слово (Вкл) внутри переключателя на другое слово (например: cc, cv), который будет основан на логическом значении. Например, если переменная 1 - «Истина», то на переключателе отображается «cc». если переменная 2 - «Истина», то на коммутаторе отображается «cv». И varaible1, и variable2 не могут быть True одновременно, поэтому не беспокойтесь.

Вот мой код в файле HTML и файле s css

HTML:

      <div> 
        <label class="switch">
          <input type="checkbox" [ionSetting]="outputEnabled" style="display: none;">
          <span class="slider"></span>
        </label>
      </div>

S CSS file:

//Start: On/Off switch-->
.switch {
  top: 12.5%;
  right: 1%;
  width: 60px;
  height: 22px;
  position: relative;
  display: inline-block;
  margin: 0 0.3vw;
  font-size: 0.8rem;
}

//Hide the Checkbox behide the switch
.switch input {
  display: none;
}

//Sheild border and radius
.slider {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  border: solid 1px rgb(184, 186, 191);
  border-radius: 30px;
}

.slider:hover {
  border: solid 1px rgb(224, 226, 231);
}
//Button inside the switch
.slider:before {
  position: absolute;
  background-color: rgb(184, 186, 191);
  height: 16px;
  width: 27px;
  content: "";
  top: 2px;
  left: 2px;
  bottom: 2px;
  border-radius: 30px;
  transition: 0.5s; //ease-in-out
}

.slider:hover:before {
  background-color: rgb(224, 226, 231);
}
.slider:hover:after {
  color: rgb(224, 226, 231);
}

.slider:after {
  content: "Off";
  color: rgb(184, 186, 191);
  display: block;
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 75%;
  transition: 0.5s;
  font-size: 0.8rem;
}

//checked condition
input:checked + .slider:after {
  transition: 0.5s;
  left: 25%;
  content: "On";
  color: white;
  font-size: 0.8rem;
}

input:checked + .slider {
  background-color: rgb(76, 142, 255);
  border: solid 2px rgb(76, 142, 255);
}

input:checked + .slider:hover {
  background-color: rgb(111, 179, 255);
  border: solid 2px rgb(111, 179, 255);
}

input:checked + .slider:before {
  transform: translate(26px, -1px);
  background-color: white;
}
//End: On/Off switch <--

Так как файл S CSS не может получить доступ к переменной в машинописном тексте, единственный способ - использовать машинописный текст для изменения содержимого в S CSS файл, верно? ИЛИ есть предложения получше?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...