Input fields not showing past certain width - html

This is driving me nuts! I'm hoping someone can help me...I'm pretty new to HTML and CSS.
I've got a sign-up form I'm trying to style on my website. Just first name, email and submit button. I want the two input fields to be on the same line (managed to achieve this), and have them take up 100% of the space. Then when the window shrinks down to mobile, they're on a line each. Mostly everything is working except the fields won't show past a certain width. I've tried a variety of combinations using width=100%, width=auto, width=..px...
Here's a screen shot of what it looks like at the moment:
http://www.marnielefevre.com/new/wp-content/uploads/2016/02/Screen-Shot-2016-02-22-at-4.10.20-pm.png
Here's a snippet of my relevant HTML...
<div class="fielddiv">
<div class="fieldrow"><label>First Name*</label>
<input name="firstname" required="" type="text" /></div>
<div class="fieldrow"><label>Email*</label>
<input name="email" required="" type="email" /></div>
<div style="padding-top: 40px; text-align: center;"><input type="submit" value="SIGN ME UP" /></div>
</div>
...and the CSS
.fielddiv {
text-align: center;
margin: auto;
width: auto;
}
.fieldrow {
display: inline-block;
margin: auto;
text-align: center;
padding-top: 20px;
min-width: 330px;
max-width: 800px;
}
I appreciate any help!!

Without knowing what the other code in your application is doing, I would suggest (blindly) the following;
.fielddiv {
display: flex;
}
.fieldrow {
flex: 1;
text-align: center;
}
.fieldrow:first-child {
margin-right: 20px;
}

Please use below code in your application, it will increase width of textbox for your page:
.fielddiv input[type="text"] {
width:100%;
}
.fielddiv input[type="email"] {
width:100%;
}
OR
.fielddiv input[type="text"] {
width:100% !important;
}
.fielddiv input[type="email"] {
width:100% !important;
}
Hope this will meet your requirement.

Related

Aligning 2 HTML inputs in the same line, when input[type=text] was already defined

I want to align two inputs in the same line.
I used the solutions available here:
http://jsfiddle.net/XAkXg/
http://www.java2s.com/Code/HTMLCSS/Form/inputclassidselectorandpropertyselector.htm
Aligning html inputs on same line
html form - make inputs appear on the same line
Everything would work, but in my case, the input[type=text] has been defined earlier
The CSS code looks pretty much as this:
input {
margin-left: 50px;
}
input[type=text] {
width: 75%;
min-width: 450px;
padding: 12px 20px;
box-sizing: border-box;
outline: none;
border: 1px solid #f7fbff;
background-color: #f7fbff;
}
input[type=text]:focus {
background-color: #c6e2f2;
}
input[type=number]:focus {
background-color: #c6e2f2;
}
and now I have implemented the location feature into my HTML code:
<figure class="fig" id="location">
<label>
<div class="order">1</div>
<p>Location<span class="asterisk">*</span></p>
</label>
<button class="locbtn" id="btn-geolocation">Find my location</button>
<br>
<label for="lat" class="location">Latitude</label>
<input type="text" name="latitude" class="location">
<label for="lon" class="location">Longitude</label>
<input type="text" name="longitude" class="location">
<div style="clear:both;"></div>
</figure>
and accordingly CSS:
.location {
width: 50x;
float: left;
vertical-align: top;
margin: auto;
}
.location input[type=text]{
width: 25px;
display: inline-block;
}
and the effect is, as you can see below:
the input texts don't work, since they have been defined earlier in the code (for entire form).
How can I make the input[type=text] definition also for this section considered?
Moreover, instead of display: inline-block; I tried: display: inline; and float: left; It didn't work either.

Trying to create Google's Advanced Search page

