Adjusting the size of a button in HTML and CSS

Check out this code:

/* custom button */
*, *:after, *:before {
  box-sizing: border-box;
}
.checkbox {
  position: relative;
  display: inline-block;
}
.checkbox:after, .checkbox:before {
  font-family: FontAwesome;
  font-feature-settings: normal;
  -webkit-font-kerning: auto;
          font-kerning: auto;
  font-language-override: normal;
  font-stretch: normal;
  font-style: normal;
  font-synthesis: weight style;
  font-variant: normal;
  font-weight: normal;
  text-rendering: auto;     
}
.checkbox label {
  width: 90px;
  position: relative;
  display: inline-block;
  border-radius: 46px;
  transition: 0.4s;
}
.checkbox label:after {
  content: '';
  position: absolute;
  width: 50px;
  border-radius: 100%;
  left: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  transition: 0.4s;
}
.checkbox input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  opacity: 0;
  cursor: pointer;
}
.checkbox input:hover + label:after {
  box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.2), 0 3px 8px 0 rgba(0, 0, 0, 0.15);
}
.checkbox input:checked + label:after {
  left: 40px;
}

.model-7 .checkbox label {
  background: none;
  border: 5px solid #555;
  height: 42px; /*This line does not affect the height*/
  margin-left: 15px;
}
.model-7 .checkbox label:after {
  background: #555;
  box-shadow: none;
  top: 2px;
  left: 2px;
  width: 28px;
  height: 28px;
}
.model-7 .checkbox input:checked + label {
  border-color: #04c6db;
}
.model-7 .checkbox input:checked + label:after {
  background: #04c6db;
  left: 50px;
}
<div class="model-7">
  <div class="checkbox">
    <input type="checkbox">
    <label></label>
  </div>
</div>

Looking to customize the height of the toggle button? The challenge lies in finding the right element in the CSS that controls the height. Despite attempts to adjust the height property in the .checkbox label section, the desired changes are not reflected. Any insights on how to effectively manage the height aspect of the button design?

Answer №1

Altering the label and its ::after pseudo-element height will adjust the size of the toggle button

/* customize toggle button appearance */
*, *:after, *:before {
  box-sizing: border-box;
}

/*=====================*/
.checkbox {
  position: relative;
  display: inline-block;
}
.checkbox:after, .checkbox:before {
  font-family: FontAwesome;
  font-feature-settings: normal;
  -webkit-font-kerning: auto;
          font-kerning: auto;
  font-language-override: normal;
  font-stretch: normal;
  font-style: normal;
  font-synthesis: weight style;
  font-variant: normal;
  font-weight: normal;
  text-rendering: auto;
}
.checkbox label {
  width: 90px;
  position: relative;
  display: inline-block;
  border-radius: 46px;
  transition: 0.4s;
}
.checkbox label:after {
  content: '';
  position: absolute;
  width: 50px;
  border-radius: 100%;
  left: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  transition: 0.4s;
}
.checkbox input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  opacity: 0;
  cursor: pointer;
}
.checkbox input:hover + label:after {
  box-shadow: 0 2px 15px 0 rgba(0, 0, 0, 0.2), 0 3px 8px 0 rgba(0, 0, 0, 0.15);
}
.checkbox input:checked + label:after {
  left: 40px;
}

.model-7 .checkbox label {
  background: none;
  border: 5px solid #555;
  height: 30px;
  margin-left: 15px;
}
.model-7 .checkbox label:after {
  background: #555;
  box-shadow: none;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
}
.model-7 .checkbox input:checked + label {
  border-color: #04c6db;
}
.model-7 .checkbox input:checked + label:after {
  background: #04c6db;
  left: 50px;
}
<div class="model-7">
  <div class="checkbox">
    <input type="checkbox" >
    <label></label>
  </div>
</div>

  

Answer №2

After utilizing Chrome to inspect the code, I made modifications to the .model-7 .checkbox label and model-7 .checkbox label:after, successfully adjusting the height of the button. By implementing the code below, the button appeared larger. It is possible to fine-tune the animation once the desired size is set.

