CSS - Form not scaling down on mobile - html

New coder here. I have a form that is scaled exactly how I want on web, but looks horrible on mobile. The form isn't scaling down. I would like the form to scale down based on a mobile devices width. Any thoughts or suggestions would be much appreciated. I have included the HTML and CSS I have below. Thank you! Also, I would prefer to do this in CSS.
HTML:
<div class="contactForm">
<form id="form" class="topBefore" method="POST" action="#">
<input id="name" type="text" name="name" placeholder="NAME">
<input id="phone" type="tel" name="phone" placeholder="PHONE">
<input id="email" type="email" name="email" placeholder="E-
MAIL">
<textarea id="messagebody" type="text" name="message"
placeholder="MESSAGE"></textarea>
<input id="submit" type="submit" name="send" value="SEND">
</form>
</div>
CSS:
.contactForm {
background-color: #FAFAFA;
width: 100%;
margin: 0 auto;
}
#form {
position: relative;
width: 500px;
margin: 0 auto;
padding-bottom: 20px;
}
input {
width: 470px;
height: 50px;
padding: 0px 15px 0px 15px;
background: transparent;
outline: none;
font-size: 14px;
color: black;
border: solid 2px #dddddd;
border-bottom: none;
letter-spacing: 2px;
background-color: white;
}
input:hover {
background: #f4f4f4;
font-size: 14px;
color: black;
letter-spacing: 2px;
border-color: #e5e5e5;
}
textarea {
width: 470px;
max-width: 470px;
height: 110px;
max-height: 110px;
padding: 15px;
letter-spacing: 2px;
background: transparent;
outline: none;
font-size: 14px;
color: #333;
background-color: white;
border: solid 1px #dddddd;
border: solid 2px #dddddd;
}
textarea:hover {
background: #f4f4f4;
color: black;
}
#submit {
width: 504px;
padding: 0;
margin: -6px 0px 0px 0px;
font-family: 'Lato', sans-serif;
font-size: 14px;
color: #333;
outline:none;
cursor: pointer;
border-top: none;
letter-spacing: 3px;
border: solid 2px #dddddd;
}
#submit:hover {
background-color: #7fbf7f;
color: black;
letter-spacing: 3px;
font-size: 15px;
border-color: #7fbf7f;
}

Try using media queries:
Media queries are useful when you want to apply CSS styles depending on a device's general type (such as print vs. screen), specific characteristics (such as the width of the browser viewport), or environment (such as ambient light conditions). With the huge variety of internet-connected devices available today, media queries are a vital tool for building websites and apps that are robust enough to work on whatever hardware your users have.
Example:
#media screen and (max-width: 699px) and (min-width: 520px)
Put this in your head tag:
<meta name="viewport" content="width=device-width, initial-scale=1">
This means that the browser will (probably) render the width of the page at the width of its own screen. So if that screen is 320px wide, the browser window will be 320px wide, rather than way zoomed out and showing 960px (or whatever that device does by default, in lieu of a responsive meta tag).
For more information:
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
Also: https://css-tricks.com/snippets/html/responsive-meta-tag/

Use mobile query: allows specified CSS to be applied depending on the device https://responsivedesign.is/develop/browser-feature-support/media-queries-for-common-device-breakpoints/
You can use this common device breakpoints.

Related

How to reposition a misplaced cursor/blinker in the textarea?

