Place form at center of page using bootstrap - css

I have a bootstrap login form appearing at the top centered page but i need it to present at the center of page.
<div class="container">
<div class="row">
<div class="col-sm-6 col-sm-offset-3 well offset4">
<div class="">
<div class="text-warning">
<h3>Login to our site</h3>
<p>Enter your username and password to log in</p>
</div>
</div>
<div class="">
<form role="form" action="" method="post" class="">
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
<input type="text" name="form-username" placeholder="Username..." class="form-control" id="form-username">
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<input type="password" name="form-password" placeholder="Password..." class="form-control" id="form-password">
</div>
<button type="submit" class="btn btn-warning col-sm-12"><strong>Sign in!</strong></button>
</form>
</div>
</div>
</div>
</div>
How can i center this form to a page using bootstrap/angularjs?

By default bootstrap has no tools to vertical centering.
For a login page you can just add this absolute centering :
.perfect-centering {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%,-50%);
}
Maybe it will be include as mixin in Bootstrap 4 ... But for now, you have to use additional styles,
I think.

I added just a div outside yours container :
<div class="center">
<div class="container">
<div class="row">
<div class="col-sm-6 col-sm-offset-3 well offset4">
<div class="">
<div class="text-warning">
<h3>Login to our site</h3>
<p>Enter your username and password to log in</p>
</div>
</div>
<div class="">
<form role="form" action="" method="post" class="">
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
<input type="text" name="form-username" placeholder="Username..." class="form-control" id="form-username">
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<input type="password" name="form-password" placeholder="Password..." class="form-control" id="form-password">
</div>
<button type="submit" class="btn btn-warning col-sm-12"><strong>Sign in!</strong></button>
</form>
</div>
</div>
</div>
</div>
</div>
also a new css class defined as :
.center{
position:absolute;
top:50%;
left:50%;
padding:10px;
-ms-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
UPDATE: if you have in local your bootstrap file just add this class without create other files, if you link to bootstrap tou can maybe add a div with style, like :
<div style=" position:absolute;
top:50%;
left:50%;
padding:10px;
-ms-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);">....</div>
instant of center class

Here is a solution without absolute positioning using view-height. It will probably retain the responsive width of the form.
CSS
/* body {height:100vh;} */ /* if needed */
.full-height {height:100vh;background-color:yellow;}/* 100% of the view-height */
.form-height {margin-top:-130px;}/* minus half the form-height */
.form-v-middle {margin-top:50vh;}/* half the view-height */
HTML
<div class="container full-height">
<div class="row form-height">
<div class="col-sm-6 col-sm-offset-3 well offset4 form-v-middle">
<div class="">
<div class="text-warning">
<h3>Login to our site</h3>
<p>Enter your username and password to log in</p>
</div>
</div>
<div class="">
<form role="form" action="" method="post" class="">
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
<input type="text" name="form-username" placeholder="Username..." class="form-control" id="form-username">
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<input type="password" name="form-password" placeholder="Password..." class="form-control" id="form-password">
</div>
<button type="submit" class="btn btn-warning col-sm-12"><strong>Sign in!</strong></button>
</form>
</div>
</div>
</div>
</div>
Example:
http://www.bootply.com/2wtIZimo3W
vh browser support:
http://caniuse.com/#search=vh

Related

two vertical inputs share a common button

