How to override Bootstrap CSS without using inline styling? - html

I'm trying to override Bootstrap's CSS of the following p element:
https://gyazo.com/6bf5dde284fa53fd4c9cd098ddb1f109
(I'd like to add a top-margin: 10px; and remove Bootstrap's bottom margin)
The only way I could get it to override thus far is to use inline styling which i'd prefer to avoid. Also I'd like to avoid !important unless really necessary.
My css files are ordered as follows:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="../css/login.css">
Things i've tried:
<p id="pMargin">
#pMargin {
margin: 10px 0px 0px 0px !important;
}
<p class="pMargin">
.pMargin {
margin: 10px 0px 0px 0px !important;
}
#sdntLogForm p {
margin: 10px 0px 0px 0px !important;
}
body p {
margin: 10px 0px 0px 0px !important;
}
My HTML:
<!-- STUDENT TAB -->
<div id="student" class="tab-pane fade in active">
<form id="sdntLogForm" class="form-container" action="#" method="post">
<div class="error">
<?php
if(isset($error)){
echo ($error);
}
?>
</div>
<div class="form-group">
<h1 class="formHeader">Student Login</h1>
<label for="sdntLogEmail">Email address</label>
<input type="email" class="form-control" id="sdntLogEmail" name="sdntLogEmail" placeholder="Email" tabindex="1" required pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,4}$">
</div>
<div class="form-group">
<label for="sdntLogPass">Password</label>
<input type="password" class="form-control" id="sdntLogPass" name="sdntLogPass" placeholder="Password" tabindex="2">
</div>
<div class="checkbox">
<label>
<input type="checkbox" tabindex="3" id="sdntLogRemember" name="sdntLogRemember">Remember me
</label>
</div>
<button type="submit" class="btn btn-success btn-block" id="sdntLogSubmit" name="sdntLogSubmit" tabindex="4">Login</button>
<p>If you don't have a student account, you can register one here.</p>
</form>
</div>

That link opens a blank page here, so it's a bit hard to tell, but since you only have one p tag in that HTML code, I try it:
Use a CSS selector with as much specifity as possible, i.e.:
div#student.tab-pane.fade.in.active form#sdntLogForm.form-container p { ... }

Related

HTML: Remove space between two inputs using bootstrap

I saw this pretty from from website.
I decided to make it using bootstrap 4, and I failed because of the space between two html input elements. It is neither padding nor margin, I have no idea what is it. I tried to remove the space several times but failed.
The space between two inputs giving me suffer.
This is HTML
<form action="" method="post">
<div class="form__wrapper">
<input type="email" name="email" class="newsletter" placeholder="Email address"/>
<input type="submit" class="newsletter__button"/>
</div>
</form>
This is CSS
.form__wrapper {
display: inline-block;
position: relative;
}
form {
display: block;
}
form input[type='email'], form input[type='text'] {
cursor: text;
-webkit-font-smoothing: antialiased;
width: 100%;
padding: 9px;
border: 1px solid #E1E0E1;
outline: none;
-webkit-border-radius: 0;
border-radius: 0;
-webkit-appearance: none;
-moz-appearance: none;
}
.form__wrapper input[type='email'] {
width: 60%;
}
This gap origins from the space between two inline elements in the source code. that is parsed as a blank space.
However, you don't have to deal with this issue - for this case exactly, Bootstrap provides Input Groups. Just use the input-group class as a wrapper for the two form elements and the input-group-added as a wrapper for the button.
You can style the form elements by using a higher specificity in your selectors. The Icon can also be achieved by FontAwesome (see Nisarg Shahs good answer for that). Here is an example:
body {
padding: 2em;
}
.input-group>.form-control,
.input-group .btn {
border-radius: 0;
border-color: #e3e3e3;
text-transform: uppercase;
font-size: .8em;
line-height: 1.95em;
letter-spacing: 2px;
}
.input-group>.form-control {
border-right: 0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="input-group">
<input type="email" class="form-control" placeholder="Email Address" aria-label="Email Address" aria-describedby="basic-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button">></button>
</div>
</div>
It is called an add-on in Bootstrap 4. Here's an example:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="input-group mb-3">
<input type="email" name="email" placeholder="Email address" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
<div class="input-group-append">
<button class="btn btn-outline-secondary">Submit</button>
</div>
</div>
You can combine that with FontAwesome, to get the desired result:
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="input-group mb-3">
<input type="email" name="email" placeholder="Email address" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
<div class="input-group-append">
<button class="btn btn-outline-secondary">
<span class="fa fa-angle-right"></span>
</button>
</div>
</div>
Write both of your input tags in the same line. Here I've included the fiddle. You can see the difference. :)
<input type="email" name="email" class="newsletter" placeholder="Email address"/><input type="submit" class="newsletter__button"/>
Bootstrap has this built in:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="input-group">
<input class="form-control newsletter" placeholder="Email" type="text">
<div class="input-group-append">
<input class="form-control"t type="submit" class="newsletter__button"/>
</div>
</div>

Legend Tag Not Rendering Correctly With Bootstrap Grid

I want to use the legend html tag to visually wrap a set of similar inputs in a form. It should look similar to how it does when one uses the legend attribute without bootstrap, like is shown here.
I made a bootply example which is here. As one can see: I am trying to create a legend which wraps the First Name and Last name input fields. The styling is not right.
I did already look at this question, but it is different than mine because I am attempting to use a legend within a grid.
Here's a way using custom CSS. Just add this CSS, and add .customLegend to the fieldset that will have a legend you want to display this way. Adjust the positioning, padding, etc as needed.
.customLegend {
border: 1px solid #e5e5e5;
padding: 2em 0 1em;
margin-top: 2em;
position: relative;
}
.customLegend legend {
border: 0;
background: #fff;
width: auto;
transform: translateY(-50%);
position: absolute;
top: 0; left: 1em;
padding: 0 .5em;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<form>
<fieldset class="customLegend row">
<legend>Enter Your Name</legend>
<div class="form-group col-sm-6">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="email">
</div>
<div class="form-group col-sm-6">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="pwd">
</div>
</fieldset>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>

Center input fields in form

I have a login form that is on the center of the page. The FORM is already in the right place with the right size. However, the two inputs are aligned to the left and I want them to be centered. The following code does not work. Any ideas?
HTML
<div class="col-sm-4 col-sm-offset-4">
<form action="/new" method="POST">
<input class="loginField" type="text" name="email" placeholder="Email address"></input>
<input class="loginField" type="text" name="password" placeholder="Password"></input>
</form>
</div>
CSS
.loginField {
margin: 0 auto;
width: 500px;
height: 50px;
}
You should use the form-control class to alter the default behavior of Bootstrap inputs.
*I altered your HTML so it's mobile first, this wont effect the text being centered if it's unnecessary for your needs tho.
body {
padding-top: 50px;
}
#loginForm {
max-width: 500px;
margin: 0 auto;
}
#loginForm .form-control {
position: relative;
height: 50px;
font-size: 16px;
text-align: center;
border-radius: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form id="loginForm">
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
</form>
</div>
<!-- /container -->
<hr>
Add a class="text-center" to your form
<form class="text-center" action="/new" method="POST">
jsBin demo
Logically, if you don't want all your form's text to be centered, wrap your inputs inside a i.e: <div> and add the class to that DIV instead.

Bootstrap border-radius: 4px is adding shadow to input

I'm making a site with bootstrap, and when I add border-radius: 4px to inputs/buttons, is adding shadow too.
Check image:
http://i.stack.imgur.com/K9pz8.png
How can I remove this shadow?
Add class="form-control to the input element it will remove shadow inside.
See demo:
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
input {
border-radius: 5px;
margin: 10px;
}
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="input-group">
<input type="text" class="" placeholder="without class">
<input type="text" class="form-control" placeholder="with class">
</div>
</div>
Try this
#usr{
border-radius:4px;
}
<div class="col-md-4"><div class="form-group">
<label for="usr">Name:</label>
<input type="text" class="form-control" id="usr">
</div>
</div>
Note: Added class = "form-control".
Demo Here

