Shrinking html items to match screen-size? - html

I have a page that includes a large vertical form and I need it to be resized depending on the screen size. I want the form inputs to shrink with adequate margins on both the left and right side. My css consists of code like:
.container-register input#search, select {
width: 300px;
}
This makes the initial input widths fairly long so I have tried using #media (max-width) scripts to change the length but it looks very hardcoded. I want it to seamlessly change depending on the viewport without me having to use these #media scripts for every possible viewport width. I was thinking maybe something like flex? However I was having trouble using it.
<div class="body-content-register">
<div class="wrapper">
<center><section id="bg" class="zoom-register">
<div class="box-register">
<center><h1>Register</h1></center>
<form class="register">
<div class="container-register">
<span class="icon"><i class="fa fa-user"></i></span>
<input type="search" name="fullname" id="search" placeholder="Full Name">
</div><br><br><br><br>
<div class="container-register">
<span class="icon"><i class="fa fa-envelope"></i></span>
<input type="search" id="search" placeholder="Email">
</div><br><br><br><br>
<div class="container-register">
<span class="icon"><i class="fa fa-user"></i></span>
<input type="search" id="search" placeholder="Username">
</div><br><br><br><br>
<div class="container-register">
<span class="icon"><i class="fa fa-birthday-cake"></i></span>
<input type="search" id="search" placeholder="Date of Birth">
</div><br><br><br><br>
<div class="container-register">
<span class="icon"><i class="fa fa-map-marker"></i></span>
<input type="search" id="search" placeholder="Postcode">
</div><br><br><br><br>
<div class="container-register">
<span class="icon"><i class="fa fa-key"></i></span>
<input type="search" id="search" placeholder="Password">
</div><br><br><br><br>
<div class="container-register">
<span class="icon"><i class="fa fa-key"></i></span>
<input type="search" id="search" placeholder="Confirm Password">
</div><br><br><br><br>
<div class="float-middle">
<input type="checkbox" name="checkbox" value="checkbox"> Do you accept our terms & conditions?<br>
</div><br>
<button class="button"><strong>Submit</strong></button>
</form>
</div>
</section></center>
</div>
</div>