I have a form, in that n number of form fields available. only For 2 inputs, I want to share a common button without affecting remaining layout, but it's not aligned properly as common.
Here is what I tried. First two input fields should have common button
<div class="container">
<div class="row">
<div class="col">
<div class="form-group pt-4">
<input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>
<div class="col">
<button type="submit" class="btn btn-secondary mt-4"><i class="fas fa-ellipsis-v"></i></button>
</div>
</div>
I assume that you want to center the button for two input elements. Is that so you can try display:table for the .row this might have fix your issue.
.row {
display: table;
width: 100%;
}
.row .col{
display: table-cell;
}
.col1 {
width: 40%;
}
.col2 {
position: relative;
vertical-align: top;
}
.col2 button {
position: absolute;
top: 30px;
left: 0;
}
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.css" >
</head>
<body>
<div class="container">
<div class="row">
<div class="col col1">
<div class="form-group pt-4">
<input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>
<div class="col col2">
<button type="submit" class="btn btn-secondary mt-4"><i class="fas fa-ellipsis-v"></i></button>
</div>
</div>
</div>
</body>
</html>
However if you want to increase the size for the button you can always add padding or set height for the button.
Codepen link
Pure bootstrap 4 impementation wll be the one below.
You have to group the two inputs into one single .col and the button to an another .col with flex-grow-0 flex-shrink-1 mb-3 d-flex to shrink the container to the minimum of button width and to have sufficient margin at bottom.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col">
<div class="row">
<div class="col">
<div class="form-group pt-4">
<input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>
<div class="col flex-grow-0 flex-shrink-1 mb-3 d-flex">
<button type="submit" class="btn btn-secondary mt-4"><i class="fas fa-ellipsis-v"></i></button>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>
</div>
</div>
col-auto in bootrap 4.0.0 does not have padding. And there may be some other bugs too. You should better use the latest version of bootstrap 4. it is version 4.6.0
Use two .row. The first .row for the first two inputs and the button and the second .row for the rest of the inputs.
Use .col-auto and .d-flex for the column that contains the button to make it take as much space at it need and full height
Use .mb-3 for the button since the .form-group has that much margin-bottom.
You may use .btn-outline-secondary instead of .btn-secondary
<div class="col-auto d-flex ">
<button type="submit" class="btn btn-secondary mt-4 mb-3"><i class="fas fa-ellipsis-v"></i></button>
</div>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col">
<div class="form-group pt-4">
<input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>
<div class="col-auto d-flex">
<button type="submit" class="btn btn-outline-secondary mt-4 mb-3"><i class="fas fa-ellipsis-v"></i></button>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>
</div>
🎁
Doing so you avoid multiple nesting of .row and .col.
here is another approach, also rethinking the structure with only BS class for the styling
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col ">
<div class="form-group pt-4">
<input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
</div>
<div class="form-group">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>
<button type="submit" class="btn btn-secondary mt-4 mb-3"><i class="fas fa-ellipsis-v"></i></button>
</div>
<div class="form-group row pl-3">
<input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
</div>
</div>

With Bootstrap 4, how to prevent form groups from overlapping on one another?