Adding dollar prefix to bootstrap input box

Is there anyway bootstrap way/style to add non-editable prefix into the inputbox? such as the dollar sign. the prefix has to be included inside the input box.
currently I'm doing something like this, but the sign is out of the inputbox.
<div class="input-group input-medium ">
<input type="text" class="form-control input-lg" readonly="">
<span class="input-group-btn">
$
</span>
</div>
Twitter Bootstrap Version 3 has a class named input-group-addon for this feature.
You probably want this
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="text" class="form-control" placeholder="price">
</div>
Js Fiddle Demo - Basic
Update: To remove the background from the $ sign- You just need to overwrite the input-group-addon class
.input-group-addon
{
background-color:#FFF;
}
Js Fiddle Demo - Without Background
If you want to remove the border from right side of $ sign, You can add this css as well
.input-group .input-group-addon + .form-control
{
border-left:none;
}
Js Fiddle Demo - Without Border
HTML:
<div class="col-xs-6" >
<div class="left-inner-addon">
<span>$</span>
<input type="text" class="form-control" placeholder="Amount" />
</div>
</div>
<div class="col-xs-6" >
<div class="right-inner-addon">
<span>$</span>
<input type="search" class="form-control" placeholder="Amount" />
</div>
</div>
CSS:
.left-inner-addon {
position: relative;
}
.left-inner-addon input {
padding-left: 22px;
}
.left-inner-addon span {
position: absolute;
padding: 7px 12px;
pointer-events: none;
}
.right-inner-addon {
position: relative;
}
.right-inner-addon input {
padding-right: 30px;
}
.right-inner-addon span {
position: absolute;
right: 0px;
padding: 7px 12px;
pointer-events: none;
}
jsFiddle
Bootstrap Versions 4 and 5
This functionality changed significantly between versions 3 and 4. The class input-group-addon has been removed in favor of using input-group-text inside of either input-group-prepend or input-group-append.
To prepend text
<!-- importing Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
<input type="text" class="form-control" placeholder="0.00" />
</div>
To append text
<!-- importing Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="input-group">
<input type="text" class="form-control" placeholder="email" />
<div class="input-group-append">
<span class="input-group-text">#gmail.com</span>
</div>
</div>
To change the background color of the added text
.input-group-text
{
background-color:#FFF;
}
You can to this by setting the input-group a position:relative and absolute positioning the input and the span with higher(than input's z-index) z-index number for span. Also you need to add to the input a padding-left value equal to span's width