How to fit text box into minimize screen? - html

I have created a web form to allow users to fill in information about books they want to search. I just want to know how to automatically fit a text box into the form when I split my screen to the side of my laptop. On fullscreen it would fit just fine. For the details of Author's name, the text boxes should also be in a single line. But when i split screen, the boxes lump together. Is this a limitation in css?
Screenshot of web form in split screen
Screenshot of web form in fullscreen
<style>
#rcorners2 {
border-radius: 25px;
border: 1px solid;
padding: 10px;
width: 400px;
height: 5px;
}
</style>
<style>
#rcorners3 {
border-radius: 25px;
border: 1px solid;
padding: 10px;
width: 100px;
height: 5px;
}
</style>
<div class="column" style="background-color:#6EFFFF;">
<center>Enter Advanced Search Terms: </center><br>
<center> Keywords: <br>
<input type="text" id="rcorners2" name="keyword" size="50"><br />
Title Words: <br>
<input type="text" id="rcorners2" name="titlewords" size="50"><br />
<br>
<br>
Author's Name: <br></center>
<br>
<td>
<tr>
<center>
Last name
<input type="text" id="rcorners3" name="titlewords" size="10">
First name
<input type="text" id="rcorners3" name="titlewords" size="10">
Initial
<input type="text" id="rcorners3" name="titlewords" size="10">
<center>
</tr>
</td>

It seems that you are beginner in web development. I will suggest you to use percentage but not pixels for width. As you asked, that's not a limitation in css. The width will remain the same in any device or resolution from which you access the page. If you want to make your site responsive, use only percentage in width and pixels only in height.
Another suggestion : You're not needed to use two style elements. You can include both the classes in one style.
<style>
#rcorners2 {
border-radius: 25px;
border: 1px solid;
padding: 10px;
width: 100%;
height: 5px;
}
#rcorners3 {
border-radius: 25px;
border: 1px solid;
padding: 10px;
width: 100%;
height: 5px;
}
</style>
<div class="column" style="background-color:#6EFFFF;">
<center>Enter Advanced Search Terms: </center><br>
<center> Keywords: <br>
<input type="text" id="rcorners2" name="keyword"
size="50"><br />
Title Words: <br>
<input type="text" id="rcorners2" name="titlewords"
size="50"><br />
<br>
<br>
Author's Name: <br></center>
<br>
<td>
<tr>
<center>
Last name
<input type="text" id="rcorners3" name="titlewords"
size="10">
First name
<input type="text" id="rcorners3" name="titlewords"
size="10">
Initial
<input type="text" id="rcorners3" name="titlewords"
size="10">
<center>
</tr>
</td>
I hope this will help you.

This isn't a limitation of css per say. You have not given your HTML enough structure or css to properly format the inputs as the size changes.
There are a lot of ways to tackle this. Is this for a homework assignment?
In your css you are setting a static size which will overflow the container that is housing the input field. If you change that to a percentage it will go a long way.
width: 80%;
I would suggest spending some time over at w3 or some other website and learn a little about responsive layouts.
https://www.w3schools.com/html/html_layout.asp
https://www.w3schools.com/html/html_responsive.asp

Try This:
#rcorners2 {
border-radius: 25px;
border: 1px solid;
padding: 10px;
width: 90%;
height: 5px;
}
#rcorners3 {
border-radius: 25px;
border: 1px solid;
padding: 10px;
width: 25%;
height: 5px;
}
<div class="column" style="background-color:#6EFFFF;">
<center>Enter Advanced Search Terms: </center><br>
<center> Keywords: <br>
<input type="text" id="rcorners2" name="keyword" size="50"><br />
Title Words: <br>
<input type="text" id="rcorners2" name="titlewords" size="50"><br />
<br>
<br>
Author's Name: <br></center>
<br>
<td>
<tr>
<center>
Last name
<input type="text" id="rcorners3" name="titlewords" size="10">
First name
<input type="text" id="rcorners3" name="titlewords" size="10">
Initial
<input type="text" id="rcorners3" name="titlewords" size="10">
</center>
</tr>
</td>
</div>

Related

Trouble with sliding textarea

