I can't alter the width of an item through CSS - html

I'm a beginner in front-end development and I'm working on a survey website. My website has a lot of input fields and I want to alter their width per their nature but I'm not able to do it for some reason. The item is not in a flex container and yet changing the value in the width attribute makes no difference.
I'm trying to change the width of my input field in my customerAge div to make it small enough to just hold 2 digits.
This is my codepen link: https://codepen.io/omaroz92/full/VBWbae/
I'd appreciate a detailed explanation on why changing the value in the width attribute made no difference.
body {
background-color: #98AFC7;
}
#title {
text-align: center;
font-family: Arial, Times, serif;
font-style: oblique;
color: white;
}
#screen-belly {
background-color: rgb(250, 250, 250);
margin: 0 auto;
border-radius: 4px;
width: 75%;
max-width: 1000px;
padding: 10px;
padding-top: 20px;
}
p {
text-align: center;
font-family: monospace, serif;
font-size: 15px;
}
.container {
width: 75%;
max-width: 600px;
margin: 0 auto;
}
.row {
display: flex;
}
.customerAge {
width: 100px;
}
input {
flex: 1;
height: 20px;
min-width: 0;
padding: 5px;
margin: 10px;
border: 1px solid #c0c0c0;
border-radius: 2px;
}
<h1 id="title">Survey Form</h1>
<div id="screen-belly">
<p>Please take the short Survey to hep us improve our services</p>
<div class="container">
<div class="row">
<input autofocus type="text" name="name" id="name" placeholder="First name" required>
<input type="text" name="name" id="name" placeholder="Last Name" required>
</div>
<div class="row">
<input type="text" name="email" id="email" placeholder="e-Mail address" required>
</div>
<div class="customerAge">
<input type="number" name="age" id="Age" placeholder="age" required>
</div>
</div>
</div>

You've wrapped the Age input in customerAge div. But you've applied the width property to the parent, not to the input.
You can try this in your css code:
.customerAge input#Age {
width: 31px;
}
And you can change 31px to the value you want.
If you are confused, the input#Age after .customerAge, means: the input field with Age id that is inside of the customerAge class.

Related

I tried to make responsive web using max-width but im stuck please help me

I'm totally new in HTML and try to make a website all is good but when I restore down the browser all the element will sepperate. Watched youtube about max-width but still not working and I'm stuck like 3 day.
This is my code for a form, the form was in a div class named bothForm and requestQuotationForm
.requestQuotationForm{
position: relative;
left: 800px;
top: -305px;
background: rgba(41, 29, 0,0.5);
border-radius: 10px;
padding: 20px;
color: white;
font-family: 'PT Sans', sans-serif;
font-size: 14px;
max-width: 300px;
}
.mainBody {
width: 1500px;
margin : 0 auto;
}
#media screen and (max-width: 500px) {
.mainBody {
width: 95%;
}
.bothForm {
max-width: 100%;
}
}
<div class = "requestQuotationForm">
<form>
<p class="requestQuotationText"><center>Request quotation </center></p>
<label for = "ICNumber">IC Number</label>
<input type="text" onfocus="this.value=''" id= "ICNumber" name="ICNumber" value = "Enter your IC number"> <br> <br>
<label for = "FlatNumber">Plate Number</label>
<input type="text" onfocus="this.value=''" id= "FlatNumber" name="FlatNumber" value = "Enter your plate number"> <br> <br>
<label for = "carModel">Plate Number</label>
<input type="text" onfocus="this.value=''" id= "carModel" name="carModel" value = "Enter your car model"> <br> <br>
<label for ="chooseInsurance">Choose insurance</label>
<select class ="chooseInsurance">
<option value = "Etiqa">Etiqa</option>
<option value = "Ikhlas">Ikhlas</option>
<option value = "AXA">AXA</option>
</select>
<label for = "PhoneNumber">Phone Number</label>
<input type="text" onfocus="this.value=''" id= "PhoneNumber" name="PhoneNumber" value = "Enter your phone number"> <br> <br>
<input type="button" value="Submit" id="RequestQuotationButton" >
</form>
</div>
I've made an example with responsive blocks (similar to forms from your website).
You can check it out by running Code Snippet -> Full Page and try resizing the window.
Hope this is what you are looking for.
I have used CSS Flex technology to achieve responsiveness + #media max-width queries (to change title font-size and form width)
.requestRoadtaxPrice {
background: green;
height: 300px;
}
.requestQuotationForm {
background: red;
height: 600px;
}
.form {
margin: 20px;
width: 350px;
}
.mainBody {
width: 100%;
margin: 0 auto;
}
.form_container {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.title {
text-align: center;
font-size: 40px;
}
#media screen and (max-width: 900px) {
.title {
font-size: 30px;
}
.form {
width: 300px;
}
}
#media screen and (max-width: 700px) {
.form {
width: 400px;
}
}
<div class="mainBody">
<h2 class="title">Welcome to Agency Abu Hanifah Webpage!</h2>
<div class="form_container">
<div class="requestRoadtaxPrice form">
<form></form>
</div>
<div class="requestQuotationForm form">
<form></form>
</div>
</div>
</div>
You are using absolute values with px thus your form gets pushed off the screen/window when it's small.
You can use something like this:
.requestQuotationForm{
position: relative;
left: 30%;
top: 10%;
background: rgba(41, 29, 0,0.5);
border-radius: 1em;
padding: 2em;
color: white;
font-family: 'PT Sans', sans-serif;
font-size: 1em;
width: 40%;
}
Read more on this here: https://css-tricks.com/quick-css-trick-how-to-center-an-object-exactly-in-the-center/

