align content with bootstrap strange behaviour - html

I am working with vuejs and bootstrap so I am calling different components and attach them inside my HTML dynamically.
My problem is I don't get the desired effect, at the moment I have this:
the section title gives too much space related to the input and I don't know why the section is a different component and the data at the bottom gets loaded dynamically depending on the select box choice.
the rows columns and cells are a horizontal form but it occupies all the width of my row, I want the inputs to be lower and the button at centre a little bigger, I can't set it like I want if I try for example to increase button it will not be at centre anymore.
So here is my code:
<template>
<div class="container">
<div class="row">
<div>
<h1 class="text-center">Document Creation</h1>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
</div>
</div>
</div>
<div class="col-md-8 margin-above">
<div class="form-group">
<label class="control-label col-sm-2">Section</label>
<div class="col-sm-6">
<select class="form-control" v-model="currentView">
<option v-for="(item,index) in sections" :value="item.key">{{item.text}}</option>
</select>
</div>
</div>
</div>
</div>
<!-- Here we load the diferent sections based on the selection choice -->
<component v-bind:is="currentView">
<!-- component changes when vm.currentView changes! -->
</component>
</div>
</template>
inside the component the other component that has the rows and cells and columns get loaded like this:
<template>
<div class="row">
<div class="col-md-offset-4">
<form class="form-inline margin-above">
<div class="form-group">
<label for="rows">rows:</label>
<input type="number" min="1" value="1" class="form-control" id="rows">
</div>
<div class="form-group">
<label for="columns">columns:</label>
<input type="number" min="1" value="1" class="form-control" id="cols">
</div>
<div class="form-group">
<label for="cells">cells:</label>
<input type="number" min="1" value="1" class="form-control" id="cols">
</div>
<div class="text-center">
<button type="submit" class="btn btn-success margin-above2">Add Table</button>
</div>
</form>
</div>
</div>
</template>
Please, I need some help trying to display it correctly. Thanks.

Currently, you're using too many <div>s for the layout. We can strip a few out to not only simplify the design, but also make it alot easier to read. We also want to leverage the use of bootstrap's Horizontal Forms
.
Your first snippet would look like this:
<template>
<div class="container">
<h1 class="text-center">Document Creation</h1>
<div class="col-md-12 form-horizontal margin-above">
<div class="form-group">
<label class="control-label col-sm-1">Section</label>
<div class="col-sm-11">
<select class="form-control" v-model="currentView">
<option v-for="(item,index) in sections" :value="item.key">{{item.text}}</option>
</select>
</div>
</div>
</div>
<!-- Here we load the diferent sections based on the selection choice -->
<component v-bind:is="currentView">
<!-- component changes when vm.currentView changes! -->
</component>
</div>
<template>
And your second would look like this:
<template>
<form class="margin-above">
<div class="form-group col-sm-4">
<label for="rows" class="control-label">rows:</label>
<input type="number" min="1" value="1" class="form-control" id="rows">
</div>
<div class="form-group col-sm-4">
<label for="columns" class="control-label">columns:</label>
<input type="number" min="1" value="1" class="form-control" id="cols">
</div>
<div class="form-group col-sm-4">
<label for="cells" class="control-label">cells:</label>
<input type="number" min="1" value="1" class="form-control" id="cols">
</div>
<div class="col-xs-12 margin-above text-center">
<button type="submit" class="btn btn-success margin-above2">Add Table</button>
</div>
</form>
</template>
I've made a fiddle here to show the snippets together.

