I have this setup here:
As you can see the Left Option Button is big and that's how I need all the buttons to be. They need to be lined up next to each other as I use the Bootstrap grid system with 3x4 columns. The button is currently the size it is (and doesn't take up all available horizontal space) because I applied this line to my HTML:
style="width: 400%; height: 500%;"
It was simply to provide a visual aid for what I'm aiming to do. I'm fairly new with bootstrap so learning how to style it is a bit tricky for me. Below is my html. Do I need CSS to achieve what I want above? If so, do I need to hardcode how "tall" I want the buttons to be or can I use some sort of relative method to do so, so that I won't run into problems if the site is viewed on a mobile phone?
I also need to place a text in the button that scales up properly but I'm sure that's doable once the buttons are scaled correctly?
<div class="categories-container">
<div class="container">
<div class="row">
<div class="col-md-4">
<form role="button">
<div class="input-group">
<input type="button" class="btn btn-primary btn-lg" value="Option" name="category-gameplay-btn" id="category-gameplay-btn">
</div>
</form>
</div>
<div class="col-md-4">
<form role="button">
<div class="input-group">
<input type="button" class="btn btn-primary btn-lg" value="Option" name="category-editor-btn" id="category-editor-btn">
</div>
</form>
</div>
<div class="col-md-4">
<form role="button">
<div class="input-group">
<input type="button" class="btn btn-primary btn-lg" value="Option" name="category-editor-btn" id="category-editor-btn">
</div>
</form>
</div>
</div>
</div>
</div>
Here are two example of what I think you're trying to do.
1) Uses a Justified button group instead of the grid and uses media queries to adjust to the viewport size.
2) Uses the grid like in your example and then just uses media queries to adjust to the viewport size.
See example Snippet.
.btn.btn-bg {
height: 300px;
font-size: 60px;
}
#media (max-width: 767px) {
.btn.btn-bg {
height: 150px;
font-size: 30px;
}
}
#media (max-width: 480px) {
.btn.btn-bg {
height: 75px;
font-size: 22px;
}
}
#media (max-width: 360px) {
.btn.btn-bg {
height: 35px;
font-size: 15px;
}
}
/*Second Sample*/
.btn.btn-bg2 {
height: 300px;
font-size: 60px;
}
#media (max-width: 767px) {
.btn.btn-bg2 {
height: 60px;
font-size: 30px;
}
}
#media (max-width: 480px) {
.btn.btn-bg2 {
height: 45px;
font-size: 20px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="well">
<form role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
</div>
</div>
<div class="categories-container">
<div class="container">
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default btn-bg">Left</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default btn-bg">Middle</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default btn-bg">Right</button>
</div>
</div>
</div>
</div>
<hr>
<div class="container">
<div class="well">
<form role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
</div>
</div>
<div class="categories-container">
<div class="container">
<div class="row ">
<div class="col-sm-4">
<input type="button" class="btn btn-primary btn-lg btn-block btn-bg2" value="Option" name="category-gameplay-btn" id="category-gameplay-btn">
</div>
<div class="col-sm-4">
<input type="button" class="btn btn-primary btn-lg btn-block btn-bg2" value="Option" name="category-editor-btn" id="category-editor-btn">
</div>
<div class="col-sm-4">
<input type="button" class="btn btn-primary btn-lg btn-block btn-bg2" value="Option" name="category-editor-btn" id="category-editor-btn">
</div>
</div>
</div>
</div>
To get the width you need to set the button and the div it is in to have 100% width:
.btn, .input-group {
width: 100%;
}
For the height you can use css and scale the height with the viewport size using vw in css or, if you're willing, you could use jquery to make the height directly proportional to the width:
$(document).ready(btnHeight);
$(window).on('resize', btnHeight);
function btnHeight() {
var width = $('.btn').width();
$('.btn').css('height', width*0.8);
};
To scale the font size you could use vw or just use media queries.
http://www.bootply.com/atAkVSnhQc
Related
I'm trying to add two buttons on both sides of the search field, so I did this:
<div id="fixtures-filter">
<div class="input-group-btn">
<div class="input-group-prepend"><button type="button" class="btn btn-light" aria-expanded="false" id="countries-btn">Filters</button></div>
<div class="app-search">
<div class="input-group"><input type="text" class="form-control" placeholder="Search..."><span class="mdi mdi-magnify"></span>
<div class="input-group-append"><button type="button" class="btn btn-light" data-toggle="modal" data-target="#fixtures-filter-modal">Search</button> </div>
</div>
</div>
</div>
</div>
the result is really weird:
This is a JSFIDDLE.
Use an append and prepend. Adjust the borders as needed to make the search icon appear inside the input.
<div class="input-group">
<span class="input-group-prepend">
<button class="btn btn-primary" type="button">
Filters
</button>
</span>
<span class="input-group-prepend">
<div class="input-group-text bg-transparent border-right-0"><i class="fa fa-search"></i></div>
</span>
<input class="form-control py-2 border-left-0 border" type="search" value="..." id="example-search-input">
<span class="input-group-append">
<button class="btn btn-outline-secondary border-left-0 border" type="button">
Search
</button>
</span>
</div>
https://www.codeply.com/go/KJcZWvSsR9
If you are trying to get the filter to be on the same line, you have to move it inside the same parent div as the other inputs:
<div id="fixtures-filter">
<div class="input-group-btn">
<div class="app-search">
<div class="input-group">
<div class="input-group-prepend"><button type="button" class="btn btn-primary" aria-expanded="false" id="countries-btn"><span class="mdi mdi-magnify"></span></button></div>
<input type="text" class="form-control padleft" placeholder="Search...">
<span class="mdi mdi-magnify search-mg"></span>
<div class="input-group-append">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#fixtures-filter-modal">Search</button>
</div>
</div>
</div>
</div>
</div>
CSS added to get the magnifying glass icon to appear in the search input:
#fixtures-filter {
position: relative;
}
span.search-mg {
position: absolute;
z-index: 10;
font-size: 20px;
line-height: 38px;
left: 45px;
}
.padleft {
padding-left: 30px;
}
fiddle: http://jsfiddle.net/5xkbn3o0/
I use the solution provide by #dippas here
Inline form make input text full width and responsive
My new request is how to put multiple input text and fill all the space.
I am aware that we can not use width with inline form like mention in bootstrap website
Requires custom widths Inputs, selects, and textareas are 100% wide by
default in Bootstrap. To use the inline form, you'll have to set a
width on the form controls used within. The default width of 100% as
all form elements gets when they got the class form-control didn't
apply if you use the form-inline class on your form.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
.form-inline {
display: flex;
padding:5px !important;
}
.flex {
flex: 1;
display: flex !important
}
.flex input {
flex: 1 !important ;
padding-right:15px !important;
}
.form-inline .form-group {
padding-right:15px !important;
}
</style>
<div class="panel panel-primary">
<div class="panel-heading">
<h4><b>Search Options</b></h4>
</div>
<div class="panel-body">
<form class="form-inline">
<div class="form-group">
<div class="btn-group">
<button type="button"
class="btn btn-default dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>Account ID <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Account ID</li>
<li>Company Name</li>
<li>Account Type</li>
<li>Marketplaces</li>
</ul>
</div>
</div>
<div class="row" style="display: block">
<div class="form-group flex" >
<input class="form-control" type="text" value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-danger"> Fermer </button>
</div>
<div class="form-group flex">
<input class="form-control" type="text" value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-danger"> Fermer </button>
</div>
<div class="form-group flex">
<input class="form-control" type="text" value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-danger"> Fermer </button>
</div>
</div>
</form>
</div>
</div>
you need to add display:flex to .row, because now the parent of .flex is .row
/* !important only for this snippet */
.form-inline {
display: flex;
padding: 5px !important;
}
.row {
display: flex;
flex-wrap: wrap;
flex: 1
}
.flex {
flex: 0 100%;
display: flex !important
}
.flex input {
flex: 1 !important;
padding-right: 15px !important;
}
.form-inline .form-group {
padding-right: 15px !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="panel panel-primary">
<div class="panel-heading">
<h4><b>Search Options</b></h4>
</div>
<div class="panel-body">
<form class="form-inline">
<div class="form-group">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Account ID <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Account ID</li>
<li>Company Name</li>
<li>Account Type</li>
<li>Marketplaces</li>
</ul>
</div>
</div>
<div class="row">
<div class="form-group flex">
<input class="form-control" type="text" value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-danger"> Fermer </button>
</div>
<div class="form-group flex">
<input class="form-control" type="text" value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-danger"> Fermer </button>
</div>
<div class="form-group flex">
<input class="form-control" type="text" value="" id="filter_id" placeholder="Put your filter here">
<button type="button" class="btn btn-danger"> Fermer </button>
</div>
</div>
</form>
</div>
</div>
I want to add some space between 2 buttons. This form is created using bootstrap. Tried a number of tricks but couldn't get what I want. The same page is accessed via mobile too.
Here is my code along with screenshot:
<div class="input-group">
<span class="input-group-btn">
<input type="button" style="border-radius: 10px;" id="button1" class="btn btn-primary btn-lg btn-block" value="My Provider"/>
</span>
<span class="input-group-btn" >
<input type="button" style="border-radius: 10px;" id="button2" class="btn btn-primary btn-lg btn-block" value="Any Provider"/>
</span>
</div>
The problem is Bootstrap's btn-block class.
A block level button spans the entire width of the parent element.
http://www.w3schools.com/bootstrap/bootstrap_buttons.asp
Try removing that class from each of your buttons, setting the width of the input-group class to 100% and adding margin after the first button.
input[type=button] {
border-radius: 10px;
width: 47%;
}
.input-group {
display: inline-block;
width: 100%;
}
input[type=button]:first-child {
margin-right: 20px;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="input-group">
<input type="button" id="button1" class="btn btn-primary btn-lg" value="My Provider"/>
<input type="button" id="button2" class="btn btn-primary btn-lg" value="Any Provider"/>
</div>
You can add paddings to input-group-btn blocks.
.container {
margin-top: 50px;
}
.input-group-btn-left {
padding-right: 30px;
}
.input-group-btn-right {
padding-left: 30px;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<div class="container">
<div class="input-group">
<span class="input-group-btn input-group-btn-left">
<input type="button" id="button1" class="btn btn-primary btn-lg btn-block" value="My Provider" style="border-radius: 10px;">
</span>
<span class="input-group-btn input-group-btn-right">
<input type="button" id="button2" class="btn btn-primary btn-lg btn-block" value="Any Provider" style="border-radius: 10px;">
</span>
</div>
</div>
i want to move my "Submit form" a little bit down. i have tried a lot but the problem doesn't seems to go away.....
<div class="form-group">
<button type="button" class="btn btn-success col-md-4 col-md-offset-4 pull-down">Submit form</button>
</div>
Button is too near with the other line:
Use this
HTML
<div class="form-group" style="margin-top:20px;">
<button type="button" class="btn btn-success col-md-4 col-md-offset-4 pull-down">Submit form</button>
</div>
Use a media query (form-group will add space itself on smaller viewports) and a custom class on the form-group div to add margin to the top.
See Snippet.
#media (min-width: 768px) {
.lg-group {
margin-top: 25px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<hr>
<hr>
<div class="container">
<div class="form-group">
<input class="form-control" />
</div>
<div class="form-group">
<div class="input-group"> <span class="input-group-addon" id="basic-addon1">#</span>
<input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1">
</div>
</div>
<div class="form-group lg-group">
<div class="col-sm-4 col-sm-offset-4">
<button type="button" class="btn btn-success btn-block">Submit form</button>
</div>
</div>
</div>
Add an extra class to your button to avoid overriding bootstrap CSS and then simply add something like so
your HTML become :
<div class="form-group">
<button type="button" class="btn btn-success col-md-4 col-md-offset-4 pull-down mybutton">Submit form</button>
</div>
suggested CSS
.mybutton {
margin-top: 30px;
}
LIVE DEMO
What would be the best way to have a logo and form in the center of the page while being responsive?
Currently, I have something like
<div class="container">
<img src="logo.jpg" class="logo img-responsive center-block">
<form role="form">
<div class="form-group center-block">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search">
<span class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</form>
</div>
then I edited it slightly in the css;
.form-group { margin-top: 15px; width: 50% }
.logo { width: 300px; }
However, now the logo will not resize like the input box does.
now you'll need to change the col size for each media that you need xs sm md and lg but this would do the trick that you are looking for.
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<img src="http://placehold.it/250x300" class="logo img-responsive center-block" />
<form role="form">
<div class="form-group center-block">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" /> <span class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</form>
</div>
</div>
</div>
i assumed that you need a fluid container, the offset col would take , and for farther reading check this
Demo
A fluid container does the trick, but a fixed container should be able to keep it center without taking all the screen span which is annoying on medium+ resolutions.
Also, media queries should keep .container within a specific width for responsiveness' sake.
<div class="container">
<div class="row">
<div class="col-md-12">
<img src="http://placehold.it/250x300" class="logo img-responsive center-block" />
<form role="form">
<div class="form-group center-block">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" /> <span class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</form>
</div>
</div>
</div>