Besides using media queries you can use intrinsic units of measurement like vw and vh. Not related to the question but I feel I should point out that #ID must be unique so you can't have every element have id='search'. The type attribute of an <input> determines its behavior so type="search" isn't really what you need. Also there are more suitable tags that you could use other than <div> and <span>, but that's purely optional. I changed the layout a bit to reflect what I previously mentioned.
Demo
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
main {
width: 100vw;
height: 100vh;
}
.icon {
display: inline-block;
margin: 0 0 2vw 2vh;
}
h3 {
margin: 0
}
.line {
border: 0;
width: 96vw;
margin: 0;
padding: 0
}
i {
width: 3vw;
margin: 0 1vw 0 0;
}
.name {
display: block
}
#fullName {
width: 86vw;
}
input {
font: inherit;
width: 39vw;
}
.DOB input {
width: 12vw;
text-align: center;
}
.disclosure {
display: block;
margin: 2vh auto 0;
width: 80vw;
}
#accept {
width: 3vw;
}
[type=submit] {
width: 16vw
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<main>
<form id='register'>
<fieldset id="bg">
<legend>
<h3>
Register
</h3>
</legend>
<label class="icon name"><i class="fa fa-user"></i>
<input type="text" id="fullName" name="fullName" placeholder="Full Name"></label>
<fieldset class='line'>
<label class="icon email"><i class="fa fa-envelope"></i>
<input type="email" id="email" placeholder="Email"></label>
<label class="icon user"><i class="fa fa-user"></i>
<input type="text" id="userName" name="userName" placeholder="Username"></label>
</fieldset>
<fieldset class='line'>
<label class='icon DOB'> <i class="fa fa-birthday-cake"></i>
<input type="number" id="DOBmonth" name="DOBmonth" placeholder="Month" min='1' max='12'>
<input type="number" id="DOBday" name="DOBday" placeholder="Day" min='1' max='31'>
<input type="number" id="DOByear" name="DOByear" placeholder="Year" min='1900' max='2000'></label>
<label class="icon country"><i class="fa fa-map-marker"></i>
<input type="text" id="country" name='country' placeholder="Country"></label>
</fieldset>
<label class="icon pass"><i class="fa fa-key"></i>
<input type="password" id="pass" placeholder="Password">
<input type="password" id="confirm" placeholder="Confirm Password">
</label>
</fieldset>
<label class='disclosure'>
<input type="checkbox" id='accept' name="accept" value="accept"> Do you accept our terms & conditions?
<input type="submit"></label>
</form>
</main>

Related

Prevent input data from showing in url - Flask

I am gathering customer data from a web app - however once data is input the data displays in the URL search bar and I am just wondering about how to prevent that from happening?
here is my current code:
<form>
<div class="row">
<div class="col-75">
<div class="container">
<form action="/action_page.php", method="POST">
<div class="row">
<div class="col-50">
<h3>Billing Address</h3>
<label for="fname"><i class="fa fa-user"></i> Full Name</label>
<input type="text" id="fname" name="firstname" placeholder="John M. Doe">
<label for="email"><i class="fa fa-envelope"></i> Email</label>
<input type="text" id="email" name="email" placeholder="john#example.com">
<label for="adr"><i class="fa fa-address-card-o"></i> Address</label>
<input type="text" id="adr" name="address" placeholder="1234 Example Street, Richmond">
<label for="city"><i class="fa fa-institution"></i> Suburb</label>
<input type="text" id="city" name="city" placeholder="Melbourne">
<div class="row">
<div class="col-50">
<label for="state">State</label>
<input type="text" id="state" name="state" placeholder="Victoria">
</div>
<div class="col-50">
<label for="postcode">Post Code</label>
<input type="text" id="postcode" name="postcode" placeholder="3934">
</div>
</div>
</div>
<div class="col-50">
<h3>Payment</h3>
<label for="fname">Accepted Cards</label>
<div class="icon-container">
<i class="fa fa-cc-visa" style="color:navy;">Visa</i>
<i class="fa fa-cc-amex" style="color:blue;">Amex</i>
<i class="fa fa-cc-mastercard" style="color:red;">Mastercard</i>
</div>
<label for="cname">Name on Card</label>
<input type="text" id="cname" name="cardname" placeholder="John More Doe">
<label for="ccnum">Credit card number</label>
<input type="text" id="ccnum" name="cardnumber" placeholder="1111-2222-3333-4444">
<label for="expmonth">Exp Month</label>
<input type="text" id="expmonth" name="expmonth" placeholder="September">
<div class="row">
<div class="col-50">
<label for="expyear">Exp Year</label>
<input type="text" id="expyear" name="expyear" placeholder="2018">
</div>
<div class="col-50">
<label for="cvv">CVV</label>
<input type="text" id="cvv" name="cvv" placeholder="352">
</div>
</div>
</div>
</div>
<label>
<input type="checkbox" checked="checked" name="sameadr"> Shipping address same as billing
</label>
<input type="submit" value="Continue to checkout" class="btn">
</form>
</div>
</div>
.row {
display: -ms-flexbox; /* IE10 */
display: flex;
-ms-flex-wrap: wrap; /* IE10 */
flex-wrap: wrap;
margin: 0 -16px;
}
.col-25 {
-ms-flex: 25%; /* IE10 */
flex: 25%;
}
.col-50 {
-ms-flex: 50%; /* IE10 */
flex: 50%;
}
.col-75 {
-ms-flex: 75%; /* IE10 */
flex: 75%;
}
.col-25,
.col-50,
.col-75 {
padding: 0 16px;
}
.container {
background-color: #f2f2f2;
padding: 5px 20px 15px 20px;
border: 1px solid lightgrey;
border-radius: 3px;
}
input[type=text] {
width: 100%;
margin-bottom: 20px;
padding: 12px;
border: 1px solid #ccc;
border-radius: 3px;
}
label {
margin-bottom: 10px;
display: block;
}
.icon-container {
margin-bottom: 20px;
padding: 7px 0;
font-size: 24px;
}
.btn {
background-color: #04AA6D;
color: white;
padding: 12px;
margin: 10px 0;
border: none;
width: 100%;
border-radius: 3px;
cursor: pointer;
font-size: 17px;
}
.btn:hover {
background-color: #45a049;
}
span.price {
float: right;
color: grey;
}
/* Responsive layout - when the screen is less than 800px wide, make the two columns stack on top of each other instead of next to each other (and change the direction - make the "cart" column go on top) */
#media (max-width: 800px) {
.row {
flex-direction: column-reverse;
}
.col-25 {
margin-bottom: 20px;
}
}
Any help would be really appreciated :)
You have an unnecessary <form> tag on the first line of your HTML and you are missing a closing </div> tag at the end. Changing this seems to resolve the issue:
<div class="row">
<div class="col-75">
<div class="container">
<form action="/action_page.php" , method="POST">
<div class="row">
<div class="col-50">
<h3>Billing Address</h3>
<label for="fname"><i class="fa fa-user"></i> Full Name</label>
<input type="text" id="fname" name="firstname" placeholder="John M. Doe">
<label for="email"><i class="fa fa-envelope"></i> Email</label>
<input type="text" id="email" name="email" placeholder="john#example.com">
<label for="adr"><i class="fa fa-address-card-o"></i> Address</label>
<input type="text" id="adr" name="address" placeholder="1234 Example Street, Richmond">
<label for="city"><i class="fa fa-institution"></i> Suburb</label>
<input type="text" id="city" name="city" placeholder="Melbourne">
<div class="row">
<div class="col-50">
<label for="state">State</label>
<input type="text" id="state" name="state" placeholder="Victoria">
</div>
<div class="col-50">
<label for="postcode">Post Code</label>
<input type="text" id="postcode" name="postcode" placeholder="3934">
</div>
</div>
</div>
<div class="col-50">
<h3>Payment</h3>
<label for="fname">Accepted Cards</label>
<div class="icon-container">
<i class="fa fa-cc-visa" style="color:navy;">Visa</i>
<i class="fa fa-cc-amex" style="color:blue;">Amex</i>
<i class="fa fa-cc-mastercard" style="color:red;">Mastercard</i>
</div>
<label for="cname">Name on Card</label>
<input type="text" id="cname" name="cardname" placeholder="John More Doe">
<label for="ccnum">Credit card number</label>
<input type="text" id="ccnum" name="cardnumber" placeholder="1111-2222-3333-4444">
<label for="expmonth">Exp Month</label>
<input type="text" id="expmonth" name="expmonth" placeholder="September">
<div class="row">
<div class="col-50">
<label for="expyear">Exp Year</label>
<input type="text" id="expyear" name="expyear" placeholder="2018">
</div>
<div class="col-50">
<label for="cvv">CVV</label>
<input type="text" id="cvv" name="cvv" placeholder="352">
</div>
</div>
</div>
</div>
<label>
<input type="checkbox" checked="checked" name="sameadr"> Shipping address same as billing
</label>
<input type="submit" value="Continue to checkout" class="btn">
</form>
</div>
</div>
</div>
(Note: my editor may have formatted your code differently to the original question)

