Aligning elements in html using bootstrap classes - html

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

Related

Bootstrap button padding makes it appear like the button is going past the container border

Why does the "Subscribe now!" button go outside the container in the picture below and how can I make it so that the right edge lines up with the rest of the page? (column 12 in the bootstrap grid)
I have tried box-sizing: border-box but it had no effect.
My HTML code:
.container-fluid {
padding: 0;
}
.carousel-inner .carousel-item h1 {
font-weight: bold;
font-size: 300%;
/*-webkit-text-stroke:1px black;*/
font-family: 'Open Sans', sans-serif;
/*text-align:right;*/
}
.carousel-inner .carousel-item img {
filter: brightness(50%);
}
#paddingrow {
padding: 25px;
}
#paddingrowLarge {
padding: 100px;
}
#accordionRightalign {
float: right;
}
#mycard {
float: right;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row" id="paddingrow"></div>
<div class="row">
<div class="col-sm-12">
<h1 style="text-align:center">SUBSCRIBE TO OUR NEWSLETTER</h1>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<form>
<div class="row">
<div class="col">
<input type="text" class="form-control" placeholder="Enter your email">
</div>
<button class="btn btn-primary" style="box-sizing: border-box" type="submit">Subscribe now!</button>
</div>
</form>
</div>
</div>
</div>
</div>
Bootstrap rows have margin-right: -15px; margin-left: -15px; that's why the right edge doesn't lined up. Try to add mx-0 = margin-left:0 and margin-right: 0, a bootstrap class. In your nested row form.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row" id="paddingrow"></div>
<div class="row">
<div class="col-sm-12">
<h1 style="text-align:center">SUBSCRIBE TO OUR NEWSLETTER</h1>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<form>
<div class="row mx-0">
<div class="col pl-0 pr-3">
<input type="text" class="form-control" placeholder="Enter your email">
</div>
<button class="btn btn-primary" style="box-sizing: border-box" type="submit">Subscribe now!</button>
</div>
</form>
</div>
</div>
</div>
</div>
Make sure col in the container with margin and padding to zero.
Put your image into container with the width not greather than 100%.
I noticed my button wasn't in the column div, so I made two column div's, one size 10 and one size 2, put input in the first, put the button in the second, and it seems to work now.
Here is the fixed code:
<div class="container">
<div class="row" id="paddingrow"></div>
<div class="row">
<div class="col-sm-12">
<h1 style="text-align:center">SUBSCRIBE TO OUR NEWSLETTER</h1>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<form class="form">
<div class="row">
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="Enter your email">
</div>
<div class="col-sm-2">
<button class="btn btn-primary w-100" type="submit">Subscribe now!</button>
</div>
</div>
</form>
</div>
</div>
</div>

Bootstrap CSS Mobile Resize Issue

I am running into an issue using Bootstrap when re-sizing the page to a mobile size. The input form is shifting to inline and the glyphicon I am using is not staying in the same position once the window is resized. I have included 2 pictures below on how it looks before and after resizing the window.
HTML code for input section:
<div class="col-sm-4" id="end">
<div class="row">
<div class="col-sm-6" id="start">
<span class="top">Date and Time</span>
<div class="input-group">
<div class = "input-group-addon"><span id="icon" class="glyphicon glyphicon-time"></span></div>
<input type="text" class="col-xs-4" id="date">
<input type="text" class="col-xs-4" id="time">
</div>
<button type="button" class="btn btn-info btn-sm" id="submit" onclick="getData()">Search</button>
</div>
<div class="col-sm-6" id="start">
</div>
</div>
</div>
CSS for the date and time ID's:
#date {
max-width: 100px;
min-width: 100px;
font-size: 12px;
}
#time {
max-width: 100px;
min-width: 100px;
margin-bottom: 0px;
font-size: 12px;
}
Normal sized look
Mobile sized look
If you sizing your #date and #time both to min-width: 100px and max-width: 100px as well, your div's wont be bigger or smaller then 100px.
Maybe you should use three declarations like:
width: 150px, min-width: 100px and max-width: 200px;
Another way would be the percentage sizing or #media screen and (...)
w3schools has a really good docu to figured it out an learn how to handle with all the diffrent ways of sizing.
It's not the most beautiful solution, but you can try to force the "input" to be wide as it can be with class="col-lg-12".
Like this:
<div class="col-sm-4" id="end">
<div class="row">
<div class="col-sm-6" id="start">
<span class="top">Date and Time</span>
<div class="input-group">
<div class = "input-group-addon"><span id="icon" class="glyphicon glyphicon-time" ></span></div>
<input type="text" class="col-lg-12" id="date">
<input type="text" class="col-lg-12" id="time">
</div>
<button type="button" class="btn btn-info btn-sm" id="submit" onclick="getData()">Search</button>
</div>
<div class="col-sm-6" id="start">
</div>
</div>