Help me please with sliding textarea. If i add icon of wrong field, my textarea goes left. Some screenshots:
And some code:
<div class="signup">
<center>
<h1>Форма регистрации</h1>
<p>Для получения информации и участия в акциях информация должна быть правдивой</p>
<form name="registerform">
<p>
<input type="text" placeholder="Ваше имя" id="user_login" class="input" size="20" /> <span id="user_login_result"></span>
</p>
<p>
<input type="email" placeholder="Ваш Email" id="user_email" class="input" size="20" /> <span id="user_email_result"></span>
</p>
</form>
</center>
</div>
css:
#user_login.input, #user_email.input {
border: 1px solid #ccc;
width: 50%;
border-radius: 0;
}
code when icon shows:
<p>
<input type="text" placeholder="Ваше имя" id="user_login" class="input" size="20" /> <span id="user_login_result"><img src="un-available.png" /></span>
</p>
<center> tags are obsolete - you should use margin-left and margin right instead
here is a jsfiddle
.signup {
width: 100%;
}
#user_login.input,
#user_email.input {
border: 1px solid #ccc;
width: 50%;
border-radius: 0;
}
h1,
.text {
text-align: center;
}
form {
margin-left: 24%;
margin-right: 24%, text-align: center;
}
<div class="signup">
<h1>Форма регистрации</h1>
<p class="text">Для получения информации и участия в акциях информация должна быть правдивой</p>
<form name="registerform">
<p>
<input type="text" placeholder="Ваше имя" id="user_login" class="input" size="20" /> <span id="user_login_result"><img src="http://www.iberia.com/ibcomv3/rbrand/img/content/ico-x.gif" width="10px" height="10px"></span>
</p>
<p>
<input type="email" placeholder="Ваш Email" id="user_email" class="input" size="20" /> <span id="user_email_result"></span>
</p>
</form>
</div>
Ofcourse your element will move to left because when you put your image, the new element needs some space for its own existence. Hence CSS pushes your input element to left to make some room.
A straight forward answer is that you need to pre-define where your elements will appear and have the space reserved for them. One way is to convert your form into a table and make your table fixed and assign width to each cell. Sample below.
Since you did not provide us with CSS, I made a sample JSFIDDLE that might not look exactly like yours but its close.
You will notice that:
When you click the input box, a new element with some text "icon" appears, but it does not move the element to the left. Instead it takes space from right.
So what have I done here:
HTML
<div class="signup">
<center>
<h1>Форма регистрации</h1>
<p>Для получения информации и участия в акциях информация должна быть правдивой</p>
<table>
<form name="registerform">
<p>
<tr><td>
<input type="text" placeholder="Ваше имя" id="user_login" class="input first" size="20" /> <span id="user_login_result"></span>
</td></tr>
</p>
<p>
<tr><td>
<input type="email" placeholder="Ваш Email" id="user_email" class="input first" size="20" /> <span id="user_email_result"></span>
</td></tr>
</p>
</form>
</table>
</center>
</div>
CSS
table {
table-layout: fixed;
width: 200px;
}
table .first {
width: 60%;
display: inline-block;
}
table .second {
width: 20%;
display: inline-block;
}
I have made your form into a table and have given it a width that it cannot exceed. I have also told the elements that they can only take 'x' amount of space and do not touch the other one.
Don't worry about the javascript. Its just there to dynamically put the "image" element as soon as you focus on the input element.

html form checkbox not positioning as expect

