Having difficulty shifting checkboxes to the right side

I'm struggling to align all checkboxes in a single vertical line. I can't figure out how to do it without moving all the content to the right when using float:right on .checkbox.

If you want to see the issue in action, visit the site (please note that it loads slowly due to embedded videos and large images). The code might look messy as I am still learning, so apologies in advance for any confusion.

body:not(#foo) input[type='checkbox'] {
  opacity: 0;
}

.checkbox,
.radio {
  position: relative;
  cursor: pointer;
  padding: 1em;
  display: inline-block;
}

/* Additional CSS code goes here */

<!-- BEGIN - FILTERS -->
<div class="indexfilters">
  <div class="border">
    <label class="checkbox">
      /* Checkbox HTML structure */
    </label><br>
    /* More checkbox labels go here */
    <div class="divbtnfilter">
      <a class="btnfilter">Filter</a>
    </div>
  </div>
</div>

Answer №1

Here is the code you are searching for:

.border {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-items: stretch;
}

.border>.checkbox {
  flex: 1 0 100%;
  text-align: right;
  display: flex;
}

.checkbox a {
  flex-grow: 1;
  padding: 0 1rem;
}

.divbtnfilter {
  padding: 1rem;
}

Your markup and CSS could use some improvements. Here's a more optimized version based on your code:

[].map.call(document.querySelectorAll(".checkboxes a"), function(element){
element.addEventListener("click", function(event) {
console.log(element.innerHTML + ' checked: '+!element.nextElementSibling.checked)
});
});
body:not(#foo) input[type='checkbox'] {
  opacity: 0;
}

.checkboxes label,
.radio {
  position: relative;
  cursor: pointer;
  padding: 1em;
  display: inline-block;
}

.checkboxes label::-moz-selection,
.radio::-moz-selection {
  background: transparent;
}

.checkboxes label::selection,
.radio::selection {
  background: transparent;
}

.checkboxes input+span,
.radio input+span {
  border: 1px solid black;
  background: white;
  content: "";
  display: inline-block;
  margin: 0 .5em 9px 0;
  padding: 0;
  vertical-align: middle;
  width: 1em;
  height: 1em;
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  -webkit-backface-visibility: hidden;
}

...
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />

<div class="indexfilters">
  <div class="checkboxes">
    <label>
      <i class="fa fa-child"></i><a>Starostlivosť o deti</a>
      <input type="checkbox">
      <span></span>
    </label>
    ...
  </div>
</div>

I have optimized your code structure to make it more maintainable and added an event listener function for better functionality. For further improvement, I recommend learning about coding best practices.

Answer №2

Update: Although this solution did not resolve the issue for the original poster, I am leaving it here as it may be helpful for others.

The problem lies in the fact that your checkbox class is being used to encompass both the checkbox name and the checkbox itself. To fix this, you should move your <input> into a separate class and then only align those elements to the right.

<label class="checkbox"> <!-- Container -->
    <i class="fas fa-utensils"></i><a class="icontext">Healthy Eating</a> <!-- Text -->
    <input id="check1" type="checkbox" onchange="console.log('changed');"> <!-- Checkbox -->
    <span></span>
</label>

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

Creating a button with multiple background gradients using CSS

When working on a button element that already boasts a gradient effect, my aim was to integrate a small play image directly in the center. However, achieving this without compromising the current layout and ensuring compatibility across various browsers pr ...

Is it possible to have text centered only on desktop devices and left-aligned on mobile devices using Bootstrap 4?

I have the following code for the header where I want two pictures to be at either end, preferably at the corners. The text should be directly in the center on a desktop, and on mobile, all images and text should be stacked. Is that possible? To view the ...

The Ajax call retrieving the complete script

For the past few days, I've been trying to find a solution to my issue. Essentially, I have two files: index.html and hellonode.js. Index.html contains a div with text and a button that should initiate a request to hellonode.js when clicked. The purpo ...

Using AJAX to submit an HTML form containing a file input

Is it possible to use AJAX to submit a form that includes a file type input? I'm attempting to achieve this using jQuery, but it seems that the file cannot be serialized during submission. Could this be a security feature implemented by the browser? A ...