CSS Contact Form not being responsive

I have created a Contact Form, everything looks somewhat fine, the way I want it but having issues. The Form is not being responsive when re-sizing/scale the browser down. I have messed around, I think a little too much with the code to the point that I have no clue what i'm doing or have done. I'm about to lose my mind!
When I re-size the browser, the labels go outside of the container it's in. The submit button is also not centering even when I try margin: 0 auto;
I will post the HTML & CSS along with my CodePen below. Thanks for any help!
CodePen https://codepen.io/vCoCo/pen/MLReKK?editors=1100
HTML
<section id="contact">
<div class="container">
<form id="contactForm" action="contactform.php" method="post">
<h2> Get In Touch! </h2>
<div class="details">
<label for="firstName"> First Name </label>
<input type="text" id="firstName" name="firstName" placeholder="Enter First Name..." required>
</div>
<div class="details">
<label for="lastName"> Last Name </label>
<input type="text" id="lastName" name="lastName" placeholder="Enter Last Name..." required>
</div>
<div class="details">
<label for="email"> Email </label>
<input type="email" id="email" name="email" placeholder="Enter Email..." required>
</div>
<div class="details">
<label for="textMessage"> Message </label>
<textarea id="textMessage" name="textMessage" placeholder="Enter Message In Here..." required></textarea>
</div>
<input type="submit" value="Submit Message">
</form>
</div>
</section>
CSS
body{
background-color: grey;
}
/**** GLOBAL ****/
.container{
max-width: 80%;
margin: auto;
overflow: hidden;
border: 2px solid white;
}
/********** CONTACT FORM **********/
#contact{
max-width: 80%;
margin: 100px auto;
border: 1px dashed orange;
}
#contact .container{
width: 500px;
margin: 100px auto;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
#contactForm{
margin: 0 auto;
}
#contactForm h2{
text-align: center;
margin-bottom: 10px;
}
.details{
max-width: 500px;
margin: 15px;
padding: 10px;
border: solid 1px #ff0000;
overflow: hidden;
}
label{
margin-bottom: 10px;
}
input[type=text], input[type=email]{
width: 400px;
padding: 12px 20px;
margin: 8px 0;
border: 2px solid;
border-radius: 4px;
}
input[type=submit]{
width: 200px;
padding: 10px 20px;
color: #fff;
background-color: #000;
border: 2px solid #fff;
border-radius: 10px;
font-family: inherit;
cursor: pointer;
}
textarea{
width: 300px;
height: 200px;
resize: none;
font-size: 16px;
}
#contactForm textarea::placeholder{
font-size: 16px;
}
You have a problem with the width of several elements, you're setting fixed widths and it repercusses on mobile resolutions, also with the overflow of the container it make the childs to hide inside the parent.
A good solution for a responsive mode is to set the widths to 100% of the parent and setting a max width for greater resolutions.
I made a fork of your Codepen.
Important: most of the problem also is, make sure to set the box-sizing of global elements. i.e. * { box-sizing: border-box;}
Hope this helps.
Codepen https://codepen.io/devlumberjack/pen/rPbMzr?editors=1100