Custom CSS

.model-7 .checkbox label {
  background: none;
  border: 5px solid #555;
  height: 62px;
  margin-left: 15px;
}
.model-7 .checkbox label:after {
  background: #555;
  box-shadow: none;
  top: 5px;
  left: 5px;
  width: 40px;
  height: 40px;
}

Answer №3

Here is how I plan to proceed...

szW.value = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--szW'))
szH.value = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--szH'))

document.querySelectorAll('input[type=range]').forEach(r=>r.oninput=_=>
  {
  r.closest('label').dataset.val = r.value
  document.documentElement.style.setProperty(`--${r.id}`, `${r.value}px`)
  })
:root {
  --szW : 90px;
  --szH : 40px;
  --szB : 5px;    
  }
  
body {
  font-family : Arial, Helvetica, sans-serif;
  font-size   : 16px;
  }
*, *:after, *:before {
  box-sizing : border-box;
  }

input[type=checkbox].model-8 {
  display: none;
}
input[type=checkbox].model-8 + label {
  position      : relative;
  display       : inline-block;
  width         : var(--szW);
  height        : var(--szH);
  border        : var(--szB) solid #555555;
  border-radius : calc( var(--szH) / 2 );
  transition    : 0.4s;
  }
input[type=checkbox].model-8 + label::before {
  position         : absolute;
  top              : 1.5px;   
  left             : 1.5px;
  display          : block;
  content          : ' ';
  width            : calc( var(--szH) - ( var(--szB) * 2 ) - 3px);
  height           : calc( var(--szH) - ( var(--szB) * 2 ) - 3px);
  border-radius    : 50%;
  background-color : #555555;
  transition       : 0.4s;
  }
input[type=checkbox].model-8:checked + label {
  border-color : #04c6db;
  }
input[type=checkbox].model-8:checked + label::before {
  left             : calc( var(--szW) -  var(--szH) + 1.5px );
  background-color : #04c6db;
  }

/******************************/
label.rg input {
  vertical-align : middle;
  width          : 300px;
  }
label.rg::after {
  content : attr(data-val) 'px';
  }
label.rg::before {
  display : inline-block;
  width   : 3.3em;
  content : attr(data-lib);
  }
<h3>make your sizing</h3>
<label class="rg" data-val="90" data-lib="width :"><input type="range" id="szW"  min="40" max="200" step="10" value="90"></label> <br>
<label class="rg" data-val="40" data-lib="height :"><input type="range" id="szH" min="30" max="80" step="5" value="40"></label> <br>

<hr>
<br>
<input type="checkbox" id="m8" class="model-8" ><label for="m8"></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

Reposition text below images in Meta Slider

I have a website where I am utilizing Meta Slider within Wordpress. I would like to position the captions below the images instead of on top of them. Meta Slider claims this feature is only available in the Pro version, but could it be achieved by adjustin ...

The bot on Discord.js is sending an incorrect message when attempting to use the _leave command on the music bot

I have been following the tutorials from Plexi Development's YouTube channel to create a music bot. I have implemented the code, but whenever I try to use the _leave command, my bot refuses to leave the voice channel even though I am in the same chann ...

Activate Vuetify to toggle a data object in an array list when the mouse hovers over

I'm currently working on a project where I need to toggle a Vuetify badge element for each item in an array when the containing div is hovered over. While I've been able to achieve a similar effect using CSS in a v-for loop with an array list, I ...

Using dual ngFor in Angular 4: A step-by-step guide

