Bootstrap checkbox size wrong with smaller body font - css

I have set my default font size to be based on 10px via 62.5%, and then set the body to be 1.4rem. This seems to cause issues with the custom checkbox controls and they no longer align correctly.
I'm using Bootstrap 4's SASS files combined with my own. Is there something in the variables file that I'm missing to fix this? Or maybe some overrides I need to do? I've tried messing with various padding, margins, font sizes, etc. but the way they have this working isn't obvious.
Here is what I have set for the default font sizes for the site:
html {
font-size: 62.5%;
}
body {
font-size: 1.4rem;
}
And here is the HTML
<div class="container-fluid">
<div class="row align-items-end">
<div class="col">
<div class="form-group">
<label for="worker">Worker</label>
<select class="form-control" id="worker">
<option>Jane Doe</option>
<option>John Smith</option>
</select>
</div>
</div>
<div class="col">
<div class="form-group">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Check this custom checkbox</span>
</label>
</div>
</div>
</div>
</div>
JSFiddle
To sum up, basically I need the ability to change the body font size and yet still have the checkbox to still work correctly and be the same height as the input fields when they are next to each other.

You can make the parent element flex and use align-items to center vertically. You would also need to use non-absolute position on the checkbox element. That will keep them centered vertically regardless the font size of the page.
html {
font-size: 62.5%;
}
body {
font-size: 1.4rem;
}
.custom-control {
display: flex;
align-items: baseline;
}
.custom-control-indicator {
position: static;
margin: 0 .5rem 0 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row align-items-end">
<div class="col">
<div class="form-group">
<label for="worker">Worker</label>
<select class="form-control" id="worker">
<option>Jane Doe</option>
<option>John Smith</option>
</select>
</div>
</div>
<div class="col">
<div class="form-group">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Check this custom checkbox</span>
</label>
</div>
</div>
</div>
</div>
You could also use top: 50%; transform: translateY(-50%); to center the checkbox vertically, then set the line-height of the text to 1 so it doesn't affect vertical alignment.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<style>
html {
font-size: 62.5%;
}
body {
font-size: 1.4rem;
}
.custom-control-indicator {
top: 50%;
transform: translateY(-50%);
}
.custom-control-description {
line-height: 1;
}
</style>
<div class="container-fluid">
<div class="row align-items-end">
<div class="col">
<div class="form-group">
<label for="worker">Worker</label>
<select class="form-control" id="worker">
<option>Jane Doe</option>
<option>John Smith</option>
</select>
</div>
</div>
<div class="col">
<div class="form-group">
<label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Check this custom checkbox</span>
</label>
</div>
</div>
</div>
</div>

A simple solution would be to change the styles for the checkbox:
.custom-control-indicator {
height: 1.4rem;
width: 1.4rem;
top: calc(1.4rem * 0.25);
}
Change the 1.4rem as required to the same size as the body font-size (you can also set this up to work automatically using SASS variables

Related

Make text box stop growing after sm break point?

I have a bootstrap 4 input text box. I want make it stop growing after sm break point, so that it won't expand to the full screen width.
Use col-md-* in wrap div of input...
the sm takes all screen and from md and up it takes width as you set in col-md-*
See fiddle:https://jsfiddle.net/s9q4d681/3/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="email" class="form-control" placeholder="Enter email">
</div>
</div>
</div>
</div>
.row {
margin-top: 20px;
}
.col {
background: #f8f9fa;
border: solid 1px #ddd;
padding: 5px 10px;
}
.col-sm-6 {
background: #f8f9fa;
border: solid 1px #ddd;
padding: 10px;
}
input{
max-width: 340px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col">
Col-6
</div>
<div class="col">
Col-6
</div>
</div>
<div class="row">
<div class="col-sm-6">
<form action="">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
</form>
</div>
</div>
</div>
You can simply restrict input field width using max-width CSS property.

How to use font awesome icon with bootstrap and large fonts

I am creating a screen to a kiosk/totem machine and I need to use large fonts.
I have a problem using input group with font awesome icons and alignment.
As I use large fonts, I had to add a 'margin-top:10px' to align the input to your label.
The side effect is that the awesome icon becomes misaligned on top.
Fiddle: http://jsfiddle.net/vb0xo8wb/
//markup
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12 form-container">
<form class="form form-horizontal" name="regForm" autocomplete="false" novalidate="" role="form">
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
<div class="col-sm-12">
<div class="row">
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
<div class="form-group">
<label class="col-sm-2 control-label">Nome</label>
<div class="col-sm-10 recuo">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-user fa-2x bg-info"></i>
</span>
<input take-focus="" type="text" class="form-control input-lg" name="user_name" required="" placeholder="Digite seu nome">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
//css
#import url('https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css');
#import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css");
#import url(http://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300ita‌​lic,400italic,500,500italic,700,700italic,900italic,900);
html, html * {
font-family: Roboto;
}
form label {
font-size: 28px !important;
}
form input, form textarea, form select {
margin-top:10px;
font-family: Roboto;
font-weight: bold;
}
.recuo{
padding-left:30px;
}
.fonte_big {
font-size: 28px !important;
}
.form-container {
background-color: rgba(0, 0, 0, 0.6);
padding: 20px;
margin-top:50px;
}
Adding
.input-lg {
margin: 0 !important;
}
should fix the issue.

set my objects to left of the columns in bootstrap 3

I am using bootstrap 3 in my website.
I created a row that looks like the following image, within this row, i've created 4 columns:
Left: picture
L-R: text
L-L: Input
Right: Button
Where is my problem ?
1. Set the user/password/input/login button to the left of the columns
2. set button height small
3. "Forgot your password" to be in 1 line and not 2 lines.
Like the following picture:
I am new to HTML/CSS. How can i achieve it ?
Here is my code:
<div class="row loginBody">
<div class="col-md-4 "></div>
<div class="col-md-4 ">
<div class="container-fluid InputLoginDetails LoginFont">
<div class="row LoginRow">
<div class="col-md-4"><img src="img/Hello.png" class="img-responsive" /></div>
<div class="col-md-2">
User:
Password:
</div>
<div class="col-md-3 ">
<input type="text" class="form-control">
<input type="text" class="form-control">
<p>Forgot your password?</p>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-primary ">Login</button>
</div>
</div>
</div>
</div>
.loginBody{
background-color: #808689;
margin: auto;
margin-top: 5%;
border-radius: 5px;
}
.LoginRow{
padding-top: 3%;
padding-bottom: 3%;
background-color: white;
}
.LoginFont{
font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif;
color: #7296cd;
font-size: 1em;
font-weight: bold;
padding-top: 5%;
}
.InputLoginDetails input[type="text"] {
height: 1.1em;
font-size: 0.9em;
}
I changed several things in your HTML markup.
1.) You don't use .container classes within a row, they are just used as containers outside of rows.
Note that, due to padding and more, neither container is nestable.
Bootstrap Containers
2.) You don't need 4 columns within your '.LoginRow', one for the image and one for the form elements are sufficient and give you more flexibility.
3.) Use the horizontal forms markup of bootstrap to create the form layout.
4.) All in all, you need to take a closer look at the Bootstrap docs and their examples, especially the grid system. Then it is really easy to do a lot of things.
Here is your changed HTML markup:
<div class="row loginBody">
<div class="col-md-4 "></div>
<div class="col-md-4 ">
<div class="InputLoginDetails LoginFont">
<div class="row LoginRow">
<div class="col-md-4"><img src="http://placehold.it/200x200" class="img-responsive"></div>
<div class="col-md-8">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">User</label>
<div class="col-sm-6">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
<div class="col-sm-4">
<button type="button" class="btn btn-primary">Login</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-2">
<p>Forgot your password?</p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
You said you wanted to align the User/Password label to the left. Since the bootstrap default labes are aligned to the right, I created this CSS additionally:
.LoginRow .form-group label {
text-align: left;
}
And here is a working bootply
If I understood correctly, and with the code you have provided. I think you didnt have to add both labels with the same div and input boxes. Please check the fiddle to see if thats what you wanted.
I also removed the <p> tag from "Forgot your password".
I changed
<div class="col-md-2">
User:
Password:
</div>
To
<div class="col-md-2">
User:
<input type="text" class="form-control">
</div>
Fiddle

