Im trying to center the header and input field with bootstrap. I cant get the input field to center with the header. If anyone has a better way of doing this let me know.
<div class="container">
<div class="row">
<div class="col-md-6">
<h1 class="display-4 text-center">Weight Converter</h1>
<form>
<div class="form-group">
<input
id="lbsInput"
type="number"
class="form-control form-control-lg"
placeholder="Enter Weight..."
/>
</div>
</form>
<div id="output">
<div class="card">
<div class="card-block">
<h4>Grams:</h4>
<div id="gramsOutput"></div>
</div>
</div>
</div>
</div>
</div>
</div>
you have incomplete HTML and no CSS. But based on what you have, a simple margin: auto; in CSS should center the element for you.
If you want more control you should look into flexbox. post more code and you'll get more help.
EDIT: thanks for the code: this works to center the input. I just verified it. let me know if you need any more help. cheers
<div class="container">
<div class="row">
<div class="col-md-6">
<h1 class="display-4 text-center">Weight Converter</h1>
<form>
<div class="form-group" id="centerParent">
<input
id="lbsInput"
type="number"
class="form-control form-control-lg"
placeholder="Enter Weight..."
/>
</div>
</form>
<div id="output">
<div class="card">
<div class="card-block">
<h4>Grams:</h4>
<div id="gramsOutput"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
#centerParent {
display: flex;
flex-direction: row;
justify-content: center;
}
</style>
Related
I am still new to bootstrap and also html/css at that.
What I am trying to do is to align the inputs on the same row,
I've looked up advice and have put it in a container but the
two inputs are still showing on different rows.
html
<div class="container">
<div class="row">
<div class="col-md">
<h3>Startdate From:</h3>
<input name="stardatefromDTP" type="date" />
</div>
<div class="col-md">
<h3>Startdate To:</h3>
<input name="stardatetoDTP" type="date" />
</div>
</div>
</div>
Can anyone help me out with this?
This will work, though you'll need to mess around with the column sizes to get the formatting exactly how you would like:
<div class="container">
<div class="row">
<div class="col-md">
<div class="row">
<div class="col">
<h3>Startdate From:</h3>
</div>
<div class="col">
<input name="stardatefromDTP" type="date" />
</div>
</div>
</div>
<div class="col-md">
<div class="row">
<div class="col">
<h3>Startdate To:</h3>
</div>
<div class="col">
<input name="stardatetoDTP" type="date" />
</div>
</div>
</div>
</div>
Alternatively you can use the label element instead:
<label class="h3" for="startdate">Startdate From:</label>
<input type="date" class="form-control" id="startdate" />
I believe h3 is a block element so the col-md will stretch to accommodate. Try col-md-6 to force it to be smaller. The col classes refer to columns and bootstrap divides the screen into 12, so col-md-6 should make room for 2 inputs in 1 row.
I am trying to implement a single page application where I want divs to display one below the other. But on resizing the viewport to various screen sizes, the positioning is getting overlapped and leaving extra spaces in between. I have codepen example to explain the problem in a better way.
https://codepen.io/SaloniDesai/pen/zPBZJr
How to make the divs appear same for every screen size ?Do i need to shuffle the way I have created the layout of the page ?
<div id="headliner" class="jumbotron text-center">
<h1>SearchGIFY app</h1>
<p>search for any GIF you want!</p>
</div>
<div id="search">
<form>
<input type="search" ng-model="vm.search.gif" value="" placeholder="type what you're looking for" />
<button type="submit" class="btn btn-primary" ng-click="vm.performSearch()">Search</button>
</form>
</div>
<div class="row">
<div class="card">
<img ng-repeat="g in vm.giphies" ng-src="{{g.images.original.url}}" height="{{g.images.fixed_height}}" title="{{g.title}}">
</div>
</div>
<div class="jumbotron text-center" id="trendingBar">
<h3>Trending gifs</h3>
<div class="row">
<div class="thumbnail">
<img ng-repeat="trending in vm.trendingGifs" ng-src="{{trending.images.original.url}}" height="{{trending.images.fixed_height.height}}" title="{{trending.title}}">
</div>
</div>
</div>
First, your bootstrap structure isn't good, there isn't container, neither rows or col.
Try this one:
<div class="container-fluid">
<div class="row">
<div id="headliner col-md-12" class="jumbotron text-center">
<h1>SearchGIFY app</h1>
<p>search for any GIF you want!</p>
</div>
</div>
<div class="row">
<div id="search">
<div class="col-md-12">
<form class="form-inline text-center col-md-6 col-md-offset-3">
<div class="form-group">
<input class="form-control" type="search" ng-model="vm.search.gif" value=""
placeholder="type what you're looking for"/>
</div>
<button type="submit" class="btn btn-primary" ng-click="vm.performSearch()">Search</button>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="card">
<img ng-repeat="g in vm.giphies" ng-src="{{g.images.original.url}}" height="{{g.images.fixed_height}}"
title="{{g.title}}">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="jumbotron text-center" id="trendingBar">
<h3>Trending gifs</h3>
<div class="thumbnail">
<img ng-repeat="trending in vm.trendingGifs" ng-src="{{trending.images.original.url}}"
height="{{trending.images.fixed_height.height}}" title="{{trending.title}}">
</div>
</div>
</div>
</div>
Second, you add a lot of absolute class with % height and width. You don't have to do that if you're using bootstrap, all the responsive stuff is handled by the bootstrap grid with col classes. Take a quick look at the grid bootstrap documentation : https://getbootstrap.com/docs/3.3/css/#grid
Here's the codepen working responsively with some modification : https://codepen.io/anon/pen/MOemgw ;)
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. 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; }
After various attempts with pull-right, float style and row-fluid, I decided to ask here:
What I try to do is simply to have a Map appear to the right of a set of rows.
Here is how it looks right now:
Which is not too far from what I want, but the name row plus any following rows should appear below each other.
Here is how my HTML looks:
<div class="panel-body">
<div class="row-fluid">
<div class="col-lg-10 pull-right">
<google-map id="my-map" bounds="map.bounds" events="map.events"
center="map.center" zoom="map.zoom" draggable="true"
control="map.control"> <marker ng-if="positionMarker"
coords="positionMarker" icon="positionMarker.icon"> </marker> </google-map>
</div>
<div class="col-lg-4">
<div class="input-group">
<span class="input-group-addon">Number</span> <input type="number"
class="form-control" placeholder="Nr">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<span class="input-group-addon">Name</span> <input type="text"
class="form-control" placeholder="Name">
</div>
</div>
</div>
</div>
I bet this is a typical scenario but I have failed to find an example.
Other attempts that makes name appear below number, moves it below the map.
Is it perhaps possible to avoid having the map take up vertical space in the Bootstrap grid system?
You should use a 2-col layout :
Left column for your inputs
Right column for your Google Map
Plus, remember to put your .input-group inside a .form-group to get paddings/margins set to Bootstrap default values.
Here's a working example (click on Full page for a better view):
body {
padding-top: 25px;
}
.map {
width: 100%;
height: 150px;
background: tomato;
}
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Panel heading</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-6">
<form role="form">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Number</span> <input type="number"
class="form-control" placeholder="Nr">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Name</span> <input type="text"
class="form-control" placeholder="Name">
</div>
</div>
</form>
</div>
<div class="col-xs-6">
<div class="map"></div>
</div>
</div>
</div>
</div>
</div>