Customizing input fields in bootstrap - html

How do I place the two input fields close to each other when they have shorter widths on larger screen. The problem is that I want the input fields to be in one line with shorter widths. I eventually achieve that but then on shorter screens it stacks up even though it has enough space to be in one line. Here is the demo.
What I would like to have: Keep the input fields in one line as long as there widths fit in the viewport or else, stack them up with full width.
NOTE: I have just started learning bootstrap and not well versed with all the classes.
HTML
<div class="site-wrapper">
<div class="jumbotron">
<h1>Header</h1>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="input-group-lg">
<input id="user" class="form-control form-inline" placeholder="Your name" type="text">
</div>
</div>
<div class="col-md-6">
<div class="input-group-lg">
<select id="boardSize" class="form-control form-inline" title="Select Size">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
body {
background-color: #fff;
color: #ffffff;
text-align: center;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
margin: 0;
}
html, body {
height: 100%;
background-color: #333;
}
.site-wrapper {
width: 100%;
height: 100%;
min-height: 100%;
-webkit-box-shadow: inset 0 0 100px rgba(0,0,0,.5);
box-shadow: inset 0 0 100px rgba(0,0,0,.5);
}
.jumbotron {
background-color: #ccbb99 !important;
/*background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.9));*/
height: 100%;
margin-bottom: 0;
}
.jumbotron h1 {
font-family: chalkitup, "sans-serif";
color: #69350F !important;
}
#user, #boardSize {
max-width: 280px;
}

To prevent stacking you should use col-xs-*.
If you combine with pull-right and pull-left then you can choose where you want to place your input in the grid. Notice the use of form-inline class
<form class="form-inline">
<div class="col-xs-6">
<div class="form-group pull-right">
<div class="input-group-lg ">
<input id="user" type="text" class="form-control form-inline" placeholder="Your name">
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group pull-left">
<div class="input-group-lg ">
<select id="boardSize" class="form-control form-inline" title="Select Size">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
</div>
</div>
</form>
DEMO

Related

How to make this search bar responsive in Bootstrap?

I am looking for a way to make this search bar with its inputs and buttons responsive. However i got stuck with Bootstrap properties and when I shrink the window everything stacks very bad and I just can't figure out how to apply some better classes and props. Here's the codepen link: http://codepen.io/anon/pen/WGKOmB
Appreciate all advices
This is my html:
.row {
background-color: blue;
padding: 40px 30px;
}
.main {
background-color: grey;
width: 1202px;
height: 156px;
margin: 0 auto;
}
.formContainer {
width: 1140px;
height: 85px;
background-color: green;
margin: 0 auto;
position: relative;
top: 50%;
transform: translate(0, -50%);
}
button {
height: 37px;
width: 160px;
}
.choice {
background-color: lightgrey;
height: 37px;
}
div.form-group.checkbox {
width: 207px;
background-color: white;
padding: 5px 10px;
}
select.form-control {
width: 173px;
}
input.form-control.choice-input {
/*.choice input input*/
width: 360px;
height: 38px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<body>
<div class="container">
<div class="row">
<!-- row -->
<div class="col-md-8 col-sm-6" style="background-color: lightblue; height: 74px;">
<p>Lorem ipsum</p>
<div class="form-inline">
<div class="form-group checkbox">
<span><input type="checkbox" value="" checked></span>
<label>Lorem</label>
<span><input type="checkbox" value=""></span>
<label>Ipsum</label>
</div>
<div class="form-group">
<select class="form-control">
<option value="one">Lorem ipsum</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
</select>
</div>
<div class="form-group">
<input class="form-control choice-input" type="text" placeholder="Placeholder text">
</div>
</div>
<!-- end form-inline -->
</div>
<div class="col-md-4 col-sm-6" style="background-color: lightgreen; height: 74px;">
<p class="pull-right">Lorem ipsum</p>
<div class="btn-group">
<button class="btn btn-default" style="margin-right: 10px">Lorem ipsum lorem</button>
<button class="btn btn-default">Lorem lorem lorem</button>
</div>
</div>
</div>
</div>
<!-- end row -->
</div>
</body>
Word from the wise (not me), never use inline styling. Always put everything in CSS. Also, you set a specific height for both the blue box and the light green box. Therefore, even when the browser is narrower and would be in col-sm-* and col-xs-* territory, you still have a set height. You should give a class name, for example form-height and then in CSS write something like the following:
.form-height {
height: 150px; /* Or whatever height you find appropriate */
}
#media (min-width:768px) {
.form-height {
height: 74px;
}
}
What this would do is say that when the browser is narrower than 768px, i.e. when it is considered col-xs-* by bootstrap, it should have a certain height. When it is larger it will have a different height.
However, an ever better solution is to never even use the height property. The reason you are doing this is probably because you want a certain padding. Therefore, you can write the following CSS for the class:
.form-height {
padding: 10px 0px; /* Give the top and bottom 10px of padding and nothing to the right or left */
}
Try this code
<div class="container">
<form class="form-inline" style="padding: 20px 0;">
<div class="row">
<div class="col-sm-8 col-md-9">
<div class="form-group">
<label class="checkbox-inline"><input type="checkbox" value="">Option 1</label>
<label class="checkbox-inline"><input type="checkbox" value="">Option 2</label>
</div>
<div class="form-group">
<select class="form-control" id="sel1">
<option>Option 1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" id="usr" placeholder="Placeholder">
</div>
</div>
<div class="col-sm-4 col-md-3">
<button type="button" class="btn btn-default">Default</button>
<button type="button" class="btn btn-success">Success</button>
</div>
</div>
</form>
Demo here : https://jsfiddle.net/adb0br5e/1/