hello i'm creating a login form .but my check box and term text related to it not positioning correctly .i have add <br> tag but no effect .i tried clearfix it's not work either.here is the fiddle preview.
this is my html code
<div class="mainlog">
<form>
<label class="la" for="xname">Name</label><input name="xname" class="in" value="" type="text"><br>
<label class="la" for="xemail">Email</label><input name="xemail" class="in" value="" type="text"><br>
<label class="la" for="xpass">password</label><input name="xpass" class="in" value="" type="text"><br>
<label class="la" for="xpasscon">confirm</label><input name="xpasscon" class="in" value="" type="text"><br>
<input type="checkbox" name="term"/><label class="lb" for="term" >I have read and agree to the Terms of Use and the Privacy Policy</label><br>
<input type="submit" value="Sign Up" />
</form>
</div>
Wrap the checkbox and text in a div and float it left. Avoid the usage of <center> it will not be supported in HTML5
.mainlog {
width: 450px;
height: 250px;
border: 5px solid #DBDBDB;
border-radius: 5px;
padding: 20px;
}
.in {
padding: 8px;
border: 1px solid #DFDFDF;
width: 250px;
float: left;
margin-bottom: 10px;
border-radius: 5px;
}
.la {
width: 120px;
float: left;
text-align: left;
text-transform: uppercase;
color: #6B6B6B;
clear: both;
}
.lb {} .checkbox {
float: left;
}
}
<center>
<div class="mainlog">
<form>
<label class="la" for="xname">Name</label>
<input name="xname" class="in" value="" type="text">
<br>
<label class="la" for="xemail">Email</label>
<input name="xemail" class="in" value="" type="text">
<br>
<label class="la" for="xpass">password</label>
<input name="xpass" class="in" value="" type="text">
<br>
<label class="la" for="xpasscon">confirm</label>
<input name="xpasscon" class="in" value="" type="text">
<br>
<div class="checkbox">
<input type="checkbox" name="term" />
<label class="lb" for="term">I have read and agree to the Terms of Use and the Privacy Policy</label>
<br />
</div>
<input type="submit" value="Sign Up" />
</form>
</div>
</center>
Quick fix: wrapp checkbox with it's label into div with class "width".
Then in CSS add ".width" with styles: width:100%; clear:both.
.width{
width:100%;
clear:both;
}
Demo
I did a minor change in your code and it looks good to me. I am not sure if this is what you were looking for.
Please check the fiddle here.
These were the changes I made.
HTML:
<div class="lb"> <!-- added class "lb" to <div> and removed it from <label> -->
<input type="checkbox" name="term" />
<label for="term">I have read and agree to the Terms of Use and the Privacy Policy</label>
</div>
CSS:
.lb {
float:left; /* Floats the element to left */
}
I hope this works for you. :)
P.S. I have removed all the <br> tags inside the <form>

html form css positioning

I am trying to make an html form and I have to replicate the following image:
I've done almost everything right but I can't get the positioning just right, specially on the submit button. What is the best to do this? and also how do I reposition the "message" caption next to the text box?
<style type="text/css">
form {
background-color: gray;
-moz-border-radius: 10px;
border-radius: 10px;
padding: 20px;
width: 400px;
text-align:right;
}
#formElements{
width: 60%;
}
</style>
<body>
<form>
<div>
Name: <input type="text" name="name" id="formElements">
<p>
Email: <input type="email" name="email" id="formElements">
<p>
Message: <textarea name="message" id="formElements"> </textarea>
<p>
<input type="submit" id="button" value="send your message">
</div>
</form>
</body>
A few problems here:
1. Broken HTML
You have several places where the HTML is broken. Remember to always close your <p> tags, and close the <input> tags with a soft closing /> just for good practice.
2. Never use IDs in place of class
IDs are only ever meant to be assigned to one element. They are to be unique. If you want to assign some CSS to multiple elements, use a class:
.class
//Not
#id
3. Use Labels for text in forms
Not only can you style them independently, but you can use the for attribute to link them to your inputs.
4. Repaired CSS
I used some different CSS tricks, such as block-style display for the button to allow me to position it in the right spot.
form {
background-color: gray;
-moz-border-radius: 10px;
border-radius: 10px;
padding: 20px;
width: 400px;
text-align:right;
}
.formElements {
width: 300px;
}
label {
display: inline-block;
vertical-align: top;
}
input[type="submit"] {
display: block;
margin-left: 95px;
}
5. Repaired HTML
Here it is. Always always always write proper HTML. It will save you a bunch of headaches.
<form>
<div>
<label>Name:</label>
<input type="text" name="name" class="formElements" />
<p>
<label>Email:</label>
<input type="email" name="email" class="formElements" />
</p>
<p>
<label>Message:</label>
<textarea name="message" class="formElements" rows="4"></textarea>
</p>
<p>
<input type="submit" id="button" value="send your message" />
</p>
</div>
</form>
Here is a JSFiddle that demo's the form for you.
I hope this helps.
Take a look at this.
There are a few things you should consider in your code:
Do Not use an ID more than once in a page, it must be specific to 1 element. Use classes instead to style multiple elements at once.
Use label tag to explain the form elements
Don't forget to close a container tag like p after opening it.
I would almost put it in a two columns table with the text on the left and the text boxes and button on the right.
I should look like this
<style type="text/css">
form {
background-color: gray;
-moz-border-radius: 10px;
border-radius: 10px;
padding: 20px;
width: 400px;
text-align:right;
}
#formElements{
width: 100%;
}
.right {
text-align:right;
}
.wide {
width:300px;
}
</style>
<body>
<form>
<div>
<table>
<tr>
<td class="right">Name:</td>
<td class="wide"><input class = "wide" type="text" name="name" id="formElements"></td>
</tr> <tr>
<td class="right">Email:</td>
<td class="wide"> <input class="wide" type="email" name="email" id="formElements"></td>
</tr> <tr>
<td class="right">Message:</td>
<td class="wide"> <textarea class="wide" name="message" id="formElements"> </textarea></td>
</tr> <tr>
<td></td><td class="wide"><input type="submit" id="button" value="send your message"></td>
</tr>
</div>
</form>
</body>