I have an issue where the cursor/blinker is right in the top left of the textarea with no margin or whatsoever. I don't know what could be causing this, the other inputs are working fine. Here is a screen shot:
I also wanna know how to change that black border color? I would like the border to stay the same when I click on it. I tried using textarea:focus to get rid of it but it's not working.
Lastly I wanna get rid of this whitish background when a form gets auto-completed, I haven't figured out how to get rid:
HTML:
<form class="form appear appear-hidden" method="post">
<h1>Contact Me</h1>
<div class="name-section">
<input type="name" placeholder="Name" required />
<input type="surname" placeholder="Surname" required />
</div>
<input type="email" placeholder="Email" required />
<textarea
class="message"
type="message"
placeholder="Message"
row="4"
required
></textarea>
<input class="submit" type="submit" placeholder="submit" />
</form>
CSS:
.name-section input {
width: 48%;
margin: 5px;
border: 2px solid white;
padding: 10px;
background-color: transparent;
font-weight: 600;
}
form input {
width: 98%;
margin: 5px;
border: 2px solid white;
padding: 10px;
/* background-color: #000; */
background-color: transparent;
font-weight: 600;
color: white;
font-family: 'Poppins', sans-serif;
}
input::placeholder {
font-family: 'Poppins', sans-serif;
color: white;
font-weight: 600;
}
input:focus {
border: 1px solid white;
}
textarea {
min-height: 100px;
background-color: transparent;
color: white;
font-family: 'Poppins', sans-serif;
width: 98%;
margin: 5px;
border: 2px solid white;
resize: none;
font-weight: 600;
}
textarea::placeholder {
color: white;
padding: 10px;
margin: 10px;
font-weight: 600;
}
Thanks in advance for the help.
You have no padding in your Textaria, try this: remove padding from textarea::placeholder and add padding to .message :
textarea::placeholder {
margin: 10px;
font-weight: 600;
}
.message{
padding:10px;
}
To remove the "black-border-color:
input:focus{
outline:solid 3px blue;
}
I didn't understand what you mean by this: "Lastly I wanna get rid of this whitish background when a form gets auto-completed, I haven't figured out how to get rid:"

Unable to decrease the width on using mediaqueries to contact form