Bootstrap Button and input box , side by side

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;}

Vertical align input and button without bootstrap

I wonder what's the best way to vertically align an input field and a button without Bootstrap.
Here's how it looks right know:
Some code:
<!doctype html>
<title>Postnummer</title>
<div class="container-fluid">
<div class="divider"></div>
<div class="row">
<div class="col-md-12">
<form class="navbar-form">
<div class="input-group">
<input style="height:50px; color: black; border-radius: 0px;" type="number" id="searchZipCode"class="form-control" placeholder="Sök postnummer">
<div class="input-group-btn">
<a id="submitBtn">
<button style="height:50px; border-radius: 0px" type="button" click="submitZipCode()" class="btn btn-default"><i class="fa fa-search fa-2x"></i></button>
</a>
</div>
</div>
</form>
</div>
</div>
</div>
Fiddle: https://jsfiddle.net/5mxzu4m5/
I want the the icon on the right side of the input field. Really grateful for all the answers! :)
Use the below code (just added display:inline-block & vertical-align:top on textbox and .input-group-btn, increased button height)
<div class="container-fluid">
<div class="divider"></div>
<div class="row">
<div class="col-md-12">
<form class="navbar-form">
<div class="input-group" style="text-align: center">
<input style="height:50px; color: black; border-radius: 0px; display: inline-block; vertical-align:top; margin-right:-4px; " type="number" id="searchZipCode"class="form-control" placeholder="Sök postnummer">
<div class="input-group-btn" style="display: inline-block; vertical-align:top">
<a id="submitBtn">
<button style="height:56px; border-radius: 0px;" type="button" click="submitZipCode()" class="btn btn-default"><i class="fa fa-search fa-2x"></i></button>
</a>
</div>
</div>
</form>
</div>
</div>
</div>
Simple and Sleek Solution:
Replace src="..." with your link
HTML
<div>
<input type="text" id="text1">
<br>
<img src="http://findicons.com/files/icons/1264/clearblack/128/find.png" height="50px" width="50px">
</div>
CSS
img{
float:right;
}
div{
width:90px;
}
Try this CSS
.input-group{
display:table;
}
.form-control,.input-group-btn
{
display:table-cell;
vertical-align:middle;
}
Link For Reference
style your button accordingly
hope this helps..

Set background color for div

I have a grid created using bootstrap 3 divs. The collection of divs has 1 button, followed by a radio button, followed by another button. I would like to highlight these with a background color. The background color should not break in between and should be like a single row.
Here is the fiddle with my attempt - https://jsfiddle.net/oxfqvtds/2/
In this, there is some empty space on the bottom right side of the div. As a result, the highlighting is not consistent.
.highlight {
background-color: yellow;
}
.input-field {
height: 20px;
padding: 2px 10px;
}
.custom-label {
line-height: 3.3em !important;
}
.label-size {
font-size: 10px;
line-height: 2.1em;
}
label {
padding-right: 0px;
}
<head>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div class="container-fluid">
<form class="form-horizontal">
<div class="col-md-12">...</div>
<div class="col-md-12">...</div>
<div class="col-md-10 highlight">
<div class="form-group">
<div class="col-md-3">
<button class="btn btn-primary btn-xs" type="button">Test</button>
</div>
<label class="col-md-2 label-size">Options</label>
<div class="radio" class="col-md-7 label-size">
<label class="label-size">
<input type="radio" name="opt" value="opt" >opt</label>
</div>
</div>
</div>
<div class="col-md-2 highlight form-group">
<button class="btn btn-info btn-xs pull-right">Test2</button>
</div>
</form>
</div>
</body>
Also, would like to have the buttons/radio buttons centered in the highlighted area. Right now they seem to be towards the top of the highlighted area.
With bootstrap you columns should be in a row. Apply the background color to the row once you have it in place. Remove form-groups, and you had class listed twice around the radio element so it wasn't reading the bootstrap column class.
.highlight.row {
background-color: yellow;
margin:0;
}
.input-field {
height: 20px;
padding: 2px 10px;
}
.custom-label {
line-height: 3.3em !important;
}
.label-size {
font-size: 10px;
line-height: 2.1em;
}
label {
padding-right: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row highlight">
<form class="form-horizontal">
<div class="col-md-10 ">
<div class="">
<div class="col-md-3">
<button class="btn btn-primary btn-xs" type="button">Test</button>
</div>
<div class="col-md-2">
<label class="label-size">Options</label>
</div>
<div class="col-md-5 label-size">
<label class="label-size">
<input type="radio" name="opt" value="opt" >opt</label>
</div>
</div>
</div>
<div class="col-md-2">
<button class="btn btn-info btn-xs pull-right">Test2</button>
</div>
</form>
</div>
</div>
remove the margin-bottom from this particular form-group