Bootstrap has-feedback icon not rendering properly when used with dropdownlist

I'm having a problem with bootstrap feedback. form-control-feedback when used with dropdownlist it doesn't align properly. Like I want it to show in the right corner after dropdownlist like it does in IE 11 (below screencast). It's kinda working in IE11 but not in all other browsers (Firefox,Chrome,Safari). I did little bit of googling and didn't find any sound workaround/solution and not sure whether its a bug or the way they intended.
Created a fiddle here http://jsfiddle.net/12qcwbbw/.
It seems this css rule .has-feedback .form-control{padding-right: 42.5px;}
works only in IE11.
Here are screen-casts;
This is what it is rendering on IE 11 and that's I want in other browsers.
Firefox
Google Chrome
Safari
Here's my html;
<div class="form-horizontal middle" >
<div class="col-xs-12 col-sm-12">
<div class="form-group">
<label class="col-xs-12 col-sm-3 control-label">Full Name</label>
<div class="col-xs-12 col-sm-9 has-feedback" >
<input type="text" class="form-control text-capitalize" name="FullName" id="txtFullName"
placeholder="Full Name" />
<span class="glyphicon glyphicon-remove text-danger form-control-feedback">
</span>
</div>
</div>
<div class="form-group ">
<label class="col-xs-12 col-sm-3 control-label">Gender</label>
<div class="col-xs-12 col-sm-9 has-feedback">
<select class="form-control">
<option>Male</option>
<option>Female</option>
<option>Other</option>
</select>
<i class="glyphicon glyphicon-remove text-danger form-control-feedback"></i>
</div>
</div>
</div>
Any workaround is appreciated!
There is not a cross browser solution for this since every browser renders the <select> element in a different way (and via CSS we have very limited control over it), but there is one alternative that could suit you.
I use CSS trick to make <select> elements be visually similar to all browsers. Its logic is really simple, it places an additional <div> that wraps the <select> that has an arrow image as background that mimics the arrows that a <select> has.
See the snippet below:
.select-style {
padding: 0;
margin: 0;
border: 1px solid #ccc;
border-radius: 3px;
overflow: hidden;
background: #fff url('data:image/gif;base64,R0lGODlhDwAUAIABAAAAAP///yH5BAEAAAEALAAAAAAPABQAAAIXjI+py+0Po5wH2HsXzmw//lHiSJZmUAAAOw==') no-repeat calc(100% - 10px) 50%;
}
.select-style select {
padding: 5px 8px;
width: 100%;
border: none;
box-shadow: none;
background-color: transparent;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: rgba(0, 0, 0, 0.6);
}
<div class="select-style">
<select class="form-control">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</div>
Using the above trick I made an adjustment for your scenario, which is a <select> element inside a .has-feedback element.
Change the background property for the .select-style` rule to change the position of the arrow icon.
.form-control + .form-control-feedback {
right: 12px;
}
.select-style {
padding: 0;
margin: 0;
border: 0 solid transparent;
border-radius: 4px;
overflow: hidden;
background: #fff url('data:image/gif;base64,R0lGODlhDwAUAIABAAAAAP///yH5BAEAAAEALAAAAAAPABQAAAIXjI+py+0Po5wH2HsXzmw//lHiSJZmUAAAOw==') no-repeat calc(100% - 30px) 50%;
}
.select-style select {
padding: 5px 8px;
width: 100%;
box-shadow: none;
background-color: transparent;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: rgba(0, 0, 0, 0.6);
}
.input-group > .select-style {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container">
<div class="form-group has-feedback has-error">
<label for="myselect">A label</label>
<div class="select-style">
<select id="myselect" class="form-control">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</div>
<span class="glyphicon form-control-feedback glyphicon-remove"></span>
</div>
<div class="form-group has-feedback has-error">
<label for="myselect2">A label</label>
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-tag"></span>
</div><div class="select-style">
<select id="myselect2" class="form-control">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</div>
</div>
<span class="glyphicon form-control-feedback glyphicon-remove"></span>
</div>
</div>

Issue with bootstrap aligning textbox next to button

I'm trying to build what I have attached in the image but unfortunately I cannot get it to sit right, so far this is my HTML (I'm new to bootstrap)
<div class="row">
<div class="container">
<div class="col-lg-3">
</div>
<div class="col-lg-6">
<p class="text-center">
<strong>Enter your email and get special information</strong>
</p>
#using (Html.BeginForm("Index", "Home", FormMethod.Post, new { #class = "form-inline col-lg-12" }))
{
<div class="input-group col-lg-9" style="margin-left: 3%">
<input type="text" class="form-control">
</div>
<div class="input-group col-lg-2">
<button class="btn btn-primary">Submit</button>
</div>
}
</div>
<div class="col-lg-3">
</div>
</div>
</div>
which is meant to look like this
but instead looks like this, Ideally I would like the button in a bit closer to the text box
but when I view it on a mobile screen I get this mess
Any help would be appreciated.
What about this fiddle:
http://jsfiddle.net/jwyr6Lwh/1/
.custom input.form-control {
border: 1px solid #848484;
-webkit-border-radius: 30px !important;
-moz-border-radius: 30px !important;
border-radius: 30px !important;
-moz-box-shadow: 2px 2px 1px #666;
-webkit-box-shadow: 2px 2px 1px #666;
box-shadow: 2px 2px 1px #666;
outline:0;
padding-left:10px;
padding-right:0px;
background-color: rgba(255,255,255,0.2);
}
.custom button {
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
The reason why it is displayed different on a mobile Browser is its responsiveness
class="col-lg-2"
means that on an large device it will be displayed in two collumns otherwise one by one under the other. If you don't intend this take class="col-sg-2".
How's this?
http://jsfiddle.net/ytn7z6tc/4/
<h3 id="btn-groups-single">Input + Button</h3>
<div class="input-group">
<input type="text" class="form-control " placeholder="email address">
<div class="input-group-btn">
<button type="button" class="btn btn-primary">
Submit
</button>
</div>
</div>

Divs do not align with each other

I have two divs in which they should be side by side. But once I add a padding to the input box in the left div, the right div shifts.
Any idea why?
The html and css is in the fiddle as below
<div style="text-align:center">
<div style="display:inline-block;width:350px;height:200px;background-color:rgba(43, 171, 145, 0.54);margin-right:30px">
<div style="text-align:left;height:30px;font-size:21px;padding:5px 0px 0px 10px;letter-spacing:7px;font-weight:bold;color:white;background-color:#2bab91"><u>NEW USER</u></div>
<div style="
/* text-align: left; */
padding-top: 20px;
width: 100%;
">
<input type="text" name="email" id="email" placeholder="(Email)" style="
width: 90%;
/* margin: 10px; */
height: 30px;
">
</div>
</div>
<div style="display:inline-block;width:350px;height:200px;background-color: rgba(193, 89, 97, 0.61);margin-left:30px">
<div style="text-align:left;height:30px;font-size:21px;padding:5px 0px 0px 10px;letter-spacing:7px;font-weight:bold;color:white;background-color:#c15961;"><u>EXISTING USER</u></div>
<div>
<input type="text" name="email" id="email" placeholder="(Email)">
</div>
</div>
</div>
http://jsfiddle.net/cAJgq/
Add vertical-align: top to the div styles
Your code aren't clean... Put your css into css file it's better to see clearly your html code
<div style="display:inline-block;width:350px;height:200px;background-color:rgba(43, 171, 145, 0.54);margin-right:30px">
<div style="text-align:left;height:30px;font-size:21px;padding:5px 0px 0px 10px;letter-spacing:7px;font-weight:bold;color:white;background-color:#2bab91"><u>EXISTING USER<</u></div>
<div style="padding-top: 20px;width: 100%;">
<input type="text" name="email" id="email" placeholder="(Email)" style="width: 90%;height: 30px;">
</div>
</div>
<div style="display:inline-block;width:350px;height:200px;background-color:red;margin-right:30px">
<div style="text-align:left;height:30px;font-size:21px;padding:5px 0px 0px 10px;letter-spacing:7px;font-weight:bold;color:white;background-color:#c15961"><u>NEW USER</u></div>
<input type="text" name="email" id="email" placeholder="(Email)" style="width: 90%;height: 30px;margin-top: 20px;">
</div>
http://jsfiddle.net/cAJgq/1/

Center a bootstrap registration form

I am trying to put a registration page in the center of my html page. I am using bootstrap, but a little confused how to center it after a couple of attempts.
Here is part of the html page I am working on. These html code goes to the <body>:
<div class="container registration-container">
<div class="row">
<div class="span6">
<form class="form-horizontal" id="registerHere" method='post' action=''>
<fieldset>
<legend>Registration</legend>
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="user_name" name="user_name" rel="popover" data-content="Enter your first and last name." data-original-title="Full Name">
</div>
</div>
<div class="control-group">
<label class="control-label">Email</label>
<div class="controls">
<input type="text" class="input-xlarge" id="user_email" name="user_email" rel="popover" data-content="What’s your email address?" data-original-title="Email">
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<button type="submit" class="btn btn-success" >Create My Account</button>
</div>
<div class="control-group success">
<!-- TODO -->
</div>
<div class="control-group error">
<!-- TODO -->
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
and this is the CSS I am trying to make this registration form looks good:
.registration-container{
position: relative;
background: rgba(240, 248, 255, 0.5);
width: 600px;
/*margin-top: 40%;*/
margin-bottom: auto;
}
legend{
text-align: center;
}
However, this form looks really ugly: the legend is not centered and not fit in the container, and everything looks strange.... Can someone please help me figure out how I can make this form be more professional and good styled?
Try This css this will work fine DEMO HERE
.registration-container{
position: relative;
background: rgba(240, 248, 255, 0.5);
width: 600px;
margin:0px auto;
}
try this with using property in css - margin: 0 auto;
.registration-container{
position: relative;
background: rgba(240, 248, 255, 0.5);
width: 600px;
/*margin-top: 40%;*/
margin-bottom: auto;
margin: 0 auto;
}
.registration-container{ margin: 0 auto; }
set your container Center of the screen :)