Created a contact form. For making it responsive, i have added a mediquery at 768px to decrease the width of the input field. But it ain't changing.
I will attach the code below for your reference
<div class="form-container">
<h1>send us a message</h1>
<form class="form">
<input id="name" type="text" placeholder="Full Name">
<input id="email" type="text" placeholder="E-Mail">
<textarea id="message" cols="30" rows="10" placeholder="Message"></textarea>
<button type="submit"><i class="fa fa-paper-plane" aria-hidden="true"></i>SEND</button>
</form>
</div>
I used SCSS to style my contact form...
.form-container {
margin: 6rem 0;
height: auto;
h1 {
color: $header-main;
text-align: center;
font-family: $primary-font;
text-transform: capitalize;
font-size: 2.3rem;
letter-spacing: 1px;
&:after {
#include shortBorder(10rem, 1rem, 3px, #111);
margin-bottom: 5rem;
}
}
.form {
input[type="text"],
textarea,button {
display: block;
margin: 2rem auto;
width: 600px;
padding: 1rem;
border-radius: 1rem;
border: 1px solid $plane-white;
box-shadow: 2px 3px 3px 3px #ccc;
outline: none;
transition: width 0.2s ease-in-out;
}
input:hover,
textarea:hover {
width: 620px;
}
::placeholder {
color: rgb(155, 148, 146);
font-weight: 900;
font-family: 'Roboto';
}
button {
background-color: $header-main;
color: $plane-white;
width: 140px;
box-shadow: none;
i {
margin-right: 0.5rem;
}
}
}
button:hover {
cursor: pointer;
width: 160px;
}
}
Media query on contact form.. should decrease to 500px from 600px.
#mediaqueries screen and (max-width:768px) {
.form {
width: 500px;
}
}
There are a bunch of things stopping inputs from shrinking.
You have set rows & columns as size parameters on your text area.
<textarea id="message" cols="30" rows="10" placeholder="Message"></textarea>
This acts as width & height in the HTML. You should remove this and set it with CSS.
Depending on the box-model you're using, margin & padding may be ADDING to the overall width of your elements.
Your media queries aren't targeting the correct elements so it's not being applied as you expect.
Base CSS: (you're changing the width of inputs INSIDE a .form)
.form input[type="text"],
.form textarea,
.form button {
width: 600px;
}
media query (you're changing the form, not the inputs)
.form {
width: 500px;
}

Chrome's inspect device is extremely inaccurate?

I am trying to see how the page looks like on a 1366x768 laptop.
In Inspect device it looks perfectly fine:
But on the actual laptop, it looks like this:
So way off! :-/ It is very frustrating as I work on a big screen, and I cannot check it on the small laptop screen every minute.
How comes the page fits perfectly fine in the 1366x768's chrome device inspect but horribly on the actual 1366x768 screen?
Any tip what may be going on?
CSS:
/* Split the screen in half */
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
/* Control the left side */
.left {
left: 0;
}
/* Control the right side */
.right {
right: 0;
}
/* If you want the content centered horizontally and vertically */
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.form {
position: relative;
z-index: 1;
background: #FFFFFF;
color:black;
max-width: 560px;
min-width: 500px;
margin: 0 auto 100px;
padding: 45px;
text-align: center;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
font-family: "Roboto", sans-serif;
outline: 0;
background: #f2f2f2;
width: 100%;
border-color: #eee;
border-width: 1px;
margin: 0 0 15px;
padding: 15px;
box-sizing: border-box;
font-size: 14px;
}
.Forgot-Password {
font-family: "Roboto";
font-size: 17px;
font-weight: normal;
font-style: normal;
font-stretch: normal;
margin-top:15px;
text-align: center;
color: #555556;
}
.form button {
font-family: "Roboto", sans-serif;
outline: 0;
background:#009bf7;
width: 100%;
border: 0;
padding: 15px;
font-size: 17px;
-webkit-transition: all 0.3 ease;
transition: all 0.3 ease;
cursor: pointer;
color:white;
}
.form button:hover,.form button:active,.form button:focus {
background:#0c6ea7
}
.form button:disabled {
background: #dddddd;
}
.form .message {
margin: 15px 0 0;
color: #b3b3b3;
font-size: 12px;
}
.form .message a {
color: #4CAF50;
text-decoration: none;
}
.form .register-form {
display: none;
}
The HTML markup:
<div class="split left">
<div class="centered">
<div style="margin-bottom:60px">
<img class="img-responsive" src="images/fineon.png" alt="Fineon"> </div>
<style>
.navbar {
display: none;
}
.navbar-primary {
display: none;
}
</style>
<div ng-controller="login-controller" ng-init="initLoginPage()">
<div align="center">{{message}}</div>
<form class="login-form form">
<p class="form-login-title" dir="{{pageInfo.direction}}">{{gs("signIn", "Sign in")}}</p>
<hr style="margin-right:370px;border: 1px solid black;" width="15%">
<div class="form-field">
<input dir="{{pageInfo.direction}}" type="text" name="first_name" id="first_name" required ng-model="user.email">
<label for="first_name">{{gs("emailAddress", "Email Address")}}</label>
</div>
<div class="form-field">
<input dir="{{pageInfo.direction}}" type="text" name="first_name" id="first_name" required ng-model="user.password">
<label for="first_name">{{gs("password", "Password")}}</label>
</div>
<button ng-disabled="crisperSessionId == undefined" dir="{{pageInfo.direction}}" ng-click="login()"
type="submit">{{gs("signInButton", "Sign in")}}</button>
<p class="Forgot-Password"><a class="Forgot-Password" href="#/loginForgot">Forgot my password</a></p>
</form>
</div>
</div>
<div class="split right ">
<div class="centered">
<h4 class="Fineon-Exchange">Fineon</h4> <br>
<p class="Export-Receivable-Finance-Marketplace" >Trade Finance & Marketplace</p>
<div style="width:70px; margin-top:50px">
<hr style="border: 1px solid white;">
</div>
</div>
</div>
</div>
Although I am not a hard core programer or any expert, but I think I know what might be wrong. The Inspect Element of your browser shows your page in a 1366x768 resolution. Whereas on the laptop, you are actually viewing the page in 1366-(top and bottom toolbars pixels) x 768-(scroll bar width pixels) resolution. So, the laptop has resolution of 1366x768 but actual displayable resolution is lesser than that and, in my opinion, is the problem.
Now you can either get the actual displayable resolution from the laptop and set as custom resolution in your chrome inspect tool or press f11 on your laptop to see the page in actual 1366x768 resolution.

Django Loop for Window expand/collapse without JQuery

I'm working using Django. I'm new to coding and working on my first project. I do not know JQuery, but I read that it's possible to collapse/expand a window without JQuery.
I followed this webpage: CSS Expand/Collapse Section (A PEN BY Peter Nguyen)
The problem is that I'm trying to use this in a for loop. I'm able to get the layout how I want it, but when I use expand/collapse it only works for the first item in the loop. So, expand/collapse works perfectly on the first iteration of the loop, but not the rest.
HTML
{% for assignment in assignments %}
<form id=form action= "/project/assignments" method='post'>
{% csrf_token %}
<label class=labels><a href="{% url 'project:assg' assignment_id=assignment.id %}">
Assignment: {{assignment.denominator}} - {{assignment.description}} </a></label>
<input id="toggle" type="checkbox">
<label for="toggle" id=labels2>Criteria</label>
<div id=expand>
<section>
<p>[Number] [Name]: Expand content goes here.
</p>
</section>
</div>
<section>
<textarea id=boxes name="review">{{assignments.review}}</textarea>
<input type="hidden" name="Function_id" value={{assignments.id}}>
<input class=save_tasks type="submit" value="Save">
</section>
</form>
CSS
#toggle{
display: none;
visibility:hidden;
}
#labels2{
display: block;
padding: 0.5em;
text-align: center;
background-color: white;
border-top: 4px solid #5e6b39;
border-left: 4px solid #5e6b39;
border-right: 4px solid #5e6b39;
width: 881px;
color: black;
font-size: 20px;
font-weight: bold;
margin: -6px;
margin-top: 5px;
margin-left: 0px;
}
#labels2:hover {
color: #000;
}
#labels2::before {
font-family: Consolas, monaco, monospace;
font-weight: bold;
font-size: 15px;
content: "+";
vertical-align: text-top;
display: inline-block;
width: 20px;
height: 20px;
margin-right: 3px;
background: radial-gradient(ellipse at center, #CCC 50%, transparent
50%);
}
#expand {
height: 0px;
overflow: hidden;
transition: height 0.5s;
background-color: white;
color:black;
font-size: 20px;
border-bottom: 4px solid #5e6b39;
border-left: 4px solid #5e6b39;
border-right: 4px solid #5e6b39;
width: 881px;
padding: 10px;
/* margin-top: -30px; */
}
#toggle:checked ~ #expand {
height: 180px;
}
#toggle:checked ~ #labels2::before {
content: "-";
}
How do I get the collapse/expand division to expand/collapse for all the items in the loop and not just the first one? Is my Django loop incorrect?
Thanks!
The loop is not the problem here.
You only use IDs in your code, and since they are supposed to be unique on a page, the browser uses only the first element that can be found.
The id global attribute defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id
I have adjusted your code once in the necessary places:
.toggle {
display: none;
visibility:hidden;
}
.labels2 {
display: block;
padding: 0.5em;
text-align: center;
background-color: white;
border-top: 4px solid #5e6b39;
border-left: 4px solid #5e6b39;
border-right: 4px solid #5e6b39;
width: 881px;
color: black;
font-size: 20px;
font-weight: bold;
margin: -6px;
margin-top: 5px;
margin-left: 0px;
}
.labels2:hover {
color: #000;
}
.labels2::before {
font-family: Consolas, monaco, monospace;
font-weight: bold;
font-size: 15px;
content: "+";
vertical-align: text-top;
display: inline-block;
width: 20px;
height: 20px;
margin-right: 3px;
background: radial-gradient(ellipse at center, #CCC 50%, transparent 50%);
}
.expand {
height: 0px;
overflow: hidden;
transition: height 0.5s;
background-color: white;
color:black;
font-size: 20px;
border-bottom: 4px solid #5e6b39;
border-left: 4px solid #5e6b39;
border-right: 4px solid #5e6b39;
width: 881px;
padding: 10px;
/* margin-top: -30px; */
}
.toggle:checked ~ .expand {
height: 180px;
}
.toggle:checked ~ .labels2::before {
content: "-";
}
{% for assignment in assignments %}
<form id=form action= "/project/assignments" method='post'>
{% csrf_token %}
<label class=labels>Assignment: {{assignment.denominator}} - {{assignment.description}}</label>
<input id="toggle-{{assignments.id}}" class="toggle" type="checkbox">
<label for="toggle-{{assignments.id}}" class="labels2">Criteria</label>
<div class="expand">
<section>
<p>[Number] [Name]: Expand content goes here.</p>
</section>
</div>
<section>
<textarea id=boxes name="review">{{assignments.review}}</textarea>
<input type="hidden" name="Function_id" value={{assignments.id}}>
<input class=save_tasks type="submit" value="Save">
</section>
</form>
At this point it is important that the input class="toggle" and the label class="labels2" get a unique distinction in the id and the for attribute, so that the click on the label also checks the correct input.
For this you should work with a dynamic value like toggle-{{assignments.id}} - Which I would also highly recommend in principle for all IDs in a loop.
I hope that could help :)

