This question already has answers here:
Delete default value of an input text on click
(13 answers)
Closed 9 years ago.
I have been playing around CSS for few hours now and I can't seem to get the result I want. Basically I want my label text to be displayed inside the textbox, so when you start typing it just disappears. Something like this [input --- enter your name --- input]
Real example: http://www.apartmani-pesa-zaton.hr/rezervacija
My label form:
<form class="email" id="forma-kontakt" action="send_mail.php" method="post">
<div id="grid_kontakt">
<div id="grid_kontakt_l">
<p>
<label for="name">Ime i prezime *</label>
<input type="text" id="name" class="required" name="name" />
</p>
<p>
<label for="email">E-mail *</label>
<input type="text" id="email" class="required email" name="email" />
</p>
</div><!-- Grid kontakt left -->
<div id="grid_kontakt_r">
<p>
<label for="country">Država</label>
<input type="text" id="country" class="required" name="country" />
</p>
<p>
<label for="phone">Telefon</label>
<input type="text" id="phone" class="required" name="phone" />
</p>
</div><!-- Grid kontakt right -->
<p class="text">
<label for="message">Poruka *</label>
<textarea name="message" class="required" id="message"></textarea>
</p>
<p class="ar">
<em>Sva polja su obavezna!</em>
<input type="submit" class="send" value="POŠALJI" />
</p>
</div><!-- Grid kontakt -->
</form>
Use the placeholder attribute, it is now widely supported.
<input type="text" id="name" class="required" name="name" placeholder="Ime i prezime *" />
I added all of the relevant CSS from your example site to your form using Chrome devloper tools.
http://jsfiddle.net/76VRz/54/
.email input[type=text], .forma input[type=email] {
width: 283px;
height: 47px;
padding: 0 15px;
background-position: 0 0;
}
.email label {
position: absolute;
width: 100%;
height: 47px;
line-height: 47px;
color: #383838;
font-size: 14px;
text-indent: 15px;
cursor: text;
}
This does overlay the label inside the input box although there must be an event wired up to dim the color and then remove it once there is a key press of value in the field.
Related
Bootstrap 4.
<div class="form-group">
<label asp-for="Enabled" class="control-label"></label>
<input asp-for="Enabled" class="form-control" type="checkbox" />
<span asp-validation-for="Enabled" class="text-danger"></span>
</div>
I have a form (see image). I would like the check box to be underneath the word "Enabled" not centred like the other full width controls.
If I set "width: auto;" on the checkbox, this does the job, but then displays a small checkbox (I want a large one). See image.
<div class="form-group">
<label asp-for="Enabled" class="control-label"></label>
<input asp-for="Enabled" class="form-control" style="width: auto;" type="checkbox" />
<span asp-validation-for="Enabled" class="text-danger"></span>
</div>
My question is, how can I get a large left aligned checkbox on my form?
I am also searched before for the same issue, but not satisfied with the above answer that's why I have done my research and I found a good solution. Just add class "col-sm-1"
in the input tag, you are done.
<div class="col-8">
<input asp-for="IsUrgent" type="checkbox" class="form-control col-sm-1" />
<span asp-validation-for="IsUrgent" class="text-danger" />
</div>
you can also use like this if you are not satisfying with class name
input[type="checkbox"]{
width: 30px; /*Desired width*/
height: 30px; /*Desired height*/
cursor: pointer;
-webkit-appearance: none; /* if you want check inside box then remove this line*/
appearance: none; /* if you want check inside box then remove this line*/
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<form>
<div class="form-group">
<label asp-for="Enabled" class="control-label">Enabled</label>
<input asp-for="Enabled" class="form-control checkbox-large" type="checkbox" />
<span asp-validation-for="Enabled" class="text-danger"></span>
</div>
</form>
Its not tidy by setting an height and width for the checkbox should do the trick.
.checkbox-large {
width: 25px !important;
height: 25px
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<form>
<div class="form-group">
<label asp-for="Enabled" class="control-label">Enabled</label>
<input asp-for="Enabled" class="form-control checkbox-large" type="checkbox" />
<span asp-validation-for="Enabled" class="text-danger"></span>
</div>
</form>
This question already has answers here:
How to align input forms in HTML
(17 answers)
Align vertically input elements in div
(2 answers)
CSS to align label and input
(6 answers)
HTML label and input box inside form not align
(3 answers)
Closed 5 years ago.
I am trying to centre the fixed-width input fields on the page, and have the text align with the left edge of the input fields: sorry forgot the divs
<style>
td {border: 1px solid black;}
input[type=text] {
width: 50%;
padding: 10px;
box-sizing: border-box;
}
.AddFunction{
position: center;
text-align: left;
margin-left: auto;
margin-right: auto;
}
</style>
<div class="AddFunction">
<h2>Add Record</h2>
<form action="crud.ctrl.php?act=insert" method="post">
First Name: <br><input type="text" name="fname"> <br />
Last Name: <br><input type="text" name="lname"> <br />
Phone: <br><input type="text" name="phone"> <br />
Email: <br><input type="text" name="email"> <br />
Location: <br><input type="text" name="location"> <br />
MC: <br><input type="text" name="mc"> <br />
Position: <br><input type="text" name="pos"> <br />
Department: <br><input type="text" name="dept"> <br />
<input type="submit">
</form>
</div>
Let's fix you mark up to use label, which you should for form elements anyway.
label {
display: block;
width: 50%;
margin: 0 auto; /*This Centers the label block*/
}
input[type=text] {
width: 100%;
display: block; /*Give the input its own line*/
padding: 10px;
box-sizing: border-box;
}
<form action="crud.ctrl.php?act=insert" method="post">
<label>First Name: <input type="text" name="fname"></label>
<label>Last Name: <input type="text" name="lname"></label>
<label>Phone:<input type="text" name="phone"> </label>
<label>Email:<input type="text" name="email"> </label>
<label>Location:<input type="text" name="location"> </label>
<label>MC: <input type="text" name="mc"> </label>
<label>Position:<input type="text" name="pos"> </label>
<label>Department:<input type="text" name="dept"> </label>
<input type="submit">
</form>
I try currently to beautify my sources a little bit. For this I want to change the width of buttons and radio buttons to 80% and change the alignment to center. For the buttons I made css settings that works quite fine, but I am not able to center the radio button group.
HTML:
<div data-role="page" id="testPage" data-theme="e">
<fieldset data-role="controlgroup">
<legend id="SettingsDifficulty"></legend>
<input class="rbgroup1" type="radio" name="test" id="radio-choice-1" value="3" />
<label for="radio-choice-1" id="label1" class="activeOnce">Radio 1</label>
<input class="rbgroup1" type="radio" name="test" id="radio-choice-2" value="4" />
<label for="radio-choice-2" id="label2" class="activeOnce">Radio 2</label>
<input class="rbgroup1" type="radio" name="test" id="radio-choice-3" value="5" />
<label for="radio-choice-3" id="label3" class="activeOnce">Radio 3</label>
</fieldset>
</br>
<hr>
</br>
Button
</div>
CSS:
.ui-btn.activeOnce
{
width:80%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
The single button at the end is now at 80% width and perfect centered. The radio buttons are also at 80% width but still left aligned. At the web I found some solutions for horizontal radio button groups, but this solutions does not work with data-type="vertical". Is there a way to center this, too?
Thank you very much for helping me :-).
JSFIDDLE: http://jsfiddle.net/7eKZb
Use jQuery Mobile grid system, ui-grid-b and 3 blocks ui-block-a, ui-block-b and ui-block-c.
Demo
<div class="ui-grid-b">
<div class="ui-block-left ui-block-a"><!-- Placeholder --></div>
<div class="ui-block-center ui-block-b">
<fieldset data-role="controlgroup">
<!-- Buttons go here -->
</fieldset>
</div>
<div class="ui-block-right ui-block-c"><!-- Placeholder --></div>
</div>
And override width of blocks a, b and c. I used extra custom classes in order not to override other blocks.
.ui-block-left, .ui-block-right {
width: 10% !important;
}
.ui-block-center {
width: 80% !important;
}
See this fiddle http://jsfiddle.net/bB2vM/
i wrapped your radio button group in a div and it worked see the fiddle
<div data-role="page" id="testPage" data-theme="e">
<fieldset data-role="controlgroup">
<legend id="SettingsDifficulty"></legend>
<div id="centregroup">
<input class="rbgroup1" type="radio" name="test" id="radio-choice-1" value="3" />
<label for="radio-choice-1" id="label1" class="activeOnce">Radio 1</label>
<input class="rbgroup1" type="radio" name="test" id="radio-choice-2" value="4" />
<label for="radio-choice-2" id="label2" class="activeOnce">Radio 2</label>
<input class="rbgroup1" type="radio" name="test" id="radio-choice-3" value="5" />
<label for="radio-choice-3" id="label3" class="activeOnce">Radio 3</label>
</div>
</fieldset>
</br>
<hr>
</br>
Button
and here is the css
.ui-btn.activeOnce
{
width:80%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
#centregroup
{
text-align:center;
}
See screeshot.
U can group your radio buttons inside a div with fixed width and height:
<fieldset data-role="controlgroup" data-type="vertical" style="text-align: center">
<div class="centerRadio">
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked" />
<label for="radio-choice-1">A</label>
<input data-theme="e" type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2" />
<label for="radio-choice-2">B</label>
</div>
</fieldset>
CSS:
.centerRadio
{
width: 80%; margin: 0 auto;
}
DEMO
i have this html structure:
<form id="signUpForm" action="login.php" method="post">
<h3>Please enter your details below:</h3>
<br />
<p>Name: </p>
<input id="name" name="name" type="text"></input>
<br />
<p>Email: </p>
<input id="email" name="email" type="text"></input>
<br />
<p>Company: </p>
<input id="company" name="company" type="text"></input>
<br />
<p id='required'>* All fields are required</p>
<p>Enquiry Details</p>
<textarea></textarea>
<input id="signUpSubmit" type="submit" value="Send"></input>
</form>
This form is underneath a div element in the html but the div element has float: left on it, so the div and form sit side by side. The thing i want to do is have the 3 text inputs vertically, then have the textarea top right of the form. so the inputs and the textarea are then side by side?
Does that make sense?
You need to make some adjustments to your markup, adding two divs for the left and right columns would make things far easier:
<form>
<div class="left-column">
<label for="name">Name: </label>
<input id="name" name="name" type="text"/>
<label for="email">Email: </label>
<input id="email" name="email" type="text"/>
<label for="company">Company: </label>
<input id="company" name="company" type="text"/>
</div>
<div class="right-column">
<label for="ta">Enquiry Details: </label>
<textarea id="ta" name="ta"></textarea>
</div>
</form>
Then using some simple CSS, you may create the two column effect:
form {
position: relative;
}
form div.left-column {
position: absolute;
width: 50%;
left: 0;
}
form div.right-column {
position: absolute;
width: 50%;
right: 0;
}
Then using correct CSS styling on your inputs in order to allow them to display vertically without using <br /> tags in your markup:
form input, form label {
float: left;
clear: left;
}
I have input text's and label tags. I can't figure out the CSS to get the label text to align right below the input text. Here's a snippet of the HTML:
<form id="sg1">
<label for="member1">member 1</label>
<input name="member1" id="member1" value="jack" />
<label for="member2">member 2</label>
<input name="member2" id="member2" value="carter" />
<label for="member3">member 3</label>
<input name="member3" id="member3" value="jackson" />
<label for="member4">member 4</label>
<input name="member4" id="member4" value="tielk" />
</form>
Trying to get:
[input box 1] [input box 2]
label 1 label 2
etc, with all elements.
A quickly whipped up example that works:
input {
display: inline-block;
width: 6em;
position: relative;
top: -3em;
}
label {
display: inline-block;
width: 6em;
margin-right: .5em;
padding-top: 1.5em;
}
<form id="sg1">
<label>member 1 <input name="member1" id="member1" value="jack" /></label>
<label>member 2 <input name="member2" id="member2" value="carter" /></label>
<label>member 3 <input name="member3" id="member3" value="jackson" /></label>
<label>member 4 <input name="member4" id="member4" value="tielk" /></label>
</form>
Could be improved, but I find it cleaner than extraneous divs, and it degrades much nicer than the label-after-input-approach when CSS support is absent. Personally, I prefer to nest the inputs in the labels anyway.
Use a table (one input/label pair per cell) or left-floating divs (one input/label pair per div). Example:
<div class="pair">
<input type="text" name="foo" value="bar" /><br />
<label for="foo">shabba</label>
</div>
<div class="pair">
…
</div>
CSS:
div.pair {
float:left;
}
You'd make the job a lot easier by wrapping each field (in this case, each input/label pair) in a div.
You can use pure css to get this to achieve what you want, but it requires a lot of adhoc positioning stuff that you're better off not doing.
The simplest way is to put the label beneath the input on the html:
<form id="sg1">
<input name="member1" id="member1" value="jack" />
<label for="member1">member 1</label>
<input name="member2" id="member2" value="carter" />
<label for="member2">member 2</label>
<input name="member3" id="member3" value="jackson" />
<label for="member3">member 3</label>
<input name="member4" id="member4" value="tielk" />
<label for="member4">member 4</label>
</form>
Then you can wrap each input/label pair with a div, and set the div like so:
<form id="sg1">
<div class="wrap">
<input name="member1" id="member1" value="jack" />
<label for="member1">member 1</label>
</div>
<div class="wrap">
<input name="member2" id="member2" value="carter" />
<label for="member2">member 2</label>
</div>
<div class="wrap">
<input name="member3" id="member3" value="jackson" />
<label for="member3">member 3</label>
</div>
<div class="wrap">
<input name="member4" id="member4" value="tielk" />
<label for="member4">member 4</label>
</div>
</form>
#sg1 div
{
clear: both;
float: left;
}
Next you can put
#sg1 label
{
float: right;
}
input
{
display:block;
}