Trouble aligning one of the labels to the right - html

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>

Related

responsive html and css code with any devices

I want to render my screen responsive with any kind of device, so my code display very good on a big screen but not the same thing with the young screen so I want my screen to be fitted for all sizes.I spend a lot of time to target it but I can't found any solution my code:
* {
box-sizing: border-box;
padding: 0%;
margin: 0%;
background-color: #dfe3ee;
}
.text {
float: left;
margin-top: 200px;
margin-left: 160px;
font-size: 2rem;
font-family: sans-serif;
color: rgb(100, 5, 5)
}
form {
border: 3px solid #f1f1f1;
width: 30%;
display: flex;
flex-wrap: wrap;
flex-direction: column;
margin-top: 5rem;
margin-right: 250px;
float: right;
}
input[type=text],
input[type=password] {
width: 90%;
padding: 8px 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: #04AA6D;
color: white;
padding: 8px 10px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
opacity: 0.8;
}
/* Extra style for the cancel button (red) */
/* Center the avatar image inside this container */
.container {
padding: 16px;
}
/* The "Forgot password" text */
span.psw {
float: right;
padding-top: 16px;
}
#media screen and (max-width: 600px) {
span.psw {
display: block;
float: right;
}
.form {
border: 3px solid #f1f1f1;
width: 30%;
display: flex;
}
}
import {Link} from "react-router-dom"; const RegisterPage =() => { return (
<div>
<div className="text">
<h1>Private</h1>
</div>
<form>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required />
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required />
<button type="submit">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember" /> Remember me
</label>
</div>
<div className="container" style={{ "backgroundColor": "#f1f1f1"}}>
Forgot password?
<div className="btn">
<button>Create New Account</button>
</div>
</div>
</form>
</div>
) }; export default RegisterPage;
Check this out, I added flexbox for your main div and modified your media query part with flexbox and removed margins. Keep in mind I changed className with class for snipping, for testing in your local you should change them again with className
* {
box-sizing:border-box;
padding: 0%;
margin: 0%;
background-color: #dfe3ee;
}
.mainDiv {
width: 100%;
height: 100vh;
display: flex;
justify-content: space-evenly;
align-items: center;
}
.text{
float: left;
font-size: 2rem;
font-family: sans-serif;
color:rgb(100, 5, 5)
}
form {
border: 3px solid #f1f1f1;
width: 30%;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
input[type=text], input[type=password] {
width: 90%;
padding: 8px 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: #04AA6D;
color: white;
padding: 8px 10px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
}
button:hover {
opacity: 0.8;
}
/* Extra style for the cancel button (red) */
/* Center the avatar image inside this container */
.container {
padding: 16px;
}
/* The "Forgot password" text */
span.psw {
float: right;
padding-top: 16px;
}
#media screen and (max-width: 600px) {
.mainDiv {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.text {
margin-left: 0;
}
span.psw {
display: block;
float: right;
}
form{
border: 3px solid #f1f1f1;
width: 30%;
display: flex;
float: none;
margin-right: 0;
min-width: 250px;
}
}
<div class="mainDiv">
<div class="text" >
<h1>Private</h1>
</div>
<form >
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required />
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required />
<button type="submit">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember" /> Remember me
</label>
</div>
<div className="container" style={{"backgroundColor":"#f1f1f1"}}>
<a href="" >Forgot password?</a>
<div className="btn" >
<button >Create New Account</button>
</div>
</div>
</form>
</div>

How to set div height to equal it div height?

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

Align Error Message Under Input - HTML/CSS

I have the following images that represent each case for user input-validation.
No Error:
Input Error:
I would like to maintain the alignment of the upper image while moving the error message underneath the input field (keep Label on left and Input on right, place error message underneath and aligned with input).
.group {
display: flex;
flex-wrap: nowrap;
margin-top: 4px;
}
.group label {
display: flex;
width: 15%;
line-height: 30px;
justify-content: center;
align-items: center;
}
.group input[type="text"] {
width: 85%;
border: 1px solid rgb(116, 115, 115);
padding-left: 3px;
}
.group textarea:focus,
input:focus {
outline: none;
}
.group .errorMsg {
color: #cc0033;
display: inline-block;
font-size: 12px;
line-height: 15px;
margin: 5px 0 0;
width: 100%;
}
.group .errorMsg {
display: none;
}
/* Error Styling */
.err label {
color: #cc0033;
}
.err input[type=text] {
background-color: #fce4e4;
border: 1px solid #cc0033;
outline: none;
}
.err .errorMsg {
display: inline-block;
}
<div class="group err">
<label for="time">Time</label>
<input type="text" name="time" id="time" />
<div class="errorMsg">Invalid Time Format</div>
</div>
<div class="group">
<label for="time2">Time2</label>
<input type="text" name="time2" id="time2" />
<div class="errorMsg">Invalid Time Format</div>
</div>
Any recommendations to fix the poor alignment?
You can align them like this. I have added comments to the right of the changes.
.group {
display: flex;
flex-wrap: wrap; /* Wrap the elements */
margin-top: 4px;
}
.group label {
display: flex;
width: 15%;
line-height: 30px;
justify-content: center;
align-items: center;
}
.group input[type="text"] {
width: 85%;
border: 1px solid rgb(116, 115, 115);
padding-left: 3px;
flex: 1; /* Take the remaining width */
}
.group textarea:focus,
input:focus {
outline: none;
}
.group .errorMsg {
color: #cc0033;
display: inline-block;
font-size: 12px;
line-height: 15px;
margin: 5px 0 0;
width: 100%;
}
.group .errorMsg {
display: none;
}
/* Error Styling */
.err label {
color: #cc0033;
}
.err input[type=text] {
background-color: #fce4e4;
border: 1px solid #cc0033;
outline: none;
}
.err .errorMsg {
display: flex; /* Instead of inline-block */
width: 85%; /* Same as input width */
left: 15%; /* Rest of the width */
position: relative; /* Relative to parent */
}
<div class="group err">
<label for="time">Time</label>
<input type="text" name="time" id="time" />
<div class="errorMsg">Invalid Time Format</div>
</div>
<div class="group">
<label for="time2">Time2</label>
<input type="text" name="time2" id="time2" />
<div class="errorMsg">Invalid Time Format</div>
</div>

Placing checkbox below input box (styling)

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>

Why are these block elements on the same line?

I'm trying to get the two block elements to be on different lines when the browser window is less than 768px. The media query tells the yellow and green divs to be blocks in responsive view, but nothing happens. If you apply the display block to all elements on mobile view, nothing still happens.
I thought block elements were 100% wide and operate on a single row?
#newsletter-wrap {
width: 100%;
height: auto;
background: lightgrey;
float: left;
display: flex;
justify-content: center;
align-items: center;
font-size: 22px;
font-weight: 300;
padding: 25px 25px;
box-sizing: border-box;
}
#newsletter-wrap > *, #newsletter-wrap > form > * {
display: inline;
vertical-align: middle;
}
#newsletter-button {
border: none;
border-radius: 6px;
padding: 10px 20px;
border: 1px solid #333;
cursor: pointer;
}
input {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
#mce-EMAIL {
background: pink;
width: 300px;
height: 25px;
margin: 0 25px;
border: 1px solid #333;
text-align: center;
padding: 4px;
}
#mc-embedded-subscribe-form {
background: green;
width: auto;
text-align: center;
height: auto;
float: left;
}
#newsletter-wrap-text {
background: yellow;
width: auto;
height: auto;
float: left;
}
/* MOBILE */
#media handheld, screen and (max-width: 768px) {
/* BELOW HAS A PROBLEM */
#newsletter-wrap-text, #mc-embedded-subscribe-form {
display: block;
}
}
<section id="newsletter-wrap">
<div id="newsletter-wrap-text">wuf wfbrie erig ergibw eiwbfwe wef00x0 __W)9.</div>
<form action="https://eiurfhyergv.us17.list-manage.com/subscribe/post?u=8c38151fa33f984127db5705c&id=4c741659e1" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<input type="email" placeholder="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
<div id="mce-responses">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<input type="submit" value="Subscribe" name="subscribe" id="newsletter-button">
</form>
</section>
As you have set display: flex to the parent section container, you have to set flex-direction: column; in order to display the child elements in a column rather than in a row. (or you could just not use display: flex at all and leave the block elements as they are, but I assume that flex is there for a reason like responsiveness or something)
By the way, you could also leave out the float: left as it has no effect in this case. I'd generally advise to clean the CSS up a bit. You are using display: flex;, but then there are the floats and display: inline, which is then again being overwritten by display: block - that's all unnecessary!
#newsletter-wrap {
width: 100%;
height: auto;
background: lightgrey;
float: left;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 22px;
font-weight: 300;
padding: 25px 25px;
box-sizing: border-box;
}
#newsletter-wrap > *, #newsletter-wrap > form > * {
display: inline;
vertical-align: middle;
}
#newsletter-button {
border: none;
border-radius: 6px;
padding: 10px 20px;
border: 1px solid #333;
cursor: pointer;
}
input {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
#mce-EMAIL {
background: pink;
width: 300px;
height: 25px;
margin: 0 25px;
border: 1px solid #333;
text-align: center;
padding: 4px;
}
#mc-embedded-subscribe-form {
background: green;
width: auto;
text-align: center;
height: auto;
float: left;
}
#newsletter-wrap-text {
background: yellow;
width: auto;
height: auto;
float: left;
}
/* MOBILE */
#media handheld, screen and (max-width: 768px) {
/* BELOW HAS A PROBLEM */
#newsletter-wrap-text, #mc-embedded-subscribe-form {
display: block;
}
}
<section id="newsletter-wrap">
<div id="newsletter-wrap-text">wuf wfbrie erig ergibw eiwbfwe wef00x0 __W)9.</div>
<form action="https://eiurfhyergv.us17.list-manage.com/subscribe/post?u=8c38151fa33f984127db5705c&id=4c741659e1" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<input type="email" placeholder="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
<div id="mce-responses">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<input type="submit" value="Subscribe" name="subscribe" id="newsletter-button">
</form>
</section>