I am trying to create Google's Advanced Search page copy. I am new to programming and I'm having 2 problems. First is that link titled "google search" should be inside the gray bar positioned at the start of the page. Second, I am trying to write css code to reverse positions of texts and their correlated input fields, because I noticed in Google's html that it is also coded in reverse and then corrected from initial position.
Help would be greatly appreciated!
.label {
color: rgb(218, 32, 32);
margin-left: 15px;
padding: 15px;
margin-bottom: 15px;
} */
html, body {
padding: 0;
margin: 0;
font-size: 16px;
}
.navbar {
padding: 20px;
text-align: right;
size: default;
}
.navbar a {
margin: 0 10px;
color:black;
text-decoration: none;
}
.navbar a:hover{
text-decoration: underline;
}
.content {
margin-top:100px;
text-align:center;
}
#textbox {
font-size: large;
height: 30px;
width: 500px;
border-radius: 25px;
}
.graybar{
background-size: 75% 50%;
background: #f1f1f1;
font: 13px/27px Arial,sans-serif;
height: 60px;
width: 100%;
}
#image {
height: 33px;
width: 92px;
margin: 15px;
}
.margin {
margin-left: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
body {
font-family: arial,sans-serif;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Advanced Search</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div class="graybar">
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" id=image>
<div class=navbar>
<a href="index.html">
Google Search
</a>
</div>
</div>
<div class="label">Advanced Search</div>
<h3 style="font-weight:normal">Find pages with...</h3>
<form action="https://google.com/search">
<input class="margin" value autofocus="autofocus" id="xX4UFf" name="as_q" type="text">
<label for="xX4UFf" class="float">all these words:</label>
<br>
<input class="margin" value autofocus="autofocus" id="CwYCWc" name="as_epq" type="text">
<label for="CwYCWc" class="float">this exact word or phrase:</label>
<br>
<input class="margin" value autofocus="autofocus" id="mSoczb" name="as_oq" type="text">
<label for="mSoczb" class=float>any of these words:</label>
<br>
<input class="margin" value autofocus="autofocus" id="t2dX1c" name="as_eq" type="text">
<label for="t2dX1c" class="float">none of these words:</label>
<br>
<input type="submit">
</form>
</body>
</htmL>
Here is how website looks
Assuming that you can change your HTML, flexbox is the solution to both of your issues.
Let's start with your header. You need your image and your text to be both in the grey box, with the image on the left side and the text on the right side.
If you set your header to use display: flex, then you can specify justify-content: space-between to tell the browser to render the child elements with as much space as is possible between them. For two children, that will result in the first child being on the left, and the second child being on the right. If there were more children, they'd be spaced evenly between (eg left, middle, right for three children etc.)
In your case, this would simply require adding the appropriate styling to the .graybar class which is serving as your header:
.graybar {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.graybar {
display: flex;
flex-direction: row;
justify-content: space-between;
background-size: 75% 50%;
background: #f1f1f1;
font: 13px/27px Arial, sans-serif;
height: 60px;
width: 100%;
}
.navbar {
padding: 20px;
text-align: right;
size: default;
}
.navbar a {
margin: 0 10px;
color: black;
text-decoration: none;
}
.navbar a:hover {
text-decoration: underline;
}
#image {
height: 33px;
width: 92px;
margin: 15px;
}
body {
font-family: arial, sans-serif;
}
<div class="graybar">
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" id=image>
<div class=navbar>
Google Search
</div>
</div>
I've left the other styling as you had in your original.
CSS's flexbox is extremely powerful; you can use it for your other issue with the labels/inputs as well, if you can modify your HTML. Looking at the actual Google advanced search page here, your HTML doesn't actually look anything like the original, so I'm assuming you're not restricted to keeping the same HTML as you have in your original post.
Let's instead structure our HTML like this:
<div class="row">
<input type="text" id="allwords" >
<label for="allwords">All these words</label>
</div>
We can now apply display: flex to each row and leverage the flex-direction property to reverse the order of the children so that the label is displayed prior to the input.
.row {
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
}
label {
display: block;
margin-right: 8px;
}
<div class="row">
<input type="text" id="allwords">
<label for="allwords">All these words:</label>
</div>
Generally I wouldn't recommend doing it like this, but I'm equally unsure why you're trying to force inputs before labels in your HTML. :)
For more information about CSS's flexbox, I highly recommend this guide from CSS-Tricks.

Need to align table under image and place another table directly to the right of the image/table column

I'm trying to help my mom out over break making a webform she can use in her office and I'm 100% self taught, so any help is incredibly appreciated. Basically, I'm trying to put an image fully left aligned on the page with a table directly under it, a larger table to the right of the image, and another table to the right of that. Right now, I can't get the first table to be directly under the image- it keeps going left aligned but under the second table (which is much larger than the first)
Here's the code I have so far:
<img src="{{logo}}" style="float:left; height: 80px; width: auto; cursor: pointer; padding: 5px;"><div>
<table style="float:right; background-color:#CCCCCC" border="1"><tbody><tr><td width="125px">#: <u>{{customerID}}</u><br>Sq Ft:<u><input type="text" style="width:50px"></u><br>Linear Ft:<u><input type="text" style="width:50px"></u><br><input type="checkbox">Live Infestation<br><input type="checkbox">Prevention<br><div style="padding-left:20px">Treatment</div><br><br><small><i></i></small><i></i><center><i><small>For Office Use Only</small></i></center></td></tr></tbody></table>
<table style="float:left; margin-left:100px" border="1"><tbody><tr><td style="text-align:center"><b>Termite Inspection Graph & Treatment Specifications</b></td></tr><tr><td style="line-height:1.4"><u>{{customerName}}</u><br><small>Name</small><br><u>{{customerAddress}} {{customerCity}} {{customerState}} {{customerZip}}</u><br><small>Address/Zip Code</small><br><u>{{customerPhone}}, {{customerEmail}}</u><br><small>Phone, Email</small><br><u>{{billingAddress}} {{billingCity}} {{billingState}} {{billingZip}}</u><br><small>Bill To Address</small><br><u><input type="text"></u><br><small>Agreement/Treatment is limited to the one structure listed above unless specified here</small></td></tr></tbody></table><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><table style="float:left; background-color:#D0F0C0" border="1"><tbody><tr><td><small><input type="checkbox"> Sentricon + Termidor <br><input type="checkbox"> Sentricon + Altriset<br><input type="checkbox"> Termidor Only<br><input type="checkbox"> Altriset Only<br><input type="checkbox"> Sentricon Only</small></td></tr></tbody></table></div>
For reference, it's the last chunk of code I'm having trouble with. Side note, the software she is using does not allow me to edit the CSS, so everything I do needs to be within the HTML code itself.
All help appreciated!!
If you have the ability to use css in the HTML page within tags this should work for you:
#media part of the CSS is to make the columns stack instead of sit next to each other on a narrow screen such as a phone; make sure to do testing and tweaking with the actual content to see if it behaves as intended.
<html>
<head>
<style>
body { /*display: inline-block;*/ }
#image { width: 25%; margin: 15px;}
#righttable { float: left; width: 20%; margin: 10px;}
#lefttable { float: left; width: 20%; margin: 10px;}
#midtable { float: left; width: 50%; margin: 10px;}
div.row { width: 100%; }
#media screen and (max-width: 600px) {
#image { width: 100%; }
#righttable { width: 100%; }
#lefttable { width: 100%; }
#midtable { width: 100%; }
}
</style>
</head>
<body>
<div class="row">
<img id="image" src="{{logo}}" style="height: 80px; width: auto; cursor: pointer; padding: 5px;"></div>
<div class="row">
<div id="lefttable">
<table style="background-color:#D0F0C0" border="1"><tbody><tr><td><small><input type="checkbox"> Sentricon + Termidor <br><input type="checkbox"> Sentricon + Altriset<br><input type="checkbox"> Termidor Only<br><input type="checkbox"> Altriset Only<br><input type="checkbox"> Sentricon Only</small></td></tr></tbody></table></div>
<div id="midtable"><table style=" /*margin-left:100px*/" border="1"><tbody><tr><td style="text-align:center"><b>Termite Inspection Graph & Treatment Specifications</b></td></tr><tr><td style="line-height:1.4"><u>{{customerName}}</u><br><small>Name</small><br><u>{{customerAddress}} {{customerCity}} {{customerState}} {{customerZip}}</u><br><small>Address/Zip Code</small><br><u>{{customerPhone}}, {{customerEmail}}</u><br><small>Phone, Email</small><br><u>{{billingAddress}} {{billingCity}} {{billingState}} {{billingZip}}</u><br><small>Bill To Address</small><br><u><input type="text"></u><br><small>Agreement/Treatment is limited to the one structure listed above unless specified here</small></td></tr></tbody></table><br></div>
</div>
<div id="righttable">
<table style=" background-color:#CCCCCC" border="1"><tbody><tr><td width="125px">#: <u>{{customerID}}</u><br>Sq Ft:<u><input type="text" style="width:50px"></u><br>Linear Ft:<u><input type="text" style="width:50px"></u><br><input type="checkbox">Live Infestation<br><input type="checkbox">Prevention<br><div style="padding-left:20px">Treatment</div><br><br><small><i></i></small><i></i><center><i><small>For Office Use Only</small></i></center></td></tr></tbody></table></div>
</body>
</html>
Update: this works by cheating the system and just putting the top image as the first row of the table that needs to be directly under it

Media query not working on HTML form

I would like the font size for my form label and input fields to scale down from 18px to 10px when the browser width reaches 1460px or less.
I read that it is not possible to get fonts to automatically 'scale down' as such when the browser width decreases, and that I would need to use media queries instead.
Therefore I have put a media query at the top of my style tags asking the font size for my label and input to display at 10px when the screen size is 1460px, but it doesn't seem to work. The rest of my code is working fine however, so it must be something to do with the way I am coding my media query.
If someone could offer some help that would be much appreciated.. my code is pasted below.
#media only screen and (max-width: 1460px) {
label input {
font-size: 10px;
}
}
* {
box-sizing: border-box;
}
input[type=text],
select {
width: 95%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 3px;
resize: vertical;
transition: 0.3s;
outline: none;
font-family: Typ1451-Medium;
font-size: 18px;
margin: 7px;
}
input[type=text]:focus {
border: 1.25px solid #ea0088;
}
label {
padding: 21px 12px 12px 12px;
margin-left: 5px;
display: inline-block;
font-family: Typ1451-Medium;
font-size: 18px;
color: #999;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
margin: 2.5% 20% 0 20%;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
.left,
.right {
width: 50%;
}
form {
display: flex;
}
<div class="container">
<form action="signin.php" method="post">
<div class="left">
<div class="row">
<div class="col-25">
<label for="fname">First Name</label>
</div>
<div class="col-75">
<input type="text" id="fname" name="firstname" placeholder="* Please complete">
</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="col-25">
<label for="lname">Last Name</label>
</div>
<div class="col-75">
<input type="text" id="lname" name="lastname" placeholder="* Please complete">
</div>
</div>
</div>
</form>
</div>
Your selector — label input — doesn't match any elements in your HTML.
None of your input elements are descendants of your label elements.
Perhaps you meant label, input to select label elements and input elements. If so, then it still wouldn't work because you define the input font-size with a more specific selector later on (and the most specific selector wins the cascade) and the label in a similar way (it doesn't have a more specific selector, but when selectors are equal, the last one wins the cascade).
Actually, you CAN scale fonts up or down with the viewport size. There is a method with calc() and vw units:
Basically you do something like font-size: 3vw and then set max and min font sizes.
Here is a link to the calculation on Smashing Magazine. The rest of the article is pretty interesting, too.
You can extend this even further and optimize the font size with media queries.
Have fun! :)