how to make an element fixed when the window resizes

I have a registration form where the there is icons in the form input. When i resize the window it displaces (squeezes) which is very annoying can anyone tell me what should i do to make it fixes in the place where it is.
#username-logo {
position: relative;
float: left;
top: 40px;
left: 15%;
}
#password-logo {
position: relative;
float: left;
top: 40px;
left: 15%;
}
#email-logo {
position: relative;
float: left;
top: 40px;
left: 15%;
}
<form id="form-container">
<h1 id="linklist">Register</h1>
<input type="text" name="username" id="username" placeholder="Username" required="required">
<i class="fas fa-user" id="username-logo"></i>
<input type="password" name="password" id="password" placeholder="Password" required="required">
<i class="fas fa-lock" id="password-logo"></i>
<input type="email" name="email" id="email" placeholder="Email" required="required">
<i class="fas fa-envelope" id="email-logo"></i>
<input type="submit" name="submit" id="submit" value="Register">
</form>
Wrap the icon and input and from there you can style it easier. The placement of the icon all depends on the design you have.
.register-form {
display: flex;
flex-wrap: wrap;
max-width: 20rem;
}
.input-container {
display: flex;
}
.input-container input {}
.input-container i {}
<h1 id="linklist">Register</h1>
<form id="form-container" class="register-form">
<div class="input-container">
<input type="text" name="username" id="username" placeholder="Username" required="required">
<i class="fas fa-user" id="username-logo"></i>
</div>
<div class="input-container">
<input type="password" name="password" id="password" placeholder="Password" required="required">
<i class="fas fa-lock" id="password-logo"></i>
</div>
<div class="input-container">
<input type="email" name="email" id="email" placeholder="Email" required="required">
<i class="fas fa-envelope" id="email-logo"></i>
</div>
<button type="submit" class="button">Register</button>
</form>
Put your container position: relative and logo position: absolute and reposition using left/right/top/bottom .
This way the logo's will be positioned according to container (here input) not according to body and will not displaces on resize if used correctly

trouble aligning the divs and other inner tags at different positions