I'm using Bootstrap 4 to create a Profile Edit form in my React app..
The form looks fine on a large display, but when on a small display like mobile, the form-groups are overlapping. See the problem image below, notice how the Profile Photo placeholder image is on top of First Name when it should be pushing First Name down and not overlapping.
Am I doing something wrong with the bootstrap Grid system or with form-groups?
JSFiddle: https://jsfiddle.net/v9fpfxyo/
CORRECT:
PROBLEM:
code from JSFiddle:
<div class="container">
<form>
<div class="row">
<div class="col-lg-3 col-sm-12">
<div class="form-group" style="height: 100%;">
<label for="files">Change your profile photo</label>
<span>
<div class="" style="width: 100%; height: 100%; font-size: 0px; margin-bottom: 1rem; background-color: rgb(29, 161, 242); background-image: url("https://abs.twimg.com/a/1498195419/img/t1/highline/empty_state/owner_empty_avatar.png"); background-position: 50% center;">
<!-- react-text: 85 -->Try dropping some files.<!-- /react-text --><input type="file" accept="image/jpeg, image/png" multiple="" style="display: none;">
</div>
<button type="button" class="btn btn-secondary btn-sm btn-block">Upload new Photo</button><!-- react-text: 88 --><!-- /react-text -->
</span>
</div>
</div>
<div class="col-lg-9 col-sm-12">
<div class="form-group">
<label>First Name</label>
<div><input type="text" name="first_name" value="XXX" placeholder="First Name" class="form-control"></div>
</div>
<div class="form-group">
<label>Last Name</label>
<div><input type="text" name="last_name" value="XXX" placeholder="Last Name" class="form-control"></div>
</div>
</div>
</div>
<div class="row row justify-content-end">
<div class="col-lg-9 col-sm-12"><button type="submit" class="btn btn-primary">Save Changes</button></div>
</div>
</form>
</div>
I had this kinda issue a lot. the way i dealt with them is using media queries. Add a class to the right grid (col-lg-9 col-sm-12). And on smaller screens #media (min-width: 780px) give the class margin-top: 30px;
Let me know if this works for you
Set The Margin OR Apply Css Code media width for mobile device and give the margin for it.
margin-top: 110px;
Example:
<div class="col-lg-9 col-sm-12">
<div class="form-group" style="margin-top: 110px;">
<label>First Name</label>
<div><input type="text" name="first_name" value="XXX" placeholder="First Name" class="form-control"></div>
</div>
<div class="form-group">
<label>Last Name</label>
<div><input type="text" name="last_name" value="XXX" placeholder="Last Name" class="form-control"></div>
</div>
</div>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<form>
<div class="row">
<div class="col-lg-3 col-sm-12">
<div class="form-group" style="height: 100%;">
<label for="files">Change your profile photo</label>
<span>
<div class="" style="width: 100%; height: 100%; font-size: 0px; margin-bottom: 1rem; background-color: rgb(29, 161, 242); background-image: url("https://abs.twimg.com/a/1498195419/img/t1/highline/empty_state/owner_empty_avatar.png"); background-position: 50% center;">
<!-- react-text: 85 -->Try dropping some files.<!-- /react-text --><input type="file" accept="image/jpeg, image/png" multiple="" style="display: none;">
</div>
<button type="button" class="btn btn-secondary btn-sm btn-block">Upload new Photo</button><!-- react-text: 88 --><!-- /react-text -->
</span>
</div>
</div>
<div class="col-lg-9 col-sm-12">
<div class="form-group" style="margin-top: 110px;">
<label>First Name</label>
<div><input type="text" name="first_name" value="XXX" placeholder="First Name" class="form-control"></div>
</div>
<div class="form-group">
<label>Last Name</label>
<div><input type="text" name="last_name" value="XXX" placeholder="Last Name" class="form-control"></div>
</div>
</div>
</div>
<div class="row row justify-content-end">
<div class="col-lg-9 col-sm-12"><button type="submit" class="btn btn-primary">Save Changes</button></div>
</div>
</form>
</div>

how do you adjust bootstrap form and button to be the same height inside a div?

I have the below HTML and CSS - how do I make the search-bar and add-contacts the same height? I currently have their height set to 100% in CSS to expand inside their container div but that doesn't work Is it possible to change their height even though they are bootstrap units?
HTML
<div className="container">
<form className="form-inline search-bar" role="form">
<div className="form-group has-success has-feedback">
<label className="control-label" htmlFor="inputSuccess4"></label>
<input type="text" className="form-control" id="inputSuccess4" type="text" placeholder="Search" onChange={handleChange}/>
<span className="glyphicon glyphicon-search flipped form-control-feedback"></span>
</div>
</form>
<div className="add-contacts">
<button type="button" className="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
+ Contacts Keeper
</button>
</div>
</div>
CSS
.table-container {
margin: 20px;
}
.search-bar {
margin-left: 20px;
float: left;
height: 100%;
}
.add-contacts {
margin-right: 20px;
float: right;
height: 100%;
}
Just change the height of the search bar.
Or you could put search bar in same div as add contacts bar.
I find simpler is better with Bootstrap. I try to avoid adding custom CSS for most of the HTML elements already styled by Bootstrap:
<div class="container">
<div class="row">
<div class="col-md-12">
<form class="form-horizontal">
<div class="col-md-3 text-left">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">Search</label>
<div class="input-group">
<input type="text" class="form-control" id="exampleInputAmount" placeholder="Search">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
</div>
</div>
</div>
<div class="col-md-6"></div>
<div class="col-md-3 text-right">
<button type="submit" class="btn btn-primary">+ add stuff</button>
</div>
</form>
</div>
</div>
</div>

Bootstrap search box and button aligned to right of header text (not in nav bar)

