I am writing some code that hides and displays a different form depending on whether the user wants to login or register. However for some reason my form isn't displaying in the html in between the <form class="login-inputs"> , its doesn't even appear in the HTML doc. Can anyone see why?
<div class="col-md-3">
<button type="button" id="login" class="btn btn-default login hidden">Login</button>
<button type="button" id="register" class="btn btn-default register">Register</button>
<form class="login-inputs hidden">
<h3>Login</h3>
<div class="form-group">
<label for="inputEmail">Email</label>
<input type="email" class="form-control" id="inputEmail" placeholder="Email">
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
Remove the hidden class.
media screen element "on" and "off" class:
/* For Phone device */
.visible-xs{
display: block !important;
}
.hidden-xs{
display: none !important;
}
/* For Phone device End */
#media (min-width: 768px){
.visible-sm{
display: block !important;
}
.hidden-sm{
display: none !important;
}
}
#media (min-width: 992px){
.visible-md{
display: block !important;
}
.hidden-md{
display: none !important;
}
}
#media (min-width: 1200px){
.visible-lg{
display: block !important;
}
.hidden-lg{
display: none !important;
}
}
Just use the class. This CSS already have bootstrap 3.
Related
At max-width: 380px; the text should disappear and only the search icon should appear. However, the text doesn't disappear.
#media screen and(max-width: 380px) {
nav div form span .text {
display: none;
}
}
<div class="search-container">
<form>
<input type="text" placeholder="Search..." name="search" />
<button type="submit">
<i class="fas fa-search"></i><span class="text">Search</span>
</button>
</form>
</div>
As #AHaworth said in the comments, spaces select siblings, whether direct or not. So if you have a span inside a div, or a span inside a p inside a div, div span would select that. That's not what you want. You want span.text. That selects spans with class text.
#media only screen and (max-width: 380px) {
span.text {
display: none;
}
}
<nav>
<div class="search-container">
<form>
<input type="text" placeholder="Search..." name="search">
<button type="submit"><i class="fas fa-search"></i><span class="text">Search</span></button>
</form>
</div>
</nav>
<script src="https://use.fontawesome.com/6ba8be0f46.js"></script>
JSFiddle -- Resize the window here.
I'm using the following markup with Bootstrap 3.
<div class="row" style="margin-bottom: 12px">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
According to all the examples I could find, this should put everything inline. However, for me, the labels appear over the textboxes rather than to the side of them.
I tried not enclosing the markup with <div class="row">. I also tried using <input type="text"> instead of <input type="date"> but none of that made any difference. I've triple checked the markup. Can anyone see what I'm doing wrong?
If I force the containers to be wider, then it appears closer to what I expect. But none of the examples I've seen do this. And I'd prefer to not specify a fixed width.
This is due to the version of Bootstrap 3 that you are using. The form-control class changed to width: auto within inline forms in v3.1.0. So versions v3.0.0, v3.0.1, v3.0.2 and v3.0.3 should all display the problem you are seeing. After the v3.1.0 release it should no longer be a problem.
From the release notes:
#11836: Along with the form validation update, we reset some key form and icon styles:
All .form-controls within inline forms are set to width: auto; to prevent stacking of .form-label within a .form-group.
Removes all select.form-control settings since those are now inherited by the above change
Removes the width: 1em; from the Glyphicons because it was virtually impossible to override.
Any version between 3.1.0 and the current 3.3.6 should work as you expect.
That being said, if you cannot upgrade you can still implement this on your own. See 3rd Snippet.
Example of the issue with v3.0.0
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
Example of expected behavior with v3.1.0
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
Example using v3.0.0 with fix:
#media (min-width: 768px) {
.form-inline .form-control {
width: auto;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
All current form-inline css just in case:
#media (min-width: 768px) {
.form-inline .form-group {
display: inline-block;
margin-bottom: 0;
vertical-align: middle
}
.form-inline .form-control {
display: inline-block;
width: auto;
vertical-align: middle
}
.form-inline .form-control-static {
display: inline-block
}
.form-inline .input-group {
display: inline-table;
vertical-align: middle
}
.form-inline .input-group .form-control,
.form-inline .input-group .input-group-addon,
.form-inline .input-group .input-group-btn {
width: auto
}
.form-inline .input-group>.form-control {
width: 100%
}
.form-inline .control-label {
margin-bottom: 0;
vertical-align: middle
}
.form-inline .checkbox,
.form-inline .radio {
display: inline-block;
margin-top: 0;
margin-bottom: 0;
vertical-align: middle
}
.form-inline .checkbox label,
.form-inline .radio label {
padding-left: 0
}
.form-inline .checkbox input[type=checkbox],
.form-inline .radio input[type=radio] {
position: relative;
margin-left: 0
}
.form-inline .has-feedback .form-control-feedback {
top: 0
}
}
your code is fine ,, but note that
Controls only appear inline in viewports that are at least 768px wide to account for narrow viewports on mobile devices.
here is my screenshot for your code
I've run into this issue in the past when I was using mvc to add my textboxes. I solved this issue by overriding the form-group class or by using an inline style on the div to set display: flex; This would force it into one line.
<div class="form-group" style="display:flex;">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
I am using bootstrap 3 and am looking to have the following.
Tablet sized devices and above:
| Input-text-area | button flush against the right edge of the text area |
Mobile sized devices:
| Input-text-area |
| button here |
This is quite easy - using this : http://getbootstrap.com/components/#input-groups-buttons Great!
However, I only want this layout when on devices >=768 pixels width i.e anything greater than col-xs-12. When on a mobile I want the Button element to drop down onto the next line - center aligned. This is my existing code:
<form id="signup-form" class="new_invitation" action="/invitations" accept-charset="UTF-8" method="post">
<div style="margin-bottom:0px;" class="col-sm-4 col-sm-offset-3 input-position">
<input class="form-control full-width cinput" placeholder="Enter email address... " id="InputEmail" type="text" name="invitation[recipient_email]">
</div>
<div class="col-xs-12 col-sm-2 input-position fixit" style="margin-bottom:0px;">
<input type="submit" name="commit" value="JOIN IN" class="btn btn-default position-mobile cbigbtn" id="gabetabtn">
</div>
</form>
This allows me to have my button on the right of my input text field on devices > XS and on its own centered col-xs-12 on mobile devices.
What CSS magic can I do to have this input text field become an input group which only groups flush to the input box on devices > 768 pixels wide.
I'd try something like this, nesting bootstrap columns:
<div class="row">
<div class="col-lg-12">
<div class="input-group">
<div class="col-xs-12 col-sm-9" style="padding:0px;">
<input class="form-control full-width cinput" placeholder="Enter email address... " id="InputEmail" type="text" name="invitation[recipient_email]">
</div>
<div class="col-xs-12 col-sm-3" style="padding:0px;">
<span class="input-group-btn" style="margin:0 auto;">
<input type="submit" name="commit" value="JOIN IN" class="btn btn-default position-mobile cbigbtn" id="gabetabtn" style="width:100%;">
</span>
</div>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
Your other option would be to look at media queries and add those to your css document.
http://www.w3schools.com/cssref/css3_pr_mediaquery.asp
These are all the rules that you need to change in order to acheive the desired behavior and so the button and input remain aligned under 768px.
body {
padding-top: 50px;
}
#media (max-width: 767px) {
.new_invitation .input-group .form-control,
.new_invitation .input-group-btn {
display: block;
border-radius: 4px;
width: 100%;
}
.new_invitation .input-group-btn .btn {
display: block;
border-radius: 4px;
width: 100%;
margin-top: 40px;
}
.new_invitation .input-group-btn > .btn + .btn {
margin-left: 0px;
}
.new_invitation .input-group-btn:first-child > .btn {
margin-right: 0px;
}
.new_invitation .input-group-btn:last-child > .btn {
margin-left: 0px;
}
.new_invitation .input-group {
width: 100%;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-sm-12">
<form id="signup-form" class="new_invitation" action="/invitations" accept-charset="UTF-8" method="post">
<div class="input-group">
<input class="form-control full-width cinput" placeholder="Enter email address..." id="InputEmail" type="text" name="invitation[recipient_email]">
<span class="input-group-btn">
<input type="submit" name="commit" value="JOIN IN" class="btn btn-default position-mobile cbigbtn" id="gabetabtn">
</span>
</div>
</form>
</div>
</div>
</div>
I have this form-inline Bootstrap form in my ASP.NET MVC View:
<div class="home-search">
#using (Html.BeginForm("index", "search", FormMethod.Get, new { #class="form-inline", #role = "search"}))
{
<div class="form-group">
<input type="text" class="form-control" name="q" placeholder="enter a title name..." required>
<select name="t" class="form-control selectpicker" data-width="auto">
<option value="all">All</option>
<option value="movies">Movies</option>
</select>
</div>
<button type="submit" class="form-control btn btn-primary"><i class="fa fa-search fa-lg"></i></button>
}
</div>
...and this accompanying CSS:
.home-search form {
text-align: center;
padding: 20px;
background-color: rgba(1, 1, 1, 0.5);
}
.home-search input, .home-search select, .home-search button {
border-radius: 0;
}
When minimizing the browser, the three controls of the form stack vertically, which is how Bootstrap works. How can I however keep the elements of the form in one line and just have them automatically resize to fit the screen? Are #media queries the way to go here or am I missing something trivial?
DEMO: https://jsbin.com/mayoru
Yes, media query and a custom class. The min-width: 350px is because that specific form looks good inline until about 320px. When you add the gutter -- 15px on either side of the .container (30px) it's 350px. Since the smallest device is 240px, under that is full width or it starts looking bad. The max-width:767px is so as to not over-write the default styling that kicks in at 768px min-width.
HTML:
<div class="container">
<form class="form-inline custom-form">
<div class="form-group">
<input type="text" class="form-control" name="q" placeholder="enter a title name..." required>
<select name="t" class="form-control selectpicker" data-width="auto">
<option value="all">All</option>
<option value="movies">Movies</option>
</select>
</div>
<button type="submit" class="btn btn-primary form-control"><i class="fa fa-search fa-lg"></i></button>
</div>
</div>
CSS
.custom-form .form-control {
margin-bottom: 5px
}
.custom-form .btn .fa {
line-height: 0px
}
#media (min-width:350px) and (max-width:767px) {
.custom-form .form-control {
display: inline-block;
width: auto;
margin: 0;
}
.custom-form .form-group {
display: inline-block;
width: auto;
margin-bottom: 0;
vertical-align: middle;
}
}
I made a login box using Bootstrap 3.0.3. On the second line, the password input box’s and check box”s (labelled Auth) heights are different. On mobile, the difference is even more noticeable.
How can I make their heights match?
Bootply
<form name="fhead" method="post" onsubmit="return fhead_submit(this);" autocomplete="off" role="form" class="form-inline">
<div id="outlogin_box" name="outlogin_box">
<input type="hidden" name="url" value="<?=$outlogin_url?>">
<input type="text" class="form-control input-sm" name="mb_id" maxlength="20" itemname="id" placeholder="login id">
<div class="input-group"><!-- needs height alignment -->
<input type="password" class="form-control input-sm" name="mb_password" id="outlogin_mb_password" maxlength="20" itemname="password" placeholder="password">
<span class="input-group-addon">
<div class="checkbox">
<label>
<input type="checkbox" name="auto_login" title="Remember me" value="1" onclick="if (this.checked) { if (confirm('자동로그인을 사용하시면 다음부터 회원아이디와 패스워드를 입력하실 필요가 없습니다.\n\n\공공장소에서는 개인정보가 유출될 수 있으니 사용을 자제하여 주십시오.\n\n자동로그인을 사용하시겠습니까?')) { this.checked = true; } else { this.checked = false; } }">
Auto
</label>
</div>
</span>
</div>
<div class="input-group">
<button type="submit" class="btn btn-success btn-sm btn-group-justified" >Login</button>
</div>
<div class="input-group">
<div class="btn-group btn-group-justified">
<a class="btn btn-default btn-sm" title="Register" href="<?=$g4[bbs_path]?>/register.php">Register</a>
<a class="btn btn-default btn-sm" title="회원 id, password 찾기" href="javascript:win_password_lost();">아이디찾기</a>
</div>
</div>
</div>
</form>
Change
<input class="form-control input-sm" name="mb_password" ...
to
<input class="form-control" name="mb_password" ...
http://www.bootply.com/98872
You have modified the height of the input by adding a class "input-sm".
Try this very simple:
input[type=checkbox], input[type=radio] {
vertical-align: middle;
position: relative;
bottom: 1px;
}
input[type=radio] {
bottom: 2px;
}
You can set fixed width and height values for HTML textboxes/checkboxes in CSS by doing the following...
input[type="text"] {
width: 10%;
height:3%;
}
input[type="password"] {
width: 10%;
height:3%;
}
input[type="checkbox"] {
height:2%;
}
You can also set them using px instead of percentages.
Hopefully setting a fixed height and width should resolve your conflicting size problems.
Try overriding bootstrap CSS with this:
.input-group-addon .checkbox {
margin: 8px 5px 0 !important;
}
.input-group-addon {
padding:0 !important;
}
change your css of checkbox class display which is display : inline-block to display: inline and the try it
.form-inline .radio,.form-inline .checkbox{display:inline-block;padding-left:0;margin-top:0;margin-bottom:0}
to
.form-inline .radio,.form-inline .checkbox{display:inline;padding-left:0;margin-top:0;margin-bottom:0}
in bootstrap.min.css