Issue
I'm having issues applying flex-box to this CSS toggle-switch extension: https://ghinda.net/css-toggle-switch/index.html
I downloaded it as a CDN, so I don't have its CSS files on me
Here is my sample index.html code:
<div class="settings">
<p>Settings</p>
<label class="switch-light switch-ios" onclick="">
<input type="checkbox">
<strong>
Send Email Notifications
</strong>
<span class="switch-light-span">
<span>Off</span>
<span>On</span>
<a></a>
</span>
</label>
<label class="switch-light switch-ios" onclick="">
<input type="checkbox">
<strong>
Set Profile to Public
</strong>
<span>
<span>Off</span>
<span>On</span>
<a></a>
</span>
</label>
<select name="timezone">
<option value="volvo" selected>Select a Timezone</option>
<option value="volvo">Volvo</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<div class="buttons">
<button>Save</button>
<button>Cancel</button>
</div>
</div>
</div>
Here is a sample CSS code:
/* SETTINGS */
.settings {
display: flex;
flex-direction: column;
}
.switch-light {
display: flex !important;
justify-content: space-between !important;
}
Apparently you have to apply the !important keyword if you're using a CDN to override their style sheets. So that's what I did, but I'm not getting the desired effect I want.
I was trying to apply a property to the span element, which is that entire button, but it is not working.
Here is an example of what I would like to achieve:

Any suggestions?
Solution
Your flexbox is indeed working, I think you might be confused because the toggle button's width is set to 100%. If you reduce the width I think it will look more like what you are expecting, see snippet below.
Also, you don't necessarily have to use !important to override the styles of a resource loaded via CDN. It's just because it is loaded after your stylesheet that it's styles will have greater precedent. There are better ways to override the styles without using !important, see this article What is the order of precedence for CSS?
Hope this helps!
.settings {
display: flex;
flex-direction: column;
}
.switch-light {
display: flex !important;
justify-content: start !important;
}
.switch-ios.switch-light > span {
width: 100px !important;
}
.switch-ios.switch-light > strong {
width: 250px !important;
}
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/css-toggle-switch@latest/dist/toggle-switch.css" />
<div class="settings">
<p>Settings</p>
<label class="switch-light switch-ios" onclick="">
<input type="checkbox">
<strong>
Send Email Notifications
</strong>
<span class="switch-light-span">
<span>Off</span>
<span>On</span>
<a></a>
</span>
</label>
<label class="switch-light switch-ios" onclick="">
<input type="checkbox">
<strong>
Set Profile to Public
</strong>
<span>
<span>Off</span>
<span>On</span>
<a></a>
</span>
</label>
<select name="timezone">
<option value="volvo" selected>Select a Timezone</option>
<option value="volvo">Volvo</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<div class="buttons">
<button>Save</button>
<button>Cancel</button>
</div>
</div>
</div>
.
Answered By - Matthew Coloe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.