I'm creating my first ever html page, and I'm trying to do some alignment for divs and labels.
The labels and the input seem out of position even after spending multiple hours trying different combinations. Some properties are not working, like I used width for label and in chrome it says unknown property.
Below is the code. Any help with this would be appreciated.
Preview of the html/css part:
div.btn-toolbar {
position: relative;
top: 100px;
left: 40%;
width: 400px;
}
div.quote-details {
position: relative;
top: 122px;
left: 250px;
font-weight: bold;
font-size: 15px;
}
div.quote-detail-section-left {
float: left;
margin-top: 145px;
margin-left: 100px;
width: 35%;
}
input.quote-input {
padding: 4px;
}
label.field-label {
float: left;
font-weight: bold;
display: inline-block;
margin-left: 40px;
width: :50px;
clear: both;
}
div.quote-detail-section-right {
float: right;
margin-top: 145px;
margin-right: 80px;
width: 35%;
}
<div class="quote-rec-page">
<div class="quote-details">
<label for="section" class="Segment">Quote Details</label>
</div>
<div class="btn-toolbar">
<button type="button">Edit</button>
<button type="button">Delete</button>
<button type="button">Create PDF</button>
<button type="button">Email Quote</button>
<button type="button">Start Sync</button>
</div>
<form>
<div class="quote-detail-section-left">
<div>
<label for="quoteNum" class="field-label">Quote Number</label>
<input type="text" class="quote-input" tabindex="1" id="quoteNumber" />
</div>
<div>
<label for="quoteName" class="field-label">Quote Name</label>
<input type="text" class="quote-input" tabindex="2" id="quoteName" />
</div>
<div>
<label for="oppName" class="field-label">Opportunity Name</label>
<input type="text" class="quote-input" tabindex="3" id="oppName" />
</div>
<div>
<label for="accName" class="field-label">Account Name</label>
<input type="text" class="quote-input" tabindex="4" id="accName" />
</div>
</div>
<div class="quote-detail-section-right">
<div>
<label for="expDate" class="field-label">Expiration Date</label>
<input type="date" class="quote-input" tabindex="5" id="expDate" />
</div>
<div>
<label for="sync" class="field-label">Syncing</label>
<input type="checkbox" class="quote-input" tabindex="6" id="sync" />
</div>
<div>
<label for="status" class="field-label">Status</label>
<input type="text" class="quote-input" tabindex="7" id="status" />
</div>
<div>
<label for="quoteDesc" class="field-label">Description</label>
<input type="text" class="quote-input" tabindex="8" id="quoteDesc" />
</div>
</div>
</form>
</div>
Html/css including apex code:
<apex:page sidebar="false" showHeader="false">
<head>
<title>Quote Details</title>
</head>
<style>
div.btn-toolbar{
position:relative;
top:100px;
left:40%;
width:400px;
}
div.quote-details{
position:relative;
top:122px;
left:250px;
font-weight:bold;
font-size:15px;
}
div.quote-detail-section-left{
float:left;
margin-top : 145px;
margin-left: 100px;
width:35%;
}
input.quote-input{
padding:4px;
}
label.field-label{
float:left;
font-weight:bold;
display:inline-block;
margin-left : 40px;
width::50px;
clear:both;
}
div.quote-detail-section-right{
float:right;
margin-top : 145px;
margin-right: 80px;
width:35%;
}
</style>
<body>
<div class="quote-rec-page">
<div class = "quote-details">
<label for = "section" class="Segment">Quote Details</label>
</div>
<div class ="btn-toolbar">
<button type="button">Edit</button>
<button type="button">Delete</button>
<button type="button">Create PDF</button>
<button type="button">Email Quote</button>
<button type="button">Start Sync</button>
</div>
<form>
<div class ="quote-detail-section-left">
<div>
<label for="quoteNum" class ="field-label">Quote Number</label>
<input type="text" class="quote-input" tabindex="1" id="quoteNumber"/>
</div>
<div>
<label for="quoteName" class ="field-label">Quote Name</label>
<input type="text" class="quote-input" tabindex="2" id="quoteName"/>
</div>
<div>
<label for="oppName" class ="field-label">Opportunity Name</label>
<input type="text" class="quote-input" tabindex="3" id="oppName"/>
</div>
<div>
<label for="accName" class ="field-label">Account Name</label>
<input type="text" class="quote-input" tabindex="4" id="accName"/>
</div>
</div>
<div class ="quote-detail-section-right">
<div>
<label for="expDate" class ="field-label">Expiration Date</label>
<input type="date" class="quote-input" tabindex="5" id="expDate"/>
</div>
<div>
<label for="sync" class ="field-label">Syncing</label>
<input type="checkbox" class="quote-input" tabindex="6" id="sync"/>
</div>
<div>
<label for="status" class ="field-label">Status</label>
<input type="text" class="quote-input" tabindex="7" id="status"/>
</div>
<div>
<label for="quoteDesc" class ="field-label">Description</label>
<input type="text" class="quote-input" tabindex="8" id="quoteDesc"/>
</div>
</div>
</form>
</div>
</body>
</apex:page>