I'm using Bootstrap 3.3.7 and am having difficulty getting the search box and button to drop underneath the heading text when viewed on small screen.
I'd like to get it to stack as follows:
Large screen (as it is currently):
[Title] [search input] [submit button]
Smaller screen:
[Title]
[search input] [submit button]
Small screen:
[Title]
[search input]
[submit button]
Any help much appreciated. I've been at this for ages and my CSS skills are too lacking for me to make any decent headway. Thanks.
Large screen:
Smaller screen (button gets cut off):
Small screen:
Here's my code:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<!-- all the navigation stuff -->
</div>
</nav>
<!-- main content -->
<div class="container" role="main">
<div class="page-header">
<form action="" method="GET" class="form-inline pull-right">
<div class="form-group form-group-lg has-feedback">
<label class="sr-only" for="search">Search</label>
<input type="text" class="form-control" name="q" id="search" placeholder="Search">
<span class="glyphicons glyphicons-xl glyphicons-group form-control-feedback"></span>
</div>
<button type="submit" class="btn btn-lg btn-success">
<span class="glyphicons glyphicons-search" aria-hidden="true"></span>Search
</button>
</form>
<h2>Quite Long Header Text</h2>
</div>
<!--rest of page content -->
</div>
update
Thank you # Robert C. This is how things look with your suggestion:
and
and
The button has reduced in size which is great, but the input field now spans the entire width. I think it would all work just fine if the small button and input field were in the same row. This would mean that even on small devices I'd only need two stacks.
Could you suggest how I might go about reducing the size of the input box so that it will allow the button to stick to its left side on the same 'row'?
Thanks a lot
You will need to add some wrappers to make sure everything is lined up (or, alternatively remove the padding on your <h2>) but something along the following should provide you a Bootstrap Grid solution:
<div class="container" role="main">
<div class="row">
<div class="col-md-8 col-sm-8 col-xs-12">
<h2>Quite Long Header Text</h2>
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
<form action="" method="GET" class="form-main">
<div class="col-md-10 col-sm-10 col-xs-12">
<label class="sr-only" for="search">Search</label>
<div class="input-group">
<input type="text" class="form-control input-search" name="q" id="search" placeholder="Search">
<span class="input-group-addon group-icon"><span class="glyphicon glyphicon-user"></span>
</div>
</div>
<div class="col-md-2 col-sm-2 col-xs-12">
<button type="submit" class="btn btn-success">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span><span class="hidden-sm hidden-xs"> Search </span>
</button>
</div>
</div>
</div>
</div>
You can see a Bootply fiddle here: http://www.bootply.com/bhvdBwcX4b
To view the Bootply fiddle on smaller screens be sure to click the mobile icon, as simply resizing your browser will result in a rendering error warning.
Of the top of my head you need to use col and rows to work it out. Here is the col part...
<!-- main content -->
<div class="col-lg-6 col-md-6 col-sml-12">
<h2>Quite Long Header Text</h2>
</div>
<div class="col-lg-6 col-md-6 col-sml-12">
<form action="" method="GET" class="form-inline">
<div class="form-group form-group-lg has-feedback">
<label class="sr-only" for="search">Search</label>
<input type="text" class="form-control" name="q" id="search" placeholder="Search">
<span class="glyphicons glyphicons-xl glyphicons-group form-control-feedback"></span>
</div>
<button type="submit" class="btn btn-lg btn-success">
<span class="glyphicons glyphicons-search" aria-hidden="true"></span>Search
</button>
</form>
</div>
I have restructured my previous solution for your problem. Have a look at the example here CODEPEN.
Hope it will be helpful to you
HTML:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<!-- all the navigation stuff -->
</div>
</nav>
<!-- main content -->
<div class="section-main">
<div class="container" role="main">
<div class="row">
<div class="col-xs-12 col-md-6">
<h2>Quite Long Header Text</h2>
</div>
<div class="col-xs-12 col-md-6">
<form action="" method="GET" class="form-main form-inline nofloat-xs pull-right pull-left-sm">
<div class="form-group form-input-fields form-group-lg has-feedback">
<label class="sr-only" for="search">Search</label>
<div class="input-group">
<input type="text" class="form-control input-search" name="q" id="search" placeholder="Search">
<span class="input-group-addon group-icon"> <span class="glyphicon glyphicon-user"></span>
</span>
</div>
<button type="submit" class="btn btn-lg btn-success btn-submit">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span> Search
</button>
</div>
</form>
</div>
</div>
<!--rest of page content -->
</div>
</div>
CSS:
.form-main {
margin-top: 15px;
}
.form-input-fields {
margin-bottom: 0;
}
.section-main {
margin-top:40px;
background-color: lightgrey;
padding: 20px 0;
}
.group-icon {
background-color:#fff;
border:0;
}
.input-search {
border:1px solid #fff;
box-shadow:none;
}
#media (max-width: 992px) {
.pull-left-sm {
float: left !important;
}
}
#media (max-width: 767px) {
.nofloat-xs {
float: none !important;
}
.btn-submit {
margin-top:10px;
}
}
enjoy :)