Using something like break in CSS

Since not everyone will be browsing the web on a computer, I need to use CSS to adapt to different screen sizes. I am working on the front-end part of the registration form, register.php. The issue is, on the computer the field name and field input position nicely. However, for the smaller screens (maximum width of 520px) I need the field name and field input to be on
top/bottom of each other, field input being on top of its field name.
HTML:
#formBody{
border-radius: 10px;
background-color: #3385ff;
padding-left: 5%;
padding-right: 5%;
padding-top: 0.5em;
padding-bottom: 0.5em;
width: 90%;
max-width: 50em;
margin: auto;
}
.field{
margin: auto;
width: 66.6%;
}
.fieldDescription{
width: 33%;
color: black;
font-size: 1.2em;
}
.fieldInput{
width: 33%;
margin: auto;
}
.input{
width: 100%;
background-color: #e6f0ff;
border-style: none;
}
CSS:
<div id="formBody">
<table>
<form>
<tr class="field">
<td class="fieldDescription">
<p>First Name:</p>
</td>
<td class="fieldInput">
<input class="input" name="firstname" type="text">
</td>
</tr>
</form>
</table>
</div>
I used an HTML table to give each field its own space. I used the <tr> element to make a row for each field, and used two <td>element to put the field name and field input in its own column. This works great for a computer screen, but it doesn't work on the smaller screen (like a smartphone). If I use something like <p class="fieldDescription">Fist Name:</p> for the field name, then <input class="fieldInput" name="firstName" type="text"> for the field input, then I'm hard coding only for small screens.
Is there a way to satisfy both screen sizes, without having to hard code it either way? I would prefer to not use Javascript. I would like to do it CSS.
Click here for the HTML
Click here for the CSS
(both are on gist.github.com)
I'll highly recommend you to use valid and semantic form elements like label and fieldset. But to address your question:
#media screen and (max-width: 520px) {
#mainContainer {
border-radius: 5px;
}
#formBody {
border-radius: 0px;
}
.fieldDescription,
.fieldInput {
width: 100%;
display: inline-block;
}
.fieldDescription p {
margin-bottom: 0;
}
}
A Few Things to tell:
What you are looking for is making responsive designs. You should take a look to Media Queries
I Highly recomend not to use tables in cases like this, just use a table when u REALLY need a table
Here is a LIVE EXAMPLE with the HTML and CSS code of what you want to do. (Resize the browser to see).
Try not to style your forms with <p> <tr> <td> and so on... Use <label> instead.
Hope this work.
#media + display:block; should be basicly what you need:
#media screen and (max-width: 520px) {
table,/* to spray whole space as block does */
tbody,/* because it is there even not in the code :) */
tr,/* this too must be a block */
td /* goal to reach to start from */{
display: block;
}
}
#media screen and (max-width: 520px) {
table,
tbody,
tr,
td {
display: block;
text-align: center;
}
}
/* copy to match snippet size */
#media screen and (max-width: 700px) {
table,
tbody,
tr,
td {
display: block;
text-align: center;
}
}
/* warning */
legend {
color: tomato;
}
<div id="formBody">
<form>
<fieldset>
<legend>Put that form around the table not in between table & tr tags !!</legend>
<table>
<tr class="field">
<td class="fieldDescription">
<p>First Name:</p>
</td>
<td class="fieldInput">
<input class="input" name="firstname" type="text">
</td>
</tr>
</table>
</fieldset>
</form>
</div>
And demo including your style