Putting a checkbox, label and input box next to each other

I am trying to put a checkbox, label and input box next to each other.
I separated it into divs and and put divs side-by-side.
I was able to get the buttons center but they are to close together which I am trying to fix too.
My question is how can I get <div class="col-centered border"> into a smaller border and put a checkbox, label and input box next to each other. In the end I want the buttons and all as a container.
html
<div class="col-centered border">
<form>
<div class="first">
<div class="form-group">
<input type="checkbox" class="form-check-input">
<label for="ssn">SSN:</label>
<input type="text" class="form-control-file" id="ssn" placeholder="Social Security Number">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="lastname">Lastname:</label>
<input type="text" class="form-control-file" id="lastname" placeholder="Password">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="role">Role:</label>
<input type="text" class="form-control-file" id="role" placeholder="Password">
</div>
</div>
<div class="second">
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="userId">User ID:</label>
<input type="text" class="form-control-file" id="userId" placeholder="User Id">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="office">Office</label>
<input type="text" class="form-control-file" id="office" placeholder="Office">
</div>
<input type="checkbox">Include Subordinates
</div>
<div class="center-block lower-button">
<div class="center-block">
<button type="submit" class="btn btn-default btn-md left-button">Search</button>
<button type="submit" class="btn btn-default btn-md right-button">Reset</button>
</div>
</div>
</form>
</div>
css
.first {
width: 100px;
float: left;
padding-left: 450px;
}
.second {
width: 200px;
float: right;
padding-right: 950px;
}
.col-centered{
padding-top: 30px;
float: none;
margin: 0 auto;
}
.btn-beside {
position: center;
left: 100%;
top: 0;
margin-left: -10px;
}
.lower-button{
padding-top:250px;
padding-left:575px;
}
.left-button{
padding-right: -14px;
}
.form-group{
text-align: center;
}
I am using bootstrap
Here's a Fiddle for you to take inspiration from.
HTML
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox">
</span>
<span class="input-group-addon">
<label for="tbox">My Label</label>
</span>
<input type="text" id="tbox" class="form-control">
</div>
</div>
</div>
</div>
As per the official documentation for Bootstrap.

Put a font-awesome icon inside an input tag

I'm trying to put a Font-awesome icon inside an input tag.
This is my HTML code:
<div class="input-group">
<input class="form-control" type="password" placeholder="Password">
<span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
</div>
But that icon is bigger than input box as you can see in this picture:
How can I fix the icon?
Bootstrap 3
Checkout the Bootstrap examples in the Font Awesome documentation:
<div class="input-group margin-bottom-sm">
<span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
<input class="form-control" type="text" placeholder="Email address">
</div>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
<input class="form-control" type="password" placeholder="Password">
</div>
It should work out of the box, so if you still have height differences, check that there is not other CSS stuff that override your input-group-addon height
Working JSFiddle: https://jsfiddle.net/vs0wpy80
Bootstrap 4
Bootstrap 4 introduced some new classes for input groups, we need to use input-group-prepend and input-group-append:
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-envelope-o fa-fw"></i></span>
</div>
<input class="form-control" type="text" placeholder="Email address">
</div>
<div class="input-group mb-3">
<input class="form-control" type="text" placeholder="Email address">
<div class="input-group-append">
<span class="input-group-text"><i class="fa fa-envelope-o fa-fw"></i></span>
</div>
</div>
Working JSFiddle: https://jsfiddle.net/8do9v4dp/5/
input.form-control{
margin-top: 0;
}
In my case it helps
With CSS only
<div class="wrapper">
<input type="text" class="input">
<i class="icon" class="fas fa-some-icon"></i>
</div>
Wrap the input and the icon in a 2 columns grid with this column template: 1fr 0
.wrapper {
display: grid;
grid-template-columns: 1fr 0;
}
Give the icon a relative position from the right:
.icon{
width: 40px;
position: relative;
right: 45px;
font-size: 35px;
line-height: 40px;
cursor: pointer
z-index: 1;
}
Give the input a nice padding on the margin:
.input{
padding-right: 57px;
}
The input will take 100% of the space in the grid and the icon will float atop.
Works well with responsive designs and you can click on the icon.