Left-align switch labels in Bootstrap 4 for a clean and organized look

Here is the code snippet that I am currently working with:

.custom-switch {
  padding-left: 0;
}

.custom-switch .custom-control-label {
  left: 0;
  padding-left: 2.5rem;
}

.custom-switch .custom-control-label::before {
  top: 0.125rem;
  left: 0;
  width: 2rem;
  height: 1.25rem;
  border-radius: 1rem;
  transition: background-color .15s ease-out;
  background-color: #fff;
}

.custom-switch .custom-control-label::after {
  top: 0.3125rem;
  left: .25rem;
  width: .875rem;
  height: .875rem;
  -webkit-transform: none;
  transform: none;
  background-color: #fff;
  border-radius: 1rem;
  background-color: #adb5bd;
}

.custom-switch .custom-control-input:checked~.custom-control-label::after {
  background-color: #fff;
  -webkit-transform: translateX(0.625rem);
  transform: translateX(0.625rem);
  box-shadow: -0.125rem 0 0.125rem rgba(0, 0, 0, 0.2);
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="custom-control custom-switch">
  <input type="checkbox" class="custom-control-input" id="example-switch-custom4" name="example-switch-custom">
  <label class="custom-control-label" for="example-switch-custom">Test</label>
</div>

The current layout shows the label on the right side (see image here https://i.sstatic.net/Z5hWp.jpg). Is there a simple way to adjust the positioning to have it on the left side instead? Appreciate any help! Thanks!

Answer №1

Adjust the spacing of left and padding elements to achieve the desired layout.

Refer to the code snippet below for the intended outcome.

...

Answer №2

i believe this method will work

<div class="form-group">
            <label class="" for="sw">Is this an extra block</label>
             <div class="custom-control custom-switch d-inline" id="sw">
                <input type="checkbox" class="custom-control-input" id="edit_extra_block" name="extra_block" value="">
                <label class="custom-control-label" for="edit_extra_block"></label>
             </div>
        </div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5b7babaa1a6a1a7b4a595e1fbe0fbe6">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccbca3bcbca9bee2a6bf8cfde2fdfae2fd">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="51333e3e25222523302111657f647f62">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
<div class="form-group">
                <label class="" for="sw">Is extra block</label>
                 <div class="custom-control custom-switch d-inline" id="sw">
                    <input type="checkbox" class="custom-control-input" id="edit_extra_block" name="extra_block" value="">
                    <label class="custom-control-label" for="edit_extra_block"></label>
                 </div>
            </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The combination of HTML Agility Pack and VB.NET is a powerful duo for web

While there are numerous examples available for other programming languages, I am curious to know if there are any specifically for vb.net. Can anyone provide some relevant examples? ...

bring in all the files located within the Directory

Is there a way to import all CSS files from a specific folder without having to import each file individually? Looking to import assets/css/* ? <link href="<?php echo base_url(); ?>assets/css/*" rel="stylesheet"/> <title&g ...

Create a layout using CSS that features two columns. The left column should be fluid, expanding to fill all remaining space, while the right column should be fixed

I need to ensure that the Online Users div always remains at a fixed size of 200px, while allowing the chat window next to it to resize dynamically based on available space. Essentially, I want the chat window to adjust its width as the window is resized, ...

Exploring HTML segments with Python and BeautifulSoup

As a beginner, I am exploring web scraping examples from Automate the Boring Stuff. My goal is to create a Python script that automates downloading images from PHD Comics using the following steps: Identify the image link in the HTML and download it. ...

What could be causing my video not to display a thumbnail on mobile devices until it is played?

When I view my website on mobile devices, there is no background image displayed before playing a video. Below is the HTML code I am using: <div class="row " > <div class="col-12 text-center"> <video control ...

Expanding an element to cover all columns in a grid with automatically generated columns

I am working on a CSS grid layout with automatic columns and 2 rows. All elements are normally placed in the first row except for one special element that should span both rows while filling all available column space. My current code looks like this: ...

Ensuring the width of a div matches the adjacent containers

I need assistance in creating a form that adjusts its width based on the form fields. The form contains both explanatory text and input fields, each enclosed in a div with inline-block set. The outer div (also using inline-block) should not expand beyond ...

Issues with the background-image scroll feature not functioning as intended

Can anyone help me out with a CSS issue I'm having? I've set an image as my background on a webpage and I want it to scroll with the page. Even though I followed some online tutorials, it's still not working for me. It's been a while si ...

Tips for adding a label element within the Semantic UI + React Dropdown component

I am trying to replicate the Dropdown component from Semantic UI using UI React, where a <label> is included for the dropdown menu: https://i.sstatic.net/XcAGw.png () Here is the markdown code I want to generate in my React app: <div class="ui ...

Learn how to collapse a list by clicking outside of it on the document with the following code: $(document).on("click"

I want to create a collapsible/expandable menu for my website. I had a version where hovering over a category would expand the subcategory, but what I really need is for the subcategories to expand when I click on a category and remain expanded until I cli ...

What is the best way to center my image both vertically and horizontally?

Utilizing react.js to develop a template website has been my current project. The issue arose when I began constructing the first component of the site. The dilemma: The picture was not centered on the page, neither vertically nor horizontally. Despite ...

Tips for effectively personalizing the dropdown menu made with ul-li elements

https://i.sstatic.net/7kkqL.png https://i.sstatic.net/dCwkI.png After creating a drop-down menu using ul and li tags, I realized that when the menu is opened, it shifts the blocks below on the screen. To prevent this from happening, I adjusted my CSS as ...

Verify the text file for any data, and if it contains any, display it on the web browser using JavaScript

I have a program in C that works with a temperature sensor. It creates a file to store the temperature and indicates whether it falls within specific values. I want to display this data on a web browser and update it every 5 minutes. I'm looking for ...

The Eclipse IDE is experiencing issues with the functionality of the JavaScript Number class

In my latest project, I decided to create a Dynamic Web Project using the Eclipse IDE 2019-12 along with Apache Tomcat 8.5.55 server. The main functionality of this project is that a user can input integers and receive their sum as an output. To ensure dat ...

Content within a div that is floated left

The scenario at hand is: HTML Structure: <div id="main"> <div id="a"></div> <div id="b">Some Text</div> </div> CSS Styles: #a{ float:left; width:800px; height:150px; background-color:#CCC; } ...

Javascript function for downloading files compatible with multiple browsers

When working with a json response on the client side to build content for an html table, I encountered an issue with saving the file to the local disk upon clicking a download button. The csvContent is generated dynamically from the json response. Here&ap ...

Issue with Gmail failing to render CSS in HTML email (svnspam)

After successfully setting up and configuring svnspam, I noticed that the emails sent to my Gmail account are missing the colored diffs. When examining the original email using Gmail's view original feature, I found the CSS code as follows: <html ...

What is the best way to apply custom css to a Google Plus share button within an iframe?

I am having an issue with the CSS on my share button. The Google style is causing my CSS to reset. Here is the iframe code I am using: <iframe src="https://apis.google.com/u/0/_/+1/fastbutton?usegapi=1&amp;size=tall&amp;origin=http%3A%2F%2F ...

Struggling to Collaborate with External PHP File Leads to Garbled Results

Recently started learning PHP and I'm pretty sure I have it set up correctly with my local IIS as I was able to use it in a form on another local website. For this particular project, I have a basic HTML file structured like this: <!doctype html&g ...

"Trouble with making jQuery AJAX calls on Internet Explorer versions 8 and 9

I've been searching for the answer to this problem without any luck. I have a page with jquery ajax calls to an API service. It works well in Chrome, Safari, Firefox, and IE 10, but fails in IE 9 and 8. Here is the code: $.ajax({ ...