I am trying to place a checkbox below a text input box, but my InputBar is not occupying the full parent width and checkbox is appearing at the end of InputBar.
I am a front-end newbea, can someone suggest what can I change to place the checkbox under the input bar.
My styling code:
.background {
background-image: url("../Back.jpg");
background-repeat: no-repeat;
margin: -11px -16px 0 -16px;
background-size: 100%;
min-height: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.inputBar {
padding-left: 30%;
width: 100%;
.enterButton {
background: url("../arrowNext.svg") no-repeat center white;
height: 50px;
width: 35px;
border-top-right-radius: 100px;
border-bottom-right-radius: 100px;
vertical-align: top;
}
.enterText {
color: $primary-text-color-light;
width: 60%;
height: 50px;
border-top-left-radius: 100px;
border-bottom-left-radius: 100px;
display: inline-block;
vertical-align: top;
padding-left: 2%;
}
}
.check {
display: inline-block;
.checkBox {
width: 40px;
height: 20px;
background: #555;
margin: 5px;
border-radius: 3px;
padding-left: 30%;
}
.checkBoxText {
font-weight: bold;
font-size: larger;
color: grey;
background-color: whitesmoke;
}
}
<div class="background">
<div class="inputBar">
<input class="enterText" id="inputBox" type="text" placeholder="Enter something" />
<button class="enterButton">Enter</button>
</div>
<div class="check">
<input class="checkBox" type="checkbox" defaultChecked/>
<span class="checkBoxText">Check this</span>
</div>
</div>
By default, flex sets direction to row.
You can set flex-direction: column to achieve what you want.
.container {
display: flex;
flex-direction: column;
}
<div class="container">
<div>
<input type="text" />
<button>Enter</button>
</div>
<div>
<input type="checkbox" id="check-this" />
<label for="check-this">Check this</label>
</div>
</div>
Related
I would like to know how can I adjust the height of a div depending of the content on it. For example, I have the following HTML:
div.Pantalla {
background-image: url("https://cdn.pixabay.com/photo/2015/07/11/23/02/plane-841441_1280.jpg");
background-size: cover;
justify-content: center;
align-items: center;
height: auto;
display: flex;
flex-direction:column;
}
.formulario{
position: relative;
width:80%;
margin:auto;
}
form{
margin-top: 10px;
display: block;
width:100%;
padding:16px;
border: 1px solid black;
border-radius:5px;
background: deepskyblue;
}
.form-inline {
display: flex;
flex-flow: row wrap;
align-items: center;
}
/* Add some margins for each label */
.form-inline label {
margin: 5px 10px 5px 0;
}
/* Style the input fields */
.form-inline input {
vertical-align: middle;
margin: 5px 10px 5px 0;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
}
/* Style the submit button */
.form-inline button {
width: 10%;
text-align: center;
padding: 10px 20px;
border: 1px solid #ddd;
background: #0095dd;
background-size: cover;
color: white;
}
.form-inline button:hover {
background-color:lightblue;
}
ul{
width:100%;
padding:16px;
border: 2px solid black;
border-radius:5px;
background: deepskyblue;
margin-top: 10px;
}
li{
position: center;
width:100%;
}
.column {
float: left;
margin-top: 20px;
width: 80%;
margin-right: 10%;
margin-left: 10%;
position: relative;
}
.column button{
margin-right: 10%;
margin-left: 10%;
margin-top: 10px;
width: 80%;
text-align: center;
padding: 10px 20px;
border: 1px solid #ddd;
background: #0095dd;
background-size: cover;
color: white;
}
.column button:hover {
background-color:lightblue;
}
<div class="Pantalla">
<div class="formulario">
<form class="form-inline" [formGroup]="SearchForm">
<input type="text" id="Origin" placeholder="Enter Origin" formControlName="Origin">
<input type="text" id="Destiny" placeholder="Enter Destination" formControlName="Destiny">
<input type="date" id="CheckIn" placeholder="Enter Check-In Date" formControlName="CheckIn">
<input type="date" id="Checkout" placeholder="Enter Check-Out Date" formControlName="Checkout">
<input type="number" id="people" placeholder="Enter Number of People" formControlName="people">
<button type="submit" (click)="getPacks()">Go!</button>
</form>
</div>
<div class="column menu">
<ul class="list-group" *ngFor="let pack of packs; let i = index">
<li class="list-group-item">Flight {{pack.flight.Airline}}, {{pack.flight.LandMarkName_Origin}} - {{pack.flight.LandMarkName_Destination}} for {{pack.flight.minPrice}} Dolars </li>
<li class="list-group-item">Stay at {{pack.hotel.name}}, with {{pack.hotel.Star_rating}} / {{pack.hotel.scale}} Stars</li>
<li class="list-group-item">Visit
<p *ngFor="let places of pack.places; let j = index">{{places.name}}, </p>
</li>
<button>Get it!</button>
</ul>
</div>
</div>
However, when I launch my application, what I get is this:
I want that the height of the "Pantalla" div equals the total height of the divs that it has. How can I achieve this?
UPDATED: When the code is like this, what I get is the following:
enter image description here
The reason why the background only cover to the first div is that you're missing the display rule.
Please add display: flex; and flex-direction:column, then you will see it's working.
div.Pantalla {
background-image: url("https://cdn.pixabay.com/photo/2015/07/11/23/02/plane-841441_1280.jpg");
background-size: cover;
justify-content: center;
align-items: center;
height: auto;
/* Add this */
display: flex;
flex-direction: column;
}
.formulario{
position: relative;
width:80%;
margin:auto;
}
form{
margin-top: 10px;
display: block;
width:100%;
padding:16px;
border: 1px solid black;
border-radius:5px;
background: deepskyblue;
}
.form-inline {
display: flex;
flex-flow: row wrap;
align-items: center;
}
/* Add some margins for each label */
.form-inline label {
margin: 5px 10px 5px 0;
}
/* Style the input fields */
.form-inline input {
vertical-align: middle;
margin: 5px 10px 5px 0;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
}
/* Style the submit button */
.form-inline button {
width: 10%;
text-align: center;
padding: 10px 20px;
border: 1px solid #ddd;
background: #0095dd;
background-size: cover;
color: white;
}
.form-inline button:hover {
background-color:lightblue;
}
ul{
width:100%;
padding:16px;
border: 2px solid black;
border-radius:5px;
background: deepskyblue;
margin-top: 10px;
}
li{
position: center;
width:100%;
}
.column {
float: left;
margin-top: 20px;
width: 80%;
margin-right: 10%;
margin-left: 10%;
position: relative;
}
.column button{
margin-right: 10%;
margin-left: 10%;
margin-top: 10px;
width: 80%;
text-align: center;
padding: 10px 20px;
border: 1px solid #ddd;
background: #0095dd;
background-size: cover;
color: white;
}
.column button:hover {
background-color:lightblue;
}
<div class="Pantalla">
<div class="formulario">
<form class="form-inline" [formGroup]="SearchForm">
<input type="text" id="Origin" placeholder="Enter Origin" formControlName="Origin">
<input type="text" id="Destiny" placeholder="Enter Destination" formControlName="Destiny">
<input type="date" id="CheckIn" placeholder="Enter Check-In Date" formControlName="CheckIn">
<input type="date" id="Checkout" placeholder="Enter Check-Out Date" formControlName="Checkout">
<input type="number" id="people" placeholder="Enter Number of People" formControlName="people">
<button type="submit" (click)="getPacks()">Go!</button>
</form>
</div>
<div class="column menu">
<ul class="list-group" *ngFor="let pack of packs; let i = index">
<li class="list-group-item">Flight {{pack.flight.Airline}}, {{pack.flight.LandMarkName_Origin}} - {{pack.flight.LandMarkName_Destination}} for {{pack.flight.minPrice}} Dolars </li>
<li class="list-group-item">Stay at {{pack.hotel.name}}, with {{pack.hotel.Star_rating}} / {{pack.hotel.scale}} Stars</li>
<li class="list-group-item">Visit
<p *ngFor="let places of pack.places; let j = index">{{places.name}}, </p>
</li>
<button>Get it!</button>
</ul>
</div>
</div>
As I can see that you have a main div and two child div inside that main div element
and you want that the background image of must cover both div.
if I am right then change the height of your main element
height: 100vh;
change your css code like below and see what happend
div.Pantalla {
background-image: url("https://cdn.pixabay.com/photo/2015/07/11/23/02/plane-841441_1280.jpg");
background-size: cover;
justify-content: center;
align-items: center;
height: 100vh;
}
If what you want is the image that occupies all the space that its parent has, try this:
I suppose that the div.Pantalla's parent is a div with id: app.
#app {
position: relative;
width: 100%;
height: auto;
}
div.Pantalla {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
View problem at:
https://jsfiddle.net/xa3u5w8j/5/
The reason why I want my button div to be flex is it has this CSS:
.button {
background-color: aqua;
text-align: center;
width: 150px;
height: 50px;
cursor: pointer;
display: flex;
}
And thus, removing the flex property will cause its text to mis-align.
I want all 3 labels to be aligned to the right, but it somehow is not working for the 3rd label. Any insight can help! Thanks
EDIT: Code
/* Gives the form left/right margin and sets text color */
.course-info {
margin: 0 20px 0 20px;
color: #9E7772;
}
/* Makes sure the form contents are lined up */
.course-info label {
display: inline-block;
width: 540px;
text-align: right;
margin: 20px 0 20px 0;
align-items: top;
}
/* Styles the input and textarea and make sure they line up */
.course-info input {
width: 400px;
background-color: white;
border-bottom: 3px solid #E0DEDE;
}
.course-info textarea {
word-break: break-all;
width: 394px; /* 400px(intended length) - 2*3px(border width) */
height: 100px;
border: 3px solid #E0DEDE;
display: inline-block;
}
/* Makes sure they don't break into diff lines */
.course-title label, .course-title input{
float: none;
display: inline-block;
}
.invitation-section {
display: flex;
justify-content: right;
}
/* Special length and height */
.invitation-link{
max-width: 250px; /* 400px - button width to align on the right side */
max-height: 20px;
}
.button-wrapper{
display: inline-block;
}
.button {
background-color: aliceblue;
width: 150px;
display: flex; /*This is necessary*/
}
<form class="course-info" onSubmit={handleSettingsChange}>
<label>
Course Title:
<input type="text" value="Whatever is here"/>
</label>
<label>
<span>Description:</span>
<textarea type="text">Random text here</textarea>
</label>
<label>
<div class="invitation-section">
<span>Invitation:</span>
<textarea readOnly
class="invitation-link" type="text">
</textarea>
<label class="button-wrapper">
<div class="button">Button</div>
</label>
</div>
</label>
</form>
label {
display: inline-block;
width: 140px;
text-align: right;
}
.button {
background-color: aqua;
text-align: center;
width: 150px;
height: 50px;
cursor: pointer;
display: flex;
}
.invitation-link {
max-width: 250px;
/* 400px - button width to align on the right side */
max-height: 20px;
}
.block {
margin-bottom: 10px;
}
label {
display: inline-block;
width: 140px;
text-align: right;
}
.button {
background-color: aqua;
text-align: center;
width: 150px;
height: 50px;
cursor: pointer;
display: flex;
}
.invitation-link {
max-width: 250px;
/* 400px - button width to align on the right side */
max-height: 20px;
}
.block {
margin-bottom: 10px;
}
.course-info textarea {
word-break: break-all;
width: 394px; /* 400px(intended length) - 2*3px(border width) */
height: 100px;
border: 3px solid #E0DEDE;
display: inline-block;
}
button {
display: inline-block;
margin-left: 10px;
margin-top:-2px;
background-color: aqua;
width: 80px;
height: 30px;
cursor: pointer;
}
<form class="course-info" onSubmit={handleSettingsChange}>
<div class="block">
<label> Course Title:</label>
<input type="text" value="Whatever is here" />
</div>
<div class="block">
<label>Description:</label>
<textarea type="text">Random text here</textarea>
</div>
<div class="block invitation-section">
<label>Invitation:</label>
<textarea readOnly class="invitation-link" type="text">
</textarea>
<button>
Copy
</button>
</div>
</form>
I am attempting to center a image next to an input field although when attempting to do so with vertical-align: bottom; nothing happens and my image is not centered where I want it to be.
I have tried to use position:relative and then move my image using top,bottom etc but I want to do it in a way that uses flexbox.
How would I go about doing this and what divs would I have to change to get the layout I want.
Layout I am trying to achieve:
Jsfiddle
HTML
<div class="container">
<h1>Inputs</h1>
<p class="spacing">multiple inputs...</p>
<div class="searchinput">
<input type="text" name="search" id="google-input" placeholder="Google search...">
<img src="logos/google.png" alt="youtube" class="logos">
</div>
</div>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.logos{
width: 90px;
vertical-align: bottom;
}
.container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 90vh;
}
.searchinput {
margin-top: 20px;
}
input {
padding: 20px;
height: 30px;
background-color: transparent;
border: 2px solid black;
border-radius: 5px;
color: black;
font-size: 20px;
vertical-align: bottom;
}
You need to have the direct parent of the items that you want to have flex properties to have the display:flex property. So in your case it would be the .searchinput. So your .searchinput css should be the following:
.searchinput {
margin-top: 20px;
display:flex;
align-items: center;
}
So here is a snippet of the whole thing:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.logos{
width: 90px;
vertical-align: bottom;
}
.container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 90vh;
}
.searchinput {
margin-top: 20px;
display:flex;
align-items: center;
}
input {
padding: 20px;
height: 30px;
background-color: transparent;
border: 2px solid black;
border-radius: 5px;
color: black;
font-size: 20px;
vertical-align: bottom;
}
<div class="container">
<h1>Inputs</h1>
<p class="spacing">multiple inputs...</p>
<div class="searchinput">
<input type="text" name="search" id="google-input" placeholder="Google search...">
<img src="https://i.imgur.com/dpkbGqu.png" alt="youtube" class="logos">
</div>
</div>
In my form, the lables/inputsare aligned with floats and fixed widths. Because of this, my labels have empty whitespace which makes it difficult to center the form in the parent div.
How can I center this form?
#Form1Layout {
font-family: Verdana;
font-size: 10pt;
margin-top: 10px;
text-align: center;
padding: 10px;
}
#Form1Layout label {
text-align: right;
padding-right: 10px;
width: 80px;
}
#Form1Layout input {
width: 300px;
}
#Form1Layout label,
#Form1Layout input {
display: block;
float: left;
margin-bottom: 10px;
}
#Form1Layout br {
clear: both;
}
<div>
<div id="Form1Layout">
<label>User name:</label><input type="text" /><br>
<label>Address:</label><input type="text" /><br>
<label>Phone:</label><input type="text" /><br>
<label></label><button class="My_Button">Submit</button>
</div>
</div>
Use flexboxes for that. Here is a quick example.
(I intentionnaly increased the height of the inputs to show you how it works).
#Form1Layout {
font-family: Verdana;
font-size: 10pt;
margin-top: 10px;
text-align: center;
padding: 10px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
}
#Form1Layout > div {
flex: 1 1 auto;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
margin: 6px 0;
}
#Form1Layout label {
text-align: right;
padding-right: 10px;
width: 80px;
}
#Form1Layout input {
width: 300px;
height: 80px;
}
<div>
<div id="Form1Layout">
<div><label>User name:</label><input type="text" /></div>
<div><label>Address:</label><input type="text" /></div>
<div><label>Phone:</label><input type="text" /></div>
<div><label></label><button class="My_Button">Submit</button></div>
</div>
</div>
I am trying to make two buttons scale appropriately with in between margin responsive design.
How do I properly specify width of each button with the margin to stay constant in between?
Equal width buttons are below that I am trying to scale together, without exceeding the total width.
|--------------------100%------------------------|
|---Button 1---||--margin in px--||---Button 2---|
Here is what I have so far..
button1.back-btn {
#include btn-inline;
}
button2.next-btn {
#include btn-inline;
}
#mixin btn-inline{
width: calc(50% - $form-control-spacing/2 - $border-btn-width*2);
width: -webkit-calc(50% - $form-control-spacing/2 - $border-btn-width*2);
width: -moz-calc(50% - $form-conrol-spacing/2 - $border-btn-width*2);
display: inline-block;
}
Flexbox can do that.
* {
box-sizing: border-box;
}
.wrap {
width: 80%;
margin: 1em auto;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
border: 1px solid pink;
}
.wide {
flex: 0 0 100%;
}
button:first-of-type {
margin-right: 2em;
}
button {
flex: 1;
}
<div class="wrap">
<input class="wide" type="text" />
<button>Button 1</button>
<button>Button 2</button>
</div>
Here is my workout to your answer. Not sure if its the way you wanted, so please do let me know. Thanks.
You can refer to this link: https://jsfiddle.net/2g5unL8y/4/
Also refer to this link for a different resizing with no space in between when viewed at smallest window: https://jsfiddle.net/jeemo0yu/
CSS:
*{ box-sizing: border-box;}
input {
width: 50%;
height: auto;
margin: 10px;
}
#new {
float: left;
max-width: 30%;
overflow: hidden;
}
#old {
float: right;
max-width: 30%;
overflow: hidden;
}
div {
width:50%;
margin: 10px;
text-align: center;
}
HTML:
<input type="text"><br>
<div>
<button id="new">Click Me!</button>
<button id="old">Click Me!</button>
</div>
Float two buttons to left: float: left, then give the second button a margin-left:
body {
font-family: Gothamroundedmedium;
}
.create-password {
text-align: center;
}
.create-password .form-horizontal .form-group {
white-space: nowrap;
}
.create-password .form-horizontal .form-group .form-control {
border-radius: 0;
border: none;
box-shadow: none !important;
background-color: #f5f5f5;
margin-bottom: 5px;
height: 38px;
}
.create-password .form-horizontal .form-group .back-btn {
background-color: white;
color: #001b24;
font-size: 14px;
border: 2px solid #49dce0;
padding-top: 10px;
padding-right: 0px;
padding-bottom: 10px;
padding-left: 0px;
}
.create-password .form-horizontal .form-group .next-btn {
background-color: #49dce0;
color: #001b24;
font-size: 14px;
border: 2px solid #49dce0;
padding-top: 10px;
padding-right: 0px;
padding-bottom: 10px;
padding-left: 0px;
}
.back-btn {
float: left;
background-color: white;
color: #001b24;
font-size: 14px;
border: 2px solid #49dce0;
padding-top: 10px;
padding-right: 50px;
padding-bottom: 10px;
padding-left: 50px;
width: 30%;
display: inline-block;
}
.next-btn {
float: left;
margin-left: 40%;
background-color: #49dce0;
color: #001b24;
font-size: 14px;
border: 2px solid #49dce0;
padding-top: 10px;
padding-right: 50px;
padding-bottom: 10px;
padding-left: 50px;
width: 30%;
display: inline-block;
}
<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 create-password">
<div class="row">
<form class="form-horizontal col-xl-6 col-xl-offest-2 col-lg-10 col-lg-offset-1 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1 ng-pristine ng-valid">
<div class="form-group">
<input class="form-control" placeholder="Password" value="" type="password">
<input class="form-control" placeholder="Confirm password" value="" type="password">
<button class="back-btn" type="button" name="button">BACK</button>
<button class="next-btn" type="button" name="button">NEXT</button>
</div>
</form>
</div>
</div>
Possible solution using margin on first element
.buttonscontainer {
width: 100%;
background-color: hsl(38, 100%, 84%);
font-size: 0;
}
.buttons {
display: inline-block;
width: 33.33%;
text-align: center;
background-color: hsl(0, 0%, 60%);
font-size: 20px;
}
.buttons:first-child {
margin-right: 33.33%;
}
<div class="buttonscontainer">
<div class="buttons">Button 1</div>
<div class="buttons">Button 2</div>
</div>
fiddle
https://jsfiddle.net/Hastig/hgcLpds0/4/
A possible flexbox solution using a ghost button as a separator
.buttonscontainer {
display: flex;
width: 100%;
justify-content: center;
align-items: center;
}
.buttons {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
border: 1px solid hsla(0, 0%, 0%, 0.4)
}
.buttons:nth-child(2) {
visibility: hidden;
}
<div class="buttonscontainer">
<div class="buttons">Button 1</div>
<div class="buttons">u cant see me</div>
<div class="buttons">Button 2</div>
</div>
fiddle
https://jsfiddle.net/Hastig/hgcLpds0/
Possible solution using floats
.buttonscontainer {
width: 100%;
background-color: hsl(38, 100%, 84%);
overflow: auto;
}
.buttons {
display: flex;
justify-content: center;
width: 33.33%;
background-color: hsl(0, 0%, 60%);
}
.buttons:first-child {
float: left;
}
.buttons:last-child {
float: right;
}
<div class="buttonscontainer">
<div class="buttons">Button 1</div>
<div class="buttons">Button 2</div>
</div>
fiddle
https://jsfiddle.net/Hastig/hgcLpds0/1/