Creating form to have fields and text next to each other - what is the semantic way to do it?

I want to create a form so there is text on the left side and the inputs on the right, currently I am doing
<div id="labels">
<ul>
<li>The Label</li>
</ul>
</div>
<div id="inputs">
<ul>
<li><input type="text /></li>
</ul>
</div>
And the CSS
input[type=text] {
height: 14px;
}
#labels {
float: left;
}
#inputs {
float: right;
}
li {
padding-top: 4px;
padding-left: 10px;
}
// Text size is 14px
What happens is that the text and fields are not aligned perfectly (the inputs get progressively lower as I add items). I am thinking this is because not all the inputs can be 14px (I use drop downs, checkboxes, radios, etc.).
What would be the correct way to create this? I know a table would fix the problem but is that semantic?
This sort of question has been asked multiple times here in SO, you can do a simple search and find many solutions.
But here is a simple form to get you started:
HTML
<form>
<div class="line">
<label for="input">Full Name</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="input">Company</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="nselect">Dropdown Menu</label>
<div class="input">
<select name="select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</div>
<div class="line">
<label for="input">Text 1</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="input">Text 2</label>
<div class="input">
<input type="text" size="30" name="input">
</div>
</div>
<div class="line">
<label for="input">Text 3</label>
<div class="input">
<input type="text" size="15" name="input">
</div>
</div>
</form>
CSS
form {
margin:10px 0;
}
label {
color: #404040;
float: left;
font-size: 13px;
line-height: 18px;
padding-top: 6px;
text-align: right;
width: 130px;
}
label, input, select, textarea {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 13px;
font-weight: normal;
line-height: normal;
}
input, textarea, select {
-moz-border-radius: 3px 3px 3px 3px;
border: 1px solid #CCCCCC;
color: #808080;
display: inline-block;
font-size: 13px;
height: 18px;
line-height: 18px;
padding: 4px;
width: 210px;
}
select {
height: 27px;
line-height: 27px;
}
form .input {
margin-left: 150px;
}
form .line {
margin-bottom: 18px;
}
Here is a demo: http://jsfiddle.net/5aduZ/1/
A lot of people will not agree with my use of divs to separate the form elements but through testing i found this format to be the safest and surefire way to go about it as it separates the fields cleanly, and it works just fine under IE. Plus, it is the format used by the big boys (facebook, twitter, google).
It makes sense for the label to be next to the input in the HTML - it's easier to read and more maintainable. Typical HTML for this would be:
<div class="fieldWrapper">
<label for="something">Something</label>
<input type="text" id="something" name="something">
</div>
<div class="fieldWrapper">
<label for="something">Something</label>
<input type="text" id="something" name="something">
</div>
And CSS would be:
label, input {
float:left;
}
input {
font-size:14px;
padding: 2px; // instead of using fixed height
}
label {
width: 100px; // can use JavaScript if it needs to be dynamic
padding-top: 3px; // to make the label vertically inline with the input element
}
.fieldWrapper {
clear:left;
}
If you really can't change your HTML, you could set a CSS height on the <li> tag to fix the alignment problem. But I strongly recommend you to choose one of other proposed solutions, because your HTML is very hard to read in its current state. And you should use the <label> tag.
Write this <input type="text" name="firstname" /> and set the height width and padding
At my company, way back when we first started our first web application back in 2001, we used a table.
<table class="formTable">
<tbody>
<tr>
<td><label>Name:</label></td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td><label>E-mail:/label></td>
<td><input type="text" name="email" /></td>
</tr>
</tbody>
</table>
And while this works, philosophically I don't like the approach, because as far as I am concerned, a table should hold table-ized data.
You could use CSS and DIV's, as well:
<style>
.formLabel, .formInput {
display:inline-block;
}
</style>
<div class="formField">
<div class="formLabel"><label>Name:</label></div>
<div class="formInput"><input type="text" name="name" /></div>
</div>
<div class="formField">
<div class="formLabel"><label>E-Mail:</label></div>
<div class="formInput"><input type="text" name="email" /></div>
</div>
See here: http://jsfiddle.net/9P7pg/
Or, you could avoid the use of div's all together, and just apply the display: inline-block for each label and input (or use classes). But then you will also have to remember to use a breaking space for carriage returns in between the label-field combination.
there is a special list for this actually! it's called definition list (dl) and is comprised of definition terms and definition definitions (dt/dd). i usually put the text in the dt and the input box in the dd. like this:
<form action="bla">
<dl>
<dt>Name*</dt>
<dd><input type="text" name="name" />
<dt>Email</dt>
<dd><input type="text" name="email" />
</dl>
<p><input type="submit" /></p>
</form>