I am encountering an issue in my Angular 4 project where I receive two different arrays in response to a server request, and I want to utilize both of them in the template. Here is my controller code: this.contractService.getOwnerContract() .subscribe( ...

Utilizing dynamic data within the ng-template

As a newcomer to Angular, I am facing a challenge in passing a string into a template. My goal is to create a reusable template or component that can display instructions on how to proceed with an action. Currently, I am achieving this by using the follow ...

Generate a JSON (Jquery) structured table matrix outlining various roles and corresponding permissions such as read, write, delete, and write special

I would like to create a table matrix that displays roles and permissions (read, write, delete, write special) using jQuery with JSON data. The table should contain checkboxes for each permission type, and the checkboxes for read, write, delete, and write ...

What is the best way to retrieve a value from an object using a promise after a certain period of time

During an event, I receive a user object. When I try to access the user._properties.uid value before using setTimeout, it returns as undefined. However, when I implement setTimeout, the value is successfully fetched after a few seconds. Is there a way to ...

What steps should I take to ensure that the login page functions properly?

Below is the HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login Pag ...

The XMLHttpRequest() function throws NS_ERROR_FAILURE when sending requests to localhost using either an absolute or relative path

Encountering an error in Firefox 31 ESR: Error: NS_ERROR_FAILURE: Source file: http://localhost/Example/scripts/index.js Line: 18 Similar issue observed on Internet Explorer 11: SCRIPT5022: InvalidStateError The script used for AJAX function call i ...

Can a universal selector be used to target a specific nth element and all subsequent occurrences of that element type?

As I navigate through using a data scraper, I find myself in the realm of code where my knowledge is limited. The tool I am using is free but comes with its limitations such as a crawl limit and no option to resume from the endpoint. My goal is to scrape ...

Determine the Nautical Miles Between Various Coordinate Points using React

Does anyone have a solution for calculating nautical miles using react? Let's say I have this object: const calculateDistance = [ {point_id: 1, long: longitude , lat: latitude}, {point_id: 2, long: longitude , lat: latitude}, {point_id: 3, ...

Encountered an unhandled rejection error: TypeError: Unable to destructure the property 'protocol' of 'window.location' because it is undefined

I integrated the react-tradingview-widget into my nextjs project and it was working perfectly on version 10.2.3. However, after upgrading to version 12.1.4, I encountered an error when trying to reload the tradingview component. The error message was: unh ...

Is there a way for me to import a variable from one file and use require() to access it in another file?

This is my current folder structure: collegesapp -- |-- node_modules -- express | -- connect | -- jade | -- passport |-- routes -- routes.js ...

Creating a custom Angular filter to group every 3 items within an iteration into a new div container

When attempting to organize three instances of app-story-preview within a wrapper div using a ngFor loop, I encountered the following code: <ng-template [ngIf]="stories.length > 0" [ngIfElse]="empty"> <cdk-virtual-scroll-viewport [itemSize ...

Searching for a specific key and its corresponding value within an Object Literal (JSON string / object) is necessary

After reading up on JSON objects , I am now trying to locate the value associated with a specific KEY, which may be null, no or yes. The KEY in question is "f03eb90f-6b5e-4b26-bd9f-bad788b7edac" and I want to retrieve its value You can find the Fiddle ...

Error: An unidentified type was encountered that is not a functioning element within an anonymous PHP JavaScript function

Hello everyone, I am seeking help with a JavaScript error that is causing some trouble. Whenever I try to sort a table and implement pagination in PHP, I get an error message in the console stating "Uncaught TypeError: undefined is not a function." Despite ...

Issue in JavaScript / D3.js: When button is clicked, data fails to update and instead new positions are plotted

When the user clicks a button, both the red woman (unvaccinated) and the blue woman (vaccinated) should be updated to reflect the new value. At present, when the button is clicked, the red woman updates correctly but the blue woman is recreated in the loca ...

Converting JSON information into a JavaScript array of objects

I have a JSON file containing placeholder articles for testing purposes. I'm using jQuery to parse the data from the JSON file and create an array of objects with the retrieved information. Take a look at my JSON file: { "news": [ { ...

What are some strategies for increasing efficiency in my drag and drop process?

Update #2 Wow, transition was stuck at .35s. My CSS just wasn't updating properly :( UPDATE: Anyone know if requestAnimationFrame could help with this? I've got a rotating image reel and I want users to be able to swipe left or right to switch ...

How to ensure the height of an image in a Bootstrap flex row matches the

I just updated to the latest Bootstrap 5.0 beta version and I'm working with this html code snippet: <div> <div class="d-flex flex-row"> <img src="img/funny.png" alt=""> ...