CSS form doesn't appear to have any line breaks

I'm working on styling my website forms and found a tutorial that seems to work up to a point... The tutorial includes code to have hover hints, and this code is causing things to get ugly. Instead of the fields all lining up under one another they seem to be attempting to position themselves one right after another and wrapping all the way down the window.
Here is the code element for the feature in question followed by the CSS...
HTML
<form id="defaultform" class="rounded" name="form2" method="post" action="<?php echo $editFormAction; ?>">
<h3>Contact Form</h3>
<div class="field">
<label for="hostess_fname">First Name:</label>
<input type="text" class="input" name="hostess_fname" value="" id="hostess_fname" />
<p class="hint">Enter your name.</p>
</div>
<div class="field">
<label for="email">Last Name:</label>
<input type="text" class="input" name="hostess_fname" value="" id="hostess_lname" />
<p class="hint">Enter your email.</p>
</div>
<input type="submit" value="Lookup Hostess" />
<input type="hidden" name="Lookup" value="form2" />
CSS
#defaultform {
width: 500px;
padding: 20px;
background: #f0f0f0;
overflow:auto;
/* Border style */
border: 1px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
/* Border Shadow */
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
label {
font-family: Arial, Verdana;
text-shadow: 2px 2px 2px #ccc;
display: block;
float: left;
font-weight: bold;
margin-right:10px;
text-align: right;
width: 120px;
line-height: 25px;
font-size: 15px;
}
#defaultform.input{
font-family: Arial, Verdana;
font-size: 15px;
padding: 5px;
border: 1px solid #b9bdc1;
width: 300px;
color: #797979;
}
.hint{
display: none;
}
.field:hover .hint {
position: absolute;
display: block;
margin: -30px 0 0 455px;
color: #FFFFFF;
padding: 7px 10px;
background: rgba(0, 0, 0, 0.6);
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
}
I just updated the code with more of the HTML from a shorter form that I was trying with the same CSS. I also added some more of the CSS code. I'm getting the same behavior. I'm still confused on selectors and how those are defined and stuff.
I see what you're doing now that you've added your code. It's a pretty simple fix, but hard to catch:
CSS
.field{
clear:both;
}
Here's the jsFiddle