Form Input element sizing

I want to make a two column layout form. but I am getting a problem i.e input elements of form are not equally divided in size(width) and also responsive.
I want it to be responsive and also equally width with gap between them.
Attached Code Below
#import url('https://fonts.googleapis.com/css?family=Montserrat');
h2 {
font-family: Montserrat;
font-size: 3em;
line-height:50px;;
}
form {
width:70%;
margin: 10% auto;
}
input[type="text"]{
display: block;
height: 30px;
width: 47%;
float:left;
}
form > input:nth-child(3){
margin-left: 31px;
margin-right:0;
}
textarea {
width:100%;
box-sizing: border-box;
margin: 30px 0;
}
input[placeholder="Name"],input[placeholder="E-mail"]{
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
}
textarea[placeholder="Message"]{
letter-spacing:5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,textarea:focus {
outline:none;
}
<section id="contact-page">
<form>
<h2>Contact Us</h2>
<input type="text" placeholder="Name">
<input type="text" placeholder="E-mail">
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>
Try This
<form>
<div class="col-sm-6 col-xs-12 form-group">
<input type="text" name="" class="form-control">
</div>
<div class="col-sm-6 col-xs-12 form-group">
<input type="email" name="" class="form-control">
</div>
<div class="col-sm-12 form-group">
<textarea name="" cols="" rows="10" class="form-control"></textarea>
</div>
<form>
Just add this to your form section and also add the required files for botstrap
1- Jquery
2- Bootsrap.min.css
Bootsrap Documentation
JS fiddle
Remove float for inputs and add a wrapper div as below
h2 {
font-family: Montserrat;
font-size: 3em;
line-height:50px;;
}
form {
width:70%;
margin: 10% auto;
}
#email{
display: block;
height: 30px;
width: 30%;
float:left;
margin:0;
margin-left:2%;
}
#name{
display: block;
height: 30px;
width: 30%;
}
form > input:nth-child(3){
margin-left: 31px;
margin-right:0;
}
textarea {
width:100%;
box-sizing: border-box;
margin: 30px 0;
}
input[placeholder="Name"],input[placeholder="E-mail"]{
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
}
textarea[placeholder="Message"]{
letter-spacing:5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,textarea:focus {
outline:none;
}
<section>
<form>
<h2>Contact Us</h2>
<div style="display: flex; justify-content: space-between;">
<input type="text" placeholder="Name">
<input type="text" placeholder="E-mail">
</div>
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>
If possible use Bootstrap with Grids, if not easy solution will be add div like this:
Bootstrap Grid LinK: https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
<form>
<h2>Contact Us</h2>
<div>
<input type="text" placeholder="Name">
</div>
<div>
<input type="text" placeholder="E-mail">
</div>
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
Your selector form > input:nth-child(3) is a problem because it counts the h2 as the first, making the email-input the third and adding left-margin to it.
Once that is gone, I added margin: 30px 0; to the existing input['text'] selector, to match what you had applied to the textarea, and you may want different values, but everything is lined up and evenly spaced:
JS Fiddle
Example :
h2 {
font-family: Montserrat;
font-size: 3em;
line-height:50px;;
}
form {
width:70%;
margin: 10% auto;
}
#email{
display: block;
height: 30px;
width: 30%;
float:left;
margin:0;
margin-left:2%;
}
#name{
display: block;
height: 30px;
width: 30%;
float:left;
}
form > input:nth-child(3){
margin-left: 31px;
margin-right:0;
}
textarea {
width:100%;
box-sizing: border-box;
margin: 30px 0;
}
input[placeholder="Name"],input[placeholder="E-mail"]{
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
}
textarea[placeholder="Message"]{
letter-spacing:5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,textarea:focus {
outline:none;
}
<section id="contact-page">
<form>
<h2>Contact Us</h2>
<input type="text" placeholder="Name" id='name'>
<input type="text" placeholder="E-mail" id='email'>
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>
Well ! i tried to figure out your problem and just gave a try to make it responsive.
Max-width and Max-height
The max-width property is used to set the maximum width of an element.
The max-width can be specified in length values, like px, cm, etc., or in percent (%) of the containing block, or set to none (this is default. Means that there is no maximum width).
Using max-width instead, in this situation, will improve the browser's handling of small windows. similarly for height
You can remove margin: 0 auto; if you want don't want your content centred
#import url('https://fonts.googleapis.com/css?family=Montserrat');
h2 {
white-space: auto;
font-family: Montserrat;
font-size: 3em;
line-height: 50px;
;
}
form {
width: 70%;
margin: 0 auto;
}
input[type="text"] {
max-height: 30px;
max-width: 47%;
}
textarea {
max-width: 100%;
box-sizing: border-box;
margin: 10px 0;
}
input[placeholder="Name"],
input[placeholder="E-mail"] {
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
margin-bottom: 10px;
}
textarea[placeholder="Message"] {
letter-spacing: 5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,
textarea:focus {
outline: none;
}
<section id="contact-page">
<form>
<h2>Contact Us</h2>
<input type="text" placeholder="Name">
<input type="text" placeholder="E-mail">
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>

Difference between font-size 190% and 200%

When I set the font-size: 200%
When I set the font-size: 190%:
I tested it on the firefox and I found it.
I don't know why "font-size: 200%" makes these differences...
body {
font-size: 190%;
font-family: sans-serif;
}
input {
width: 300px;
padding: 5px 5px 12px 5px;
font-size: 25px;
border-radius: 5px;
border: 1px gray solid;
}
#wrapper {
margin: 0, auto;
width: 1000px;
}
lable {
width: 100px;
float: left;
}
.element-container {
margin-bottom: 5px;
}
<div id="wrapper">
<div class="element-container">
<lable for="email">Email</lable>
<input type="text" name="email" id="email" placeholder="input the email here">
</div>
<div class="element-container">
<lable for="phone">Telephone</lable>
<input type="text" name="phone" id="phone" placeholder="input the phone number here">
</div>
</div>
you can give it a padding-right of 5% which will move the box away from the text.
lable {
width: 100px;
float: left;
padding-right:5%;
}

How to move form to center of page

I am creating a registration form and am wondering how can I move the whole form to the center of the page? right now its all on the left side of the container, I want it to look a bit something like this: https://id2.s.nfl.com/fans/register?returnTo=http%3A%2F%2Fweeklypickem.fantasy.nfl.com%2F
#Regcontainer {
width: 1200px;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> </h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label>FIRST NAME</label>
<input type="text" name="FName" />
<label>LAST NAME</label>
<input type="text" name="SNAME" />
<br/>
<label>EMAIL ADDRESS</label> <input id="email" name="email" type="text" />
<BR/>
<label>CREATE YOUR USERNAME</label> <input name="uname" type="text" /> <br/>
<label>CREATE PASSWORD</label> <input name="pass" type="password" />
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Here is the solution I came up with... but what does it do?
#Registercontainer needs to be on the center of the page. Meaning, your fixed with of 1200px is not going to work too well. I took the approach of reducing the size of your from container to give a better look and feel like this:
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
/* ... your other properties here ... */
}
Another note, your <label> needs the for attribute as specified in this article.
Let me know if you have any questions, FYI there are many ways to make this work for you.
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
padding: 15px;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> Register With NackStack</h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label for="fname">FIRST NAME</label>
<input type="text" name="FName" id="fname" />
<br/>
<label for="sname">LAST NAME</label>
<input type="text" name="SNAME" id="sname" />
<br/>
<label for="email">EMAIL ADDRESS</label>
<input id="email" name="email" type="text" />
<br/>
<label for="uname">CREATE YOUR USERNAME</label>
<input name="uname" type="text" id="uname" />
<br/>
<label for="password">CREATE PASSWORD</label>
<input name="pass" type="password" id="password"/>
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Add margin:auto and a fixed width to the parent <div>. Example:
<div id="Registercontainer" style="margin-left:auto;margin-right:auto;width:250px">
Fiddle:
https://jsfiddle.net/mwatz122/g9ay26x3/
#Registercontainer {
text-align: center;
}
Please try this. It might help.
Put your form within a <div> like this:
<div align="center">
<!-- insert code here -->
</div>
Then in the CSS, add
form {
text-align: left;
}