You are going to run into problems trying to use Boostrap and Vue together, but that is a question for another day.
By carefully mimicking the examples here, you can get a more nicely-spaced section layout.
<div class="margin-above form-group row">
<label class="col-form-label col-sm-1">
Section
</label>
<div class="col-sm-6">
<select class="form-control" v-model="currentView">
<option v-for="(item,index) in sections" :value="item.key">{{item.text}}</option>
</select>
</div>
</div>
Making the button bigger is just a matter of adding one of the sizing classes. It does not cause a problem for centering:
<div class="text-center margin-above2">
<button type="submit" class="btn btn-success btn-lg">Add Table</button>
</div>
Putting some extra space in is some ordinary CSS. Here it is as a snippet. Depending on your display size, you may need different col-*-# classes.
new Vue({
el: '#app',
data: {
currentView: 'doesNotMatter',
sections: [{
label: 'one'
}, {
label: 'two'
}]
},
components: {
someComponent: {}
}
});
.margin-above2 {
margin-top: 2rem;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>
<div id="app" class="container">
<div class="row">
<div>
<h1 class="text-center">Document Creation</h1>
</div>
<div class="margin-above form-group row">
<label class="col-form-label col-sm-1">
Section
</label>
<div class="col-sm-6">
<select class="form-control" v-model="currentView">
<option v-for="(item,index) in sections" :value="item.key">{{item.text}}</option>
</select>
</div>
</div>
</div>
<!-- Here we load the diferent sections based on the selection choice -->
<some-component inline-template>
<div class="row">
<form class="form-inline">
<div class="form-group">
<label for="rows">rows:</label>
<input type="number" min="1" value="1" class="form-control" id="rows">
</div>
<div class="form-group">
<label for="columns">columns:</label>
<input type="number" min="1" value="1" class="form-control" id="cols">
</div>
<div class="form-group">
<label for="cells">cells:</label>
<input type="number" min="1" value="1" class="form-control" id="cells">
</div>
<div class="text-center margin-above2">
<button type="submit" class="btn btn-success btn-lg">Add Table</button>
</div>
</form>
</div>
</some-component>
</div>

Related

Need help on CSS inline alignment in Servicenow

I am new and learning front end.
I created a simple form contains 4 fields. how to align all these in line equally divided?
below is my code written on HTML along with the output what i see:
<div>
<form>
<div class="form-inline">
<div class="col-sm-6">
<label>Name: </label>
<input type="text" class="form-control" >
</div>
<div class="col-sm-6">
<label>Email: </label>
<input type="text" class="form-control" >
</div>
<br>
<br>
<div class="col-sm-6">
<label>Phone #: </label>
<input type="text" class="form-control" >
</div>
<div class="col-sm-6">
<label>Education Qualificiation: </label>
<input type="text" class="form-control" >
</div>
</div>
</form>
</div>
Output above code
You can do something like this:
fiddle to validate
.lblClass {
width: 50%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div>
<form>
<div class="form-inline d-flex">
<div class="col-sm-6 d-flex">
<label class="lblClass">Name: </label>
<input type="text" class="form-control">
</div>
<div class="col-sm-6 d-flex">
<label class="lblClass">Email: </label>
<input type="text" class="form-control">
</div>
<br>
<br>
<div class="col-sm-6 d-flex">
<label class="lblClass">Phone #: </label>
<input type="text" class="form-control">
</div>
<div class="col-sm-6 d-flex">
<label class="lblClass">Education Qualificiation: </label>
<input type="text" class="form-control">
</div>
</div>
</form>
</div>
There are lots of ways to align element. But here you are uses bootstrap and bootstrap have predefined classes for align element. You want to align elements in the form so bootstrap have Form-group, form control class for your all. Problems
Visit this link for more info
https://getbootstrap.com/docs/4.3/components/forms/

Bootstrap 4 - can't horizontally align a vertical form

I have the following form code:
<div id="site" class="container-fluid">
<div class="row">
<div class="my-4 offset-3 col-6 justify-content-center align-items-center">
<form action="/some/path" method="post">
<div class="form-group row">
<label for="username" class="col-2 col-form-label">Username</label>
<div class="col-4">
<input type="text" class="form-control" id="username" name="_username" required="required" autocomplete="username" />
</div>
</div>
<div class="form-group row">
<label for="password" class="col-2 col-form-label">Password</label>
<div class="col-4">
<input type="password" class="form-control" id="password" name="_password" required="required" autocomplete="current-password" />
</div>
</div>
<div class="form-group row">
<div class="col-2"></div>
<div class="col-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me" class="form-check-label">Remember me</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-6">
<button class="btn btn-burnt-orange" type="submit" id="_submit" name="_submit">Log in</button>
</div>
</div>
</form>
</div>
</div>
</div>
I want the form to be centered on the page, but instead, it's still further to the left than center as shown by this screenshot:
I thought my math was correct: Bootstrap uses a 12-column grid, so by using a 3-column offset, and a 6-column content area, I'd have essentially two 3-column gutters on each side. And by specifying the form rows to add up to 6-columns (2-column labels and 4-column inputs), the form would fill the 6-column content area, thereby automatically centering itself. But I'm obviously wrong.
So, what can I do to actually center this thing? And to make it 6 columns wide (because, judging by the screenshot, it isn't)?
The form is horizontally centered, but it's only half the width of it's parent. The issue is...
"And by specifying the form rows to add up to 6-columns (2-column
labels and 4-column inputs), the form would fill the 6-column content
area, thereby automatically centering itself"
Since 6 is half of 12, the form col-6 (2+4) is only going to fill half the parent col-6. If you want a narrower form in the middle use col-4 (1/3 width), and then something that adds to 12 for the labels and form input (eg. 3+9). OFC you could also use 4/8, 6/6, etc...
<div class="container-fluid">
<div class="row">
<div class="my-4 offset-4 col-4 justify-content-center align-items-center">
<form action="/some/path" method="post">
<div class="form-group row">
<label for="username" class="col-3 col-form-label">Username</label>
<div class="col-9">
<input type="text" class="form-control" id="username" name="_username" required="required" autocomplete="username">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-3 col-form-label">Password</label>
<div class="col-9">
<input type="password" class="form-control" id="password" name="_password" required="required" autocomplete="current-password">
</div>
</div>
<div class="form-group row">
<div class="col-3"></div>
<div class="col-9">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="remember_me" name="_remember_me" value="on">
<label for="remember_me" class="form-check-label">Remember me</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<button class="btn btn-burnt-orange" type="submit" id="_submit" name="_submit">Log in</button>
</div>
</div>
</form>
</div>
</div>
</div>
https://www.codeply.com/go/b4FE5qflxS
Related: Center the content inside a column in Bootstrap 4
You can accomplish this by using col-6 and justify-content-center. All you have to do is setup the elements, rows and columns with bootstrap.
Here is an example of centering the form group:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="site" class="container-fluid">
<div class="row justify-content-center">
<div class="col-6" style="background: #eee;">
<!-- formgroup start -->
<form>
<div action="/some/path" class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" placeholder="Enter username" name="_username" required="required" autocomplete="username" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" name="_password" required="required" autocomplete="current-password" />
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="remember_me" name="_remember_me" value="on" />
<label class="form-check-label" for="remember_me">Remember me</label>
</div>
<button type="submit" class="btn btn-primary" id="_submit" name="_submit">Submit</button>
</form>
<!-- formgroup end -->
</div>
</div>
</div>
Reference these pages on the Bootstrap 4 documentation
https://getbootstrap.com/docs/4.1/layout/grid/
https://getbootstrap.com/docs/4.1/components/forms/

How to add inline components inside a default Bootstrap 3 form?

I need to add an "inline" control inside a form-group class in TB3 but I am not able to do it. This is what I've tried without success meaning it does not work as I want:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-12">
<form id="new_question" method="POST" class="form-vertical" role="form">
<div class="form-group">
<label for="field_type_id">Select a Question Type</label>
<select class="form-control" id="field_type_id" name="field_type_id">
<option value="">Select One</option>
</select>
</div>
<div class="form-group">
<label for="field_name">Question Text</label>
<textarea class="form-control" name="field_name" id="field_name" rows="4"></textarea>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Option 1</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
<div class="checkbox">
<label>
<input type="checkbox" value=""> Checkbox
</label>
</div>
</form>
</div>
</div>
</div>
From the snippet/example above I would expect:
Keep the first and second element as it's: the label on the top then the HTML element
Make an inline version of the third element: first have the option, then the HTML, then the checkbox which mean everything in one line.
The idea is to have something like:
Label1 Input1 Checkbox1
Label2 Input2 Checkbox2
Does any knows how to achieve this? It has to be done only in a certain lines so the rest of the form behaves as the form basic example.
For example, you might want to use columns from the Grid system:
<form role="form">
<div class="form-group col-sm-2">
<label>Some label</label>
</div>
<div class="form-group col-sm-2">
<label>E-mail</label>
<input type="email" class="form-control">
</div>
<div class="form-group col-sm-2">
<div class="checkbox">
<label>
<input type="checkbox" class="form-check-input"> Check me out
</label>
</div>
</div>
</form>
The above example creates 3 equal-width columns using predefined grid class col-sm-2
Create a
Give it a class of Flex
Set the width
<div class='flex'>
<div> item1</div>
<div> item2</div>
<div> item3</div>
</div>
<div class='flex'>
<div> item4</div>
<div> item5</div>
<div> item6</div>
</div>
.flex {
display:flex;
justify-content:center;
align-items: center;
}
https://codepen.io/Codokk101/pen/goQNOW

Vertical Form Inside Jumbotron

I am trying to do something like this. http://www.lolnexus.com/
I am trying to build the search module but cannot get my form to vertically stack. How can I go about this better using bootstrap. I am trying to build the part where it says enter summoner name and under that the radio buttons but I cant seem to figure how to get that alignment at least the vertical alignment. Custom styling can come later.
<div class="container">
<div class="row">
<div class="jumbotron text-center">
<form role="form" method="post">
<div class="col-md-6 form-group">
<input type="search" size="100" id="mySearch" placeholder="Search for Summoner Name">
<button type="button" class="btn btn-primary">Search</button>
</div>
<div class="col-md-6 form-group">
<label> NA</label>
<input type="radio" name="region" id="NA" value="NA" />
<label>EUW</label>
<input type="radio" name="region" id="EUW" value="EUW">
</div>
</form>
</div>
</div>
</div>
Did you try changing column width of form-groups to 12 columns?
<div class="container">
<div class="row">
<div class="jumbotron text-center">
<form role="form" method="post">
<div class="col-md-12 form-group">
<input type="search" size="100" id="mySearch" placeholder="Search for Summoner Name">
<button type="button" class="btn btn-primary">Search</button>
</div>
<div class="col-md-12 form-group">
<label> NA</label>
<input type="radio" name="region" id="NA" value="NA" />
<label>EUW</label>
<input type="radio" name="region" id="EUW" value="EUW">
</div>
</form>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="jumbotron">
<form class="form" role="form" method="post">
<div class="form-group">
<input type="search" class="form-control" size="100" id="mySearch" placeholder="Search for Summoner Name" />
</div>
<div class="form-group form-inline">
<div class="radio">
<label>
<input type="radio" name="region" id="NA" value="NA" />
NA
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="region" id="EUW" value="EUW">
EUW
</label>
</div>
</div>
<div class="form-group">
<button type="button" class="btn btn-primary">Search</button>
</div>
</form>
</div>
</div>
</div>
There are lots of different classes you can use. I recommend you study bootstrap better to understand it. My example is for a form that spans the width of the container. Below the search input are the radio buttons. Below them is the search button. Bootstrap, by default is a 12 column layout. You were specifying 6 columns in width which placed the elements next to one another instead of vertically. You can just add the form-inline class to the form-group divs to make those particular elements inline. The form-control class makes the control span the width of its container.
Not sure what you trying to do, but if you are trying to have input and the button in one row and the radio buttons underneath, just put both form-groups in a separate row as well and also add col-md-offset-3 so it will be in the middle.

Using Bootstrap, how do I position labels to the left of the input box when there are multiple inputs on the same row

I have a row with three inputs, two of the inputs have labels to their left. What is happening is the label is being displayed on top of the input box rather than to the side, like so:
Here is what I am trying to achieve:
<div class="row">
<div data-bind="foreach: items" class="padding-left-lg">
<div class="col-sm-4">
<input type="text" data-bind="value: Description,valueUpdate: 'afterkeydown'" class="form-control"/>
</div>
<div class="col-sm-4">
<label class="control-label">
Quantity: <input type="text" data-bind="value: Quantity,valueUpdate: 'afterkeydown'" class="form-control"/>
</label>
</div>
<div class="col-sm-1">
<input type="text" data-bind="value: Units,valueUpdate: 'afterkeydown'" class="form-control"/>
</div>
</div>
</div>
I would try something like this:
<form class="row form-horizontal">
<div class="col-sm-5">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
</div>
<div class="col-sm-2">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</div>
</form>
Here is the fiddle I made https://jsfiddle.net/g3e8yjyg/.
What is different from the default Bootstrap example? You treat your form as a row or a set of rows, and each formgroup becomes a cell, where you will only vary the value of the size. This will allow you to put many fields in a single row.
<form class="row">
<!--Columns -->
<div class="col-lg-*">
<!--Your form group in here -->
<div class="form-group">
<!--The elements of you formgroup treated as col divs-->
<label for="inputPassword3" class="col-lg-*">Your label</label>
<div class="col-lg-*">
<input name="my-input">
</div>
</div>
</div>
<!--Columns -->
<div class="col-lg-*">
...
</div>
</form>
Add the form-inline class to your form, add the form-group class to the containing div, and move the input tag out of your label tag:
<form class="form-inline">
<div class="form-group col-sm-4">
<label class="control-label">Quantity:</label>
<input type="text" data-bind="value: Quantity,valueUpdate: 'afterkeydown'" class="form-control"/>
</div>
</div>