I'm working in Bootstrap 3.0 trying to make a Google-style search box that has a "Search Help" link after the Submit button.
My problem: when I go responsive I lose my offset margins and the button wraps to the next line.
<div class="row search">
<div class="col-md-8 col-md-offset-2">
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="">Enter search terms</label>
<input type="search" class="form-control" id="k" name="k" placeholder="Enter search terms">
<input id="cn" name="cn" type="hidden" value="false" />
</div>
<button type="submit" id="s" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
Search Help
</form>
</div>
</div>
C.f.: http://jsfiddle.net/redo1134/su3eq/2/
Everything's fine at >991px. But at 991 and below I lose the offset.
This is certainly related to the #media (min-width: 992px) media query in bootstrap.css, but I don't know how to keep the offset.
And to make matters worse: when the viewport is <768px the button and the link wrap to the next line.
Again, I'm drawn to bootstrap.css and the min-width: 768px media query, but I don't know how to keep the input, button, and text all together.
Thanks!
<div class="row search">
<div class="col-sm-8 col-sm-offset-2">
<form role="form">
<div class="input-group">
<input type="text" class="form-control input-sm">
<span class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</span>
Search Help
</div>
</form>
</div>
</div>
So, using Bootstrap will automatically make the spans break to show full widths at a certain breakpoint... it does that for responsiveness! I usually have to create my own styles when i would like something to act as I want it. Which is totally ok!
So, using inline styles just for a quick example, (you can turn them into proper styles for your stylesheet) you can do something like this with your search area... also updated the jsfiddle here
<!-- Global Search -->
<div class="row search">
<div class="col-md-8 col-md-offset-2">
<form class="form-inline" role="form">
<div class="form-group">
<div style="width:75%; float: left;">
<label class="sr-only" for="">Enter search terms</label>
<input type="search" class="form-control" id="k" name="k" placeholder="Enter search terms">
<input id="cn" name="cn" type="hidden" value="false" />
</div>
<div style="width: 25%; float: left; padding-left: 10px; box-sizing: border-box;">
<button type="submit" id="s" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
Search Help
</div>
<div class="clearfix"></div>
</div>
</form>
</div>
</div>
DEMO:http://jsbin.com/IKaKosoX/1/
EDIT: http://jsbin.com/IKaKosoX/1/edit?html,css,output
Remove the row col wrapping the form-inline and replace with this html:
<!-- Global Search -->
<form class="form-inline global-search" role="form">
<div class="form-group">
<label class="sr-only" for="">Enter search terms</label>
<input type="search" class="form-control" id="k" name="k" placeholder="Enter search terms">
<input id="cn" name="cn" type="hidden" value="false" />
</div>
<button type="submit" id="s" class="btn btn-default"><span class="glyphicon glyphicon-search"></span>
</button> Search Help
</form>
Remove previous custom css regarding the form and replace with:
/* center search */
.global-search {
text-align:center;
padding:10px;
}
.global-search * {
display:inline-block;
margin-bottom:0;
}
.global-search .form-control {
width:120px;
}
.global-search a {
display:block;
padding-top:10px;
}
#media (min-width:400px){
.global-search {
padding: 20px 0;
text-align:center;
}
.global-search .form-control {
width:300px;
}
}
Related
I am trying to use the adaptive placeholder CSS files on my page - it works perfectly for text and select inputs but when I try and use it with bootstraps input-group, it just doesn't work.
I've created a bootply to show what I mean bootply (the middle one is what I want it to look like)
This is the input-group that doesn't take the adaptive placeholder
<div class="row">
<div class="col-sm-6">
<div id="divSupplierInput2" class="input-group">
<input class="form-control" type="text" id="Text2" name="txtSupplier" value="" runat="server"
required="">
<label for="txtSupplier" placeholder="Supplier">
</label>
<span class="input-group-btn">
<button class="btn btn-secondary btn-sm" type="button">
...</button>
</span>
</div>
</div>
</div>
and this is an input where it does work
<div class="row">
<div class="col-sm-6">
<input id="Text1" type="text" class="form-control input-sm" runat="server" required="">
<label for="txtInvoiceNumber" placeholder="Invoice Number">
</label>
</div>
any help would be greatly appreciated, cheers
Use two divs, col-sm-5 adjust-span-left and col-sm-1 adjust-span-right.
You can also use col-sm-6 to col-sm-11 depending how long you want it to be.
Note I added adjust-span-left and adjust-span-right to the divs respectively, now use CSS to adjust it accordingly:
.adjust-span-right{
margin-left: -40px;
}
/* To make it responsive to smaller screens add this */
#media screen and (max-width: 780px) {
.adjust-span-left{
float:left;
width:90%;
overflow:hidden;
}
.adjust-span-right{
float:left;
width:10%;
overflow:hidden;
}
}
Then use this input
<div class="row">
<div class="col-sm-5 adjust-span-left">
<input id="txtInvoiceNumber" type="text" class="form-control input-sm" runat="server" required="">
<label for="txtInvoiceNumber" placeholder="Invoice Number">
</label>
</div>
<div class="col-sm-1 adjust-span-right">
<span class="input-group-btn">
<button class="btn btn-secondary btn-sm" type="button">
...
</button>
</span>
</div>
</div>
EDIT
I noticed the placeholder doesn't show on the smaller screen on focus, so you should also adjust the css for that in the responsive css style.
Something like:
#media screen and (max-width: 780px) {
input[type="text"][required]:focus + label[placeholder]:before,
input[type="text"][required]:valid + label[placeholder]:before {
/* Adjust the css accordingly */
-webkit-transform: translate(6px, -10px);
-ms-transform: translate(6px, -10px);
transform: translate(8px, -10px);
}
}
I want to be able to change the color of my login button (the button with the id= "loginbtn") when I hover over it, here is the html code:
<template >
<div class="login background" style="height:100%" >
<div style="color:#76323F">{{error}}</div>
<button id="signbtn" v-on:click="signup">Signup</button>
<button v-on:click="calendar">Calendar</button>
<div>
<div class="container col-lg-2 col-md-3 col-sm-4 col-xs-6 " style="margin-top:300px" >
<div class="input-group" style="margin-top:15px;">
<span class="input-group-addon" id="basic-addon1" style="background-color:#C09F80;border-color:#C09F80;opacity:.8;color:#76323F;" > <span class="glyphicon glyphicon-user"></span></span>
<input type="text" v-model="username" id="inputUsername" name="username" class="form-control col-lg-1" required autofocus placeholder="Username" aria-describedby="basic-addon1" style="opacity:.8;color:#76323F;font-weight:bold;">
</div>
<div class="input-group" style="margin-top:15px;">
<span class="input-group-addon" style="background-color:#C09F80;border-color:#C09F80;opacity:.8;color:#76323F;">
<i class="glyphicon glyphicon-lock"></i>
</span>
<input v-model="password" type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required autofocus style="opacity:.8;color:#76323F;font-weight:bold;"/>
</div>
<button id="loginbtn"v-on:click="submit" class="btn btn-lg btn-primary btn-block" style=".btn-primary{color:#C09F80;color:#C09F80;background-color:#76323F;border-color:#76323F;margin-top:20px;}" type="submit">Log in</button>
</div>
</div>
</div>
</template>
Use #loginbtn:hover { background-color:yellow; } (or whatever color you want) in your CSS.
And if that doesn't work because of the inline-styles you are using, move those inline styles out of the HTML code into the style sheet:
#loginbtn {
color: #C09F80;
background-color: #76323F;
border-color: #76323F;
margin-top: 20px;
}
#loginbtn:hover {
background-color: yellow;
}
<button id="loginbtn" v-on:click="submit" class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
If you only want to change the color of a single button (not a class of buttons) on hover, then you can add these attributes to the tags:
onMouseOver="this.style.color='#HexCodeForHoverColor'"
onMouseOut="this.style.color='#HexCodeForNormalBackground'"
You can also change color to backgroundColor -- not sure which one you'd want for what you're doing.
I can include CSS code to achieve the same thing if you want, but it's not really necessary if you only want to do this for one button.
A very similar question was asked here (Alex S. posted basically the same answer that I'm giving you).
Here's a demo. Obviously this is very basic in appearance.
<button onMouseOver="this.style.color='#00ffff'"
onMouseOut="this.style.color='#000000'">Test</button> <!-- Example of text color -->
<br>
<button onMouseOver="this.style.backgroundColor='#00ffff'"
onMouseOut="this.style.backgroundColor=''">Test</button> <!-- Example with background color -->
I am using Bootstrap 3 and I stuck on some form formatting.
E.g. I want to have 3 inline forms (each with label, text input and button) so they elements (label, text input, button) will be all perfectly matching (in column?)
If you look at this fiddle example you can see, that I almost achieved this by setting col-xs-6 to each form-group. But this makes too big space between input and submit button and also break too soon when resizing (and also when I try to align whole form set to left, everything is broken).
So is there any way to align this form elements instead of this?
<form class="form-inline">
<div class="form-group col-xs-6 text-right">
<label for="exampleInputName2">Results per page</label>
<input type="text" class="form-control" id="exampleInputName2" >
</div>
<div class="form-group col-xs-6">
<button type="submit" class="btn btn-default">Save</button>
</div>
</form>
<form class="form-inline">
<div class="form-group col-xs-6 text-right">
<label for="exampleInputName2">Keyword weight</label>
<input type="text" class="form-control" id="exampleInputName2" >
</div>
<div class="form-group col-xs-6">
<button type="submit" class="btn btn-default">Save</button>
</div>
</form>
<form class="form-inline">
<div class="form-group col-xs-6 text-right">
<label for="exampleInputName2">Results per page</label>
<input type="text" class="form-control" id="exampleInputName2" >
</div>
<div class="form-group col-xs-6">
<button type="submit" class="btn btn-default">Save</button>
</div>
</form>
This fiddle might help you. The entire layout can be put into container and each form can be given a margin and text-align css properties.
And I dont think there is a need for text-right and col-xs-6 to be included, instead you can use container to restrict the max-width and make it more responsive as shown in the fiddle.
Why not just give a width to your label? If you put the three elements into the same column then you can just make the label inline-block and give it a width (you may need to use the full page link in the snippet below to see this working)
.form-group > label {
display: inline-block;
vertical-align: middle;
width: 9em;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form class="form-inline">
<div class="form-group">
<label for="exampleInputName2">Results per page</label>
<input type="text" class="form-control" id="exampleInputName2">
<button type="submit" class="btn btn-default">Save</button>
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label for="exampleInputName2">Keyword weight</label>
<input type="text" class="form-control" id="exampleInputName2">
<button type="submit" class="btn btn-default">Save</button>
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label for="exampleInputName2">Results per page</label>
<input type="text" class="form-control" id="exampleInputName2">
<button type="submit" class="btn btn-default">Save</button>
</div>
</form>
http://codepen.io/anon/pen/WQQpyg
On a larger screen this isn't a problem, but when I reduce the browser window, the submit button moves underneath the text field.
This is causing a problem when I try to add a background color to the form with css. Does anyone know how to prevent this?
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div>
<form class="form-inline" role="form">
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</body>
Is this what you are looking for? https://jsfiddle.net/DIRTY_SMITH/2zkwxm97/
Added col-xs-4 to <div class="form-group col-xs-4">
You could use a horizontal form with column sizing.
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
.less-padding {
padding: 0 2px;
}
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4">
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-xs-6 less-padding">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<div class="col-xs-6 less-padding">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
Another solution was mentioned.
Here is how it goes:
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
#media (max-width: 768px) {
.form-group {
display: inline-block;
vertical-align: top;
}
}
<form class="form-inline" role="form">
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
class .form-inline only applies to forms within viewports that are at least 768px wide.
Check Bootstrap Doc here
To achieve what you want, you shouldn't use it. You could do something like this:
<div>
<form>
<div class="col-xs-6">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
Check this demo
Looks like it uses a media query like this:
#media (min-width: 768px)
And anything narrower than that, the form-group will change to display:block instead of inline-block. So maybe override that back to inline-block, but not sure that is best way to solve your issue. Maybe let it stack like that and find another way to fix the background color issue.
this is my HTML
<div id="formSuscription">
<form class="form-inline">
<div class="form-group">
<input type="text" class="form-control" placeholder="First Name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Last Name">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email">
</div>
<div class="form-group ">
<input type="button" class="form-control" value="Submit">
</div>
<div class="clearfix"></div>
<center>
<div class="form-group">
<label>
<input type="checkbox" class="form-control" value="Submit"> DON'T SHOW AGAIN
</label>
</div>
</center>
</form>
</div>
image: https://www.dropbox.com/s/mpa7rybvpngf19z/ohnails.png
I can't post image, due to my reputation
How can I make for the button is full width?
I tried with:
style: display: block; width: 100%;
and
class btn-block
and
<div class="form-group btn-group-justified">
<input class="form-control btn-block" type="button" style="display: block; width: 100%;" value="Submit">
</div>
but not working
You can override current css by adding id="submit" to the <button> tag and use css to change it's width.
Your example: http://jsfiddle.net/urahara/b64yf2jm/2/
You can do it statically :
edit this:
<input id="submit" type="button" class="form-control" value="Submit">
use css:
#submit{
width:180px; // <-- Your width value
}
Or use css dynamically via jQuery:
Here what we do is assigning the #submit button width with witdh of the other fields on the form. ( I added +8 to compensate padding or margins, just tweak it a bit )
jQuery:
$('#submit').css('width', $('.form-control').width()+8);
If you're using bootstrap shouldnt this work?
<button type="button" class="btn btn-primary btn-lg btn-block" >Block level button</button>
Creates a button the full width of its container.
http://getbootstrap.com/css/#buttons-sizes
Phil