my css selector for form-control is not working

div class="container">
<div class="row">
<div class="col-md-6">
<form class="form-inline" action="#" method="POST" role="form" name="myForm" style="margin-top: 50px;">
<div class="well">
<div class="form-group col-sm-12">
<label class="Control-label col-sm-4" id=""> Email:</label>
<label class="Control-label col-sm-4" id=""> Username:</label>
<label class="Control-label col-sm-4" id=""> Password:</label>
</div>
<div class="row">
<div class="form-group ">
<div class="input-group col-sm-12">
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Email here" ng-model="Email" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Username here" ng-mode="Username" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Password here" ng-mode="Password" required/>
</div>
</div>
</div>
<h1> Test </h1>
</div>
</div>
</form>
</div>
</div>
and my CSS code is :
.form-control{
width: 150px;
}
h1{
color:red;
}
Good Day mate, i am just confuse if im doing right or not. i want to resize the input on my website which defined as class "form-control" but when i do the css above nothing changes. can someone help me if my selector or wrong or my codes is? thank you
P.S the test below is just a xample if the css is being link in my editor and yes the color red is being executed
The more specific the selector, the more precedence it has. For example :
.mydiv .myclass {
background-color: blue;
}
.myclass {
background-color: red;
}
Even tho the red background is defined after the blue one, the first one is more specific in the class that it is applied to, and in case you have the following code, the blue background will be applied :
<div class="mydiv">
<div class="myclass">
</div>
</div>
So what you want to do in your case, and this is the most basic but still the better solution, is to add a class to your form in order to be able to specify the width of the form-control elements for this form :
<form class="form-inline cool-form">
<div class="well">
<div class="form-group ">
<div class="input-group col-sm-12">
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Email here" ng-model="Email" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Username here" ng-mode="Username" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Password here" ng-mode="Password" required/>
</div>
</div>
</div>
</div>
</form>
And then specify the width in your css :
.cool-form .form-control {
width: 250px;
}
try this:
note: and you are missing to close your first div i.e <div class="container">
.form-control::-webkit-input-placeholder {
color: red;
width: 250px;
}
h1 {
color: red;
}
<div class="container">
<div class="row">
<div class="col-md-6">
<form class="form-inline" action="#" method="POST" role="form" name="myForm" style="margin-top: 50px;">
<div class="well">
<div class="form-group col-sm-12">
<label class="Control-label col-sm-4" id="">Email:</label>
<label class="Control-label col-sm-4" id="">Username:</label>
<label class="Control-label col-sm-4" id="">Password:</label>
</div>
<div class="row">
<div class="form-group ">
<div class="input-group col-sm-12">
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Email here" ng-model="Email" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Username here" ng-mode="Username" required/>
</div>
<div class="col-sm-4">
<input class="form-control" placeholder="Enter Password here" ng-mode="Password" required/>
</div>
</div>
</div>
<h1> Test </h1>
</div>
</div>
</form>
</div>
</div>
You are using Bootstrap and form-control class is used from Bootstrap CSS.
Use (Easy way)
.form-control{
width: 150px !important;
}
to override your code over Bootstrap CSS
The best practice -
In your case the class is .form-control (Bootstrap class)
To overcome this is to define new class and add new changes to your own class.
.form-control-override{
width: 150px;
}
and use this form-control-override in your HTML code instead of form-control

Resources