Which CSS tag creates a box like this with title?

I want to create a box like this with title:
Can any one please let me know if there is a default CSS tag to do this? Or do I need to create my custom style?
I believe you are looking for the fieldset HTML tag, which you can then style with CSS. E.g.,
<fieldset style="border: 1px black solid">
<legend style="border: 1px black solid;margin-left: 1em; padding: 0.2em 0.8em ">title</legend>
Text within the box <br />
Etc
</fieldset>
If you are not using it in forms, and instead want to use it in an non-editable form, you can do this via the following code -
.title_box {
border: #3c5a86 1px dotted;
}
.title_box #title {
position: relative;
top: -0.5em;
margin-left: 1em;
display: inline;
background-color: white;
}
.title_box #content {}
<div class="title_box" id="bill_to">
<div id="title">Bill To</div>
<div id="content">
Stuff goes here.<br> For example, a bill-to address
</div>
</div>
from http://www.pixy.cz/blogg/clanky/css-fieldsetandlabels.html
fieldset {
border: 1px solid green
}
legend {
padding: 0.2em 0.5em;
border: 1px solid green;
color: green;
font-size: 90%;
text-align: right;
}
<form>
<fieldset>
<legend>Subscription info</legend>
<label for="name">Username:</label>
<input type="text" name="name" id="name" />
<br />
<label for="mail">E-mail:</label>
<input type="text" name="mail" id="mail" />
<br />
<label for="address">Address:</label>
<input type="text" name="address" id="address" size="40" />
</fieldset>
</form>
This will give you what you want
<head>
<title></title>
<style type="text/css">
legend {border:solid 1px;}
</style>
</head>
<body>
<fieldset>
<legend>Test</legend>
<br /><br />
</fieldset>
</body>
As far as I know (correct me if I'm wrong!), there isn't.
I'd recommend you to use a div with a negative-margin-h1 inside. Depending on the semantic structure of your document, you could also use a fieldset (HTML) with one legend (HTML) inside which approximately looks like this by default.
I think this example can also be useful to someone:
.fldset-class {
border: 1px solid #0099dd;
margin: 3pt;
border-top: 15px solid #0099dd
}
.legend-class {
color: #0099dd;
}
<fieldset class="fldset-class">
<legend class="legend-class">Your Personal Information</legend>
<table>
<tr>
<td><label>Name</label></td>
<td><input type='text' name='name'></td>
</tr>
<tr>
<td><label>Address</label></td>
<td><input type='text' name='Address'></td>
</tr>
<tr>
<td><label>City</label></td>
<td><input type='text' name='City'></td>
</tr>
</table>
</fieldset>
You can try this out.
<fieldset class="fldset-class">
<legend class="legend-class">Your Personal Information</legend>
<table>
<tr>
<td><label>Name</label></td>
<td><input type='text' name='name'></td>
</tr>
<tr>
<td><label>Address</label></td>
<td><input type='text' name='Address'></td>
</tr>
<tr>
<td><label>City</label></td>
<td><input type='text' name='City'></td>
</tr>
</table>
</fieldset>
DEMO