Can anybody please advise/correct me how to align or arrange the button and input box side by side without grouping in bootstrap.
I had searched few examples in the internet which are only in grouping of elements.
jsfiddle: https://jsfiddle.net/erama035/p9dagmL3/3/
<div class="container">
<div class="row">
<div class="col-xs-5 col-sm-5 col-md-5">
<button class="btn btn-default col-sm-2 col-md-2">add</button>
<input class="form-control col-md-3 col-sm-2"/>
</div>
<div class="col-xs-7 col-sm-7 col-md-7">
<button class="btn btn-default col-md-2">remove</button>
<input class="form-control col-md-5"/>
</div>
</div>
</div>
The quick way would be, to simply use Flexbox for the parent <div>. This converts the child elements to flex items, which are arranged side by side by default.
.container > .row > div {
display: flex;
}
The proper way would be to use Bootstraps predefined classes for grouping.
.container>.row>div {
display: flex;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-xs-5 col-sm-5 col-md-5">
<button class="btn btn-default">add</button>
<input class="form-control" />
</div>
<div class="col-xs-7 col-sm-7 col-md-7">
<button class="btn btn-default">remove</button>
<input class="form-control" />
</div>
</div>
</div>
for the cross-browser you can simple use inline-block
.btn,.form-control{display: inline-block; width: auto;}
Related
I'm trying to use flexbox to align vertically a section.
So this is what I'm trying to align vertically:
HTML:
<!--Top Hero Section -->
<div class="d-flex hm-hero justify-content-center">
<div class="container">
<div class="row align-items-end">
<div class="col-12">
<h1 class="text-center">Fix Your Problem Today!</h1>
<p class="text-center">Start searching for a contractor or company around your area and get your problem fixed in a matter of hours!</p>
</div>
<!--Form Section -->
<div class="col-12">
<div class="form-group row justify-content-center">
<div class="col-12 col-md-6">
<input class="form-control" type="text" value="e.g. plumbing, carpentry" id="example-text-input">
</div>
<div class="col-12 col-md-4">
<input class="form-control" type="text" value="e.g. city name, postcode" id="example-text-input">
</div>
<div class="col-12 col-md-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
Regarding CSS, I've only applied this:
.hm-hero {
background: url("../img/main_pic.png") no-repeat;
background-size: fill;
min-height: 600px;
}
I can't figure out why flexbox is not working. I've tried two classes, align-content/items-center in whatever div possible and still can't get it to work.
So since I have that full width div with the background image, inside it is a container div, which I'm trying to get it to stay vertically. I really want to avoid putting a 200px margin top to this. Is this is a Bootstrap 4 bug?
I added the align-items-center class to the flex div parent and it worked. As long as you have a height on the .hm-hero the content will be centered. Hope this helps. JSFiddle
.hm-hero {
background: url("https://placehold.it/960x600") no-repeat;
background-size: fill;
min-height: 600px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<!--Top Hero Section -->
<div class="d-flex hm-hero justify-content-center align-items-center">
<div class="container">
<div class="row align-items-end">
<div class="col-12">
<h1 class="text-center">Fix Your Problem Today!</h1>
<p class="text-center">Start searching for a contractor or company around your area and get your problem fixed in a matter of hours!</p>
</div>
<!--Form Section -->
<div class="col-12">
<div class="form-group row justify-content-center">
<div class="col-12 col-md-6">
<input class="form-control" type="text" value="e.g. plumbing, carpentry" id="example-text-input">
</div>
<div class="col-12 col-md-4">
<input class="form-control" type="text" value="e.g. city name, postcode" id="example-text-input">
</div>
<div class="col-12 col-md-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
I'm using Bootstrap's grid system. I have 3 divs inside a "row", and inside each of those divs are nested controls.
When I horizontally decrease the browser size, the 2nd and 3rd div in the row are overlapping the 1st div. I want them to wrap, not overlap.
How can I achieve this?
Here is my code:
<!-- SEARCH CONTROLS -->
<div class="row">
<!-- Left side search boxes and search button -->
<div class="col-xs-5">
<div class="article" id="SAorPIList">
<select style="min-width: 215px; max-width: 300px;" class="col-xs-4 form-control" data-bind="value: selectedSAPIValue, options: saorpi, optionsText: 'Name', optionsValue: 'CmeTypeId', optionsCaption: 'Select SA or PI'"></select>
</div>
<div class="col-xs-5" style="padding-top: 20px;">
<select style="max-width: 300px;" class="specialties-class form-control" name="Name" id="SpecialtyId"></select>
</div>
<div class="col-xs-5" style="max-width: 150px; padding-top: 20px; padding-left: 175px;">
<button id="btnDropDownsSearch" class="btn btn-search collapsed" type="button">
<i class="icon-search"></i>
</button>
</div>
</div>
<!-- The world "OR" in the center of the page -->
<div class="col-xs-2" style=" padding-left: 75px; padding-top:50px;">
<strong style="display:inline;">OR</strong>
</div>
<!-- Right side search box -->
<div class="col-xs-5 pull-left" style="padding-bottom: 50px; min-width:400px;">
<span><strong style="text-align:left;">Activity Search</strong></span>
<div class="col-xs-4 input-group pull-left input-group-lg" style="padding-top:50px;">
<input id="txtFreeformSearch" class="form-control" type="search" style="min-width:175px;" />
<div class="input-group-btn">
<button id="btnFreeformSearch" class="btn btn-search collapsed" type="button">
<i class="icon-search"></i>
</button>
</div>
</div>
</div>
</div>
When you say, you nesting controls to div; Do you mean somethink like this?
.row > div {
background: lightgrey;
border: 1px solid grey;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">.col-md-4</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">.col-md-4</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">.col-md-4</div>
</div>
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">.col-md-4</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">.col-md-4</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">.col-md-4</div>
</div>
I solved this by defining min-width inside a good number of the tags.
This allowed the DIVs to wrap in PC, tablet, and mobile formats.
I would post the resulting HTML, but I think it would affect too few readers to make it worthwhile. I say this because there is a knockout control and select2 control within the HTML, and some of their UI properties are defined in javascript.
I'm using bootstrap. I want the text labels for the inputs to be aligned left of the text boxes edge, not above in the center as they are now.
Is this something that is done with bootstrap?
EDIT: Sorry the code snippet did not show my problem properly so i redid it in jsFiddle.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="text-center col-xs-12 ">
<div class="row">
</div>
<div class="row ">
<div class="col-xs-6 ">
<label for="companyInput">LABEL</label>
<br />
<input id="companyInput" type="text">
</div>
<div class="col-xs-6 ">
LABEL
<br />
<input id="cardInput" type="text" />
</div>
</div>
</div>
EDIT:
I updated your fiddle, here - https://jsfiddle.net/Lfmxt3kv/1/
If you have to have text-center on the parent container, then you'll need a wrapper div around your label and input element. Here are the changes I made to the fiddle:
<div class="text-center col-xs-12">
<div class="row ">
<div class="col-xs-6 ">
<!-- .input-wrapper needs to be wrapped around both the label and input element -->
<div class="input-wrapper">
<label for="companyInput">LABEL</label>
<input id="companyInput" type="text">
</div>
</div>
<div class="col-xs-6 ">
<div class="input-wrapper">
<label for="cardInput">LABEL</label>
<input id="cardInput" type="text" />
</div>
</div>
</div>
</div>
.input-wrapper {
display: inline-block;
text-align: left;
}
.input-wrapper label {
display: block;
}
Just adding text-left looks like it works.
<div class="col-sm-6 text-left">
LABEL ONE
<br />
<input id="companyInput" type="text" placeholder="Företag... (1-100)">
</div>
you are looking for Bootstrap forms
Individual form controls automatically receive some global styling.
All textual <input>, <textarea>, and <select> elements with
.form-control are set to width: 100%; by default. Wrap labels and
controls in .form-group for optimum spacing.
For what you want, you need to display:inline-block the .form-group and add class text-left to align left because .container has text-center
Snippet
.form-group {
display: inline-block
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="text-center container">
<div class="row">
<div class="col-xs-12">
<form class="form">
<div class="form-group text-left">
<label for="companyInput">Company</label>
<input class="form-control" id="companyInput" type="text" placeholder="Företag... (1-100)">
</div>
<div class="form-group text-left">
<label for="cardInput">Card</label>
<input class="form-control" id="cardInput" type="text" placeholder="Kort... (1-100)" />
</div>
</form>
</div>
</div>
</div>
for a quick fix you could add a class to the div..
<div class="textalign col-span-6">
then in css just do
.textalign { text-align: left; }
I'm using Bootstrap but with a non-collapse nav. I'm trying to have the search form placed in center of the col-md-6. I seem to have tried everything so far but nothing works but it still aligns left in the column. Anyone know how I can achieve that?
Here's my code:
<div class="navbar navbar-default">
<div class="container" style="margin-top:14px;">
<div class="row">
<div class="col-md-3">
<div class="navbar-header pull-left">
<a class="navbar-brand" href="#"><%= image_tag ("logo.png") %></a>
</div>
</div>
<div class="col-md-6">
<div class="navbar-header search">
<input type="text" id="search" class="form-control" placeholder="Search"></input>
</div>
</div>
<div class="col-md-3">
<div class="navbar-header pull-right">
<button type="button" class="btn btn-link" style="margin-top:7px;text-decoration:none;font-weight:bold;">Sign In</button>
</div>
</div>
</div>
</div>
</div>
Thanks alot in advance!
you can do it with following set of CSS rules:
<div class="row">
<div class="col-md-3">
<div class="navbar-header pull-left">
<a class="navbar-brand" href="#"><%= image_tag ("logo.png") %></a>
</div>
</div>
<div class="col-md-6" style="
text-align: center;
">
<div class="text-center navbar-header search" style="
display: inline-block;
float: none;
margin: 0 auto;
">
<input type="text" id="search" class="form-control" placeholder="Search">
</div>
</div>
<div class="col-md-3">
<div class="navbar-header pull-right">
<button type="button" class="btn btn-link" style="margin-top:7px;text-decoration:none;font-weight:bold;">Sign In</button>
</div>
</div>
</div>
Make alignment within central column div text-align: center; and display the block with float: none;.
Here is plunk with properties assigned CSS classes: http://plnkr.co/edit/Iu3rnVK5dLi7fiaSHBRj?p=preview
make it's position absolute, check in firebug if it is inheriting float from any other class. In bootstrap you have to beware of these things as well.
after doing this go for auto margin or try with top left positions by giving values in percentage values
If you can replace the div parent with a form element you could do it without additional styles:
<div class="col-md-6">
<form class="form-inline text-center">
<input id="search" class="form-control" type="text" placeholder="Search">
</form>
</div>
JSFiddle
Bootstrap alignment classes
I have the following code
html page(part of it)
<div class="container">
<div class="right-page col-md-9">
<div class="row">
<div class="category-item col-md-4">
<form action="/settings/category/2/" method="post" class="form-inline">
<div class="container">
<div class="row input-container">
<div class="form-group">
<div class="col-md-8">
<input class="form-control input-sm col-md-3" type="text" value="KONS ">
</div>
<div class="col-md-3">
<input class="form-control input-sm col-md-3 myColorPicker">
</div>
</div>
</div>
</div>
<div class="container">
<div class="row btn-container">
<button class="btn btn-default btn-sm edit-category">Cancel</button>
<button name="delete" class="btn btn-default btn-sm">Delete</button><input type="submit" name="submit" class="btn btn-default btn-sm" value="Save">
</div>
</div>
</form>
</div>
</div>
</div>
and the css (part of it)
.diagnosis-phrase,
.treatment-phrase,
.category-item{
padding-bottom: 1em;
padding-top: 0.5em;
border: 1px solid black;
margin-bottom: 0.5em;
}
.diagnosis-phrase input[type="text"],
.treatment-phrase input[type="text"],
.category-item input[type="text"]{
margin-bottom:0.5em;
}
.category-item p{
padding-left: 0.5em;
padding-bottom:0.3em;
border-radius:0.5em;
width:50%;
}
The bootply for it. The part of html is the right column of a two column webpage. As you can see inside the div with black border I have two input boxes(For some reason the second appears outside the div with borders but in my working code appears correctly. Maybe because of me providing part of page.). My problem is that the first one is not aligned with the Cancel button. How can I do that using bootstrap classes?
if you use the following styles
.form-group .col-md-8:first-child {padding-left:0;}
It should fix your problem
Or if you just change the col-md-8 class on your div to col-md-pull-8 it should also achieve the same thing