To grab a specific CSS attribute from a stylesheet using JavaScript

I am looking for a way to extract the value from a CSS file using a JavaScript function. Take a look at my code snippet below: HTML file -> <link rel="stylesheet" type="text/css" href="test_css.css" /> <script type="text/javascript ...

Button click functionality for updating in Classic ASP is functioning correctly exclusively in Internet Explorer and not in other web browsers

Currently, I am in the process of enhancing a Classic ASP application. Within this application, there is an HTML table that is populated from a SQL database. One cell within the table contains checkboxes. Upon clicking one of these checkboxes, a popup wind ...

CSS for creating a vertical dropdown in a Bootstrap horizontal navigation bar

I recently delved into the world of twitter bootstrap and decided to construct a website from scratch using it. I've hit a roadblock while trying to develop a horizontal navigation bar with vertical dropdowns where each <li> creates a new row (c ...

implementing a new CSS file to replace the existing one

Is there a way to dynamically load CSS properties in JavaScript? I have two canvases and I've already linked a CSS file in the head tag. I'm looking for a solution where when a specific option is selected, the CSS properties of the canvases cha ...

Why won't my Twitter Bootstrap navigation bar apply the styles?

I am currently working on a Rails app (4.0) and have incorporated Bootstrap 3 into my project. Both bootstrap.css and bootstrap-theme.css are stored in the stylesheets directory, while bootstrap.js is located in the javascripts directory. Most of the Boots ...

Clicking on the input element in an md-checkbox will toggle the checkbox option

I have a unique feature in my list of checkboxes where users can select an "other" option and input their own text. Here is how it works: <md-checkbox class="md-checkbox-interactive" ng-model="$ctrl.someVar"> <input type="text" placeholder="Pla ...

jQuery does not provide the reference of a basic canvas element

I'm having trouble with a simple initialization function that is supposed to create a canvas element in the body and save its reference in a variable. No matter what I try, jQuery doesn't seem to want to return the reference. I attempted refere ...

Replace the typical bootstrap text class with stylish and modern google material icons

As a newcomer to the world of javascript, I acknowledge that my approach may not be ideal... I'm attempting to modify the color of a material icon upon clicking it. Essentially, I want to toggle it on and off. The challenge lies in the code's in ...

Incorporate a notification into the Windows notification center without it being visibly displayed on the desktop

I am currently developing an Electron application that includes a custom Notification feature. This feature involves html5 divs appearing and disappearing as necessary on a frameless, transparent, always-on-top window. Although the feature works well, I s ...

Child div within a parent div with absolute positioning does not extend to the full height of the webpage

I am currently facing an issue with a bug in my project that I am working on. The mobile menu is not taking the full height of the viewport when the screen size is less than 768px, even though it has been set to 100%. It only becomes visible when toggled ...

Position the float input to the right on the same line as an element

This Angular code contains a challenge where I aim to have text at the start of a column and an input box on the right side of the page, both aligned on the same line. The issue lies in the code which floats the input to the right but disrupts the alignme ...

The hyperlink function is malfunctioning in HTML pages

Hello there, I'm having trouble linking HTML pages together. Here is the code snippet I am currently using: <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <a class="navba ...

Saving HTML content into a MySQL database using Python

I have the task of storing locally stored crawled HTML pages. I successfully open the file using myHTML = open(file_location,'r').read() output can be found here: I am able to create the SQL query successfully: query_insert = ("insert into jo ...

Updating the src attribute of a video element using jQuery

I've been attempting to use this jQuery solution to update the video source, but it doesn't seem to be working as expected. The video still loads the initial inline source. Here is the HTML: <video id="lanvid" autoplay class="lanvid" p ...

Error: Unable to access the 'classList' property of null in HTMLSpanElement.expand function

Encountering a minor issue with my javascript code. Following a tutorial for a seemingly simple task: link What I did: Adapted the HTML from the tutorial to fit my desired visual outcome while maintaining correct class and id attributes. Utilized identic ...

Is your localhost contact form experiencing issues?

I am receiving an error even though I believe I have done everything correctly. I am currently using localhost, could that be the issue? If not, what else could it be? The error is occurring on this line: $name = $_POST['name']; Here is the co ...