div will not scroll under another div

I have a need to get the TextBoxesGroup scrolling under the image on the top if the visitors scroll up or under the Add to basket in the footer if the visitors scroll down.
My footer add-to-wrap is pretty much fixed but the problem is that the div will not scroll undless it goes well under the footer and then when I scroll the add-to-wrap div also scrolls.
What am I doing wrong?
<style>
.wrong_email{
display:none;
color:red;
}
.add-to-wrap {
width: 100%;
display: block;
position: fixed;
bottom: 0;
margin: 0 auto;
text-align: center;
background-color: rgba(0,0,0,0.6);
padding: 10px 0 10px 0;
z-index: 3;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-4" style="padding-left:0px; padding-right:0px;">
<img src="/brand/nvite.png" class="img-responsive"/>
</div>
<div>
<form method="POST" id="login_form">
<div id='TextBoxesGroup' class="textboxes-area">
<div id="TextBoxDiv1">
<input type='text' id='textbox1' name='textbox_1' class="form-control" placeholder="Enter email address here"/>
</div>
<div class="wrong_email" id="err_1">Wrong email address</div>
<div class="divider"><img src="/mobileimages/brand_takeovers/divider_invite.png" class="img-responsive"/></div>
<div id="TextBoxDiv2">
<input type='text' id='textbox2' name='textbox_2' class="form-control" placeholder="Enter email address here"/>
</div>
<div class="wrong_email" id="err_2">Wrong email address</div>
<div class="divider"><img src="/mobileimages/brand_takeovers/divider_invite.png" class="img-responsive"/></div>
<div id="TextBoxDiv3">
<input type='text' id='textbox3' name='textbox_3' class="form-control" placeholder="Enter email address here"/>
</div>
<div class="wrong_email" id="err_3" >Wrong email address</div>
</div>
<span id='addButton' class="send-invite-more-boxes "/><img src="invitemore.png" class="img-responsive"/></span>
</div>
</div>
</div> <!-- /container -->
<div class="add-to-wrap">
<button type="submit" class="send-invite-button">Add To Basket</button>
</div>
</form>

Bootstrap centre horizontal form

I'm trying to centre a horizontal form in a hero unit, by setting text-align:center; and then display:block-inline;
See jsfiddle for a demo http://jsfiddle.net/bVJZ2/
But this hasn't quite worked in that the checkbox and submit button are not correctly aligned any more. Any suggestions how to fix this?
There are some problems that doesn't allow you to center the checkbox.
<div class="controls"> has a margin-left. You shouldn't put your checkbox inside a that div.
The input[checkbox] has a float: left. You should remove that float with:
.radio input[type="radio"], .checkbox input[type="checkbox"] {
float: none;
}
The checkbox is bad aligned. You should add vertical-align: top to the last selector.
To sum up:
HTML:
<div class="control-group">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</div>
CSS:
.radio input[type="radio"], .checkbox input[type="checkbox"] {
float: none;
vertical-align: top;
}
You can see the result here: http://jsfiddle.net/GW8zk/
Well This is how you can implement a Hero-unit with form centered in middle .
JSFiddle with centered form http://jsfiddle.net/shail/YmmVS/
First the css :
.hero-unit {
padding:50px 50px 50px 50px;
}
.form-horizontal .control-label {
width: 61px;
}
.form-horizontal .controls {
margin-left: 80px;
}
/* Landscape phones and down */
#media (max-width: 480px) {
.hero-unit{
margin-left:-20px;
margin-right:-20px;
}
.form-horizontal .controls {
margin-left: 0;
}
}
The Html Part :
<div class="container">
<div class="hero-unit">
<div class="row-fluid">
<div class="offset4 span4">
<legend>Sign in to WebApp</legend>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox">Remember me</label>
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>

Resources