I am using Squarespace and trying to move the margin of the first .field.text.three-digits using "nth-of-type", but I can't get it to work right.
CSS:
.form-item.fields.phone:nth-of-type(3) {
background-color: red;
margin-left: 20%;
}
HTML:
<fieldset id="phone-yui_3_17_2_1_1531771537607_16560" class="form-item fields
phone">
<div class="title">Phone</div>
<legend>Phone</legend>
<div class="field text three-digits" id="yui_3_17_2_1_1531936132691_509">
<label class="caption" id="yui_3_17_2_1_1531936132691_508"><input
class="field-element" x-autocompletetype="phone-area-code" type="text"
maxlength="3" data-title="Areacode" id="yui_3_17_2_1_1531936132691_507">
(###)</label>
</div>
<div class="field text three-digits">
<label class="caption"><input class="field-element" x-
autocompletetype="phone-local-prefix" type="text" maxlength="3" data-
title="Prefix">###</label>
</div>
<div class="field text four-digits">
<label class="caption"><input class="field-element" x-
autocompletetype="phone-local-suffix" type="text" maxlength="4" data-
title="Line">####</label>
</div>
</fieldset>
Thanks!
This code:
.form-item.fields.phone:nth-of-type(3)
Will apply the styles to the third element it finds with these three classes
form-item fields phone
If you want to modify the first instance of an element with the classes field text three-digits, your CSS should be something like this:
.field.text.three-digits:nth-of-type(2) {
background-color: red;
margin-left: 20%;
}
Related
I have an example of form draft in Microsoft Word as shown:
and I'm trying to recreate this form as a web page via HTML but I'm having issues with getting the textbox label alignment to be exactly like the one in the draft which is somewhat "right" aligned, followed by the textbox.
When I added the HTML elements it is currently as so:
However I'm trying to achieved the "right" alignment of the labels like the draft above, so I tried using the "text-align: right" function in css but this is what I got instead.
It achieves what I wanted which is for the label to be right aligned but everything got shifted to the right at the end of the div, which means if I were to want the fields to be sort of positioned somewhat left like the draft, does this mean that I would have to move each individual element via the "left" positioning attribute in css? Is there any more efficient way I could use for this?
* {
margin: 0;
padding: 0;
}
.outer_frame {
position: relative;
border: 1px solid black;
}
.inner_frame {
border: 1px solid black;
height: 600px;
width: 700px;
text-align: right;
}
<div class="outer_frame">
<div class="inner_frame">
<div class="entry">
<label id="name">Name</label>
<input type="text" id="name_in" disabled class="field">
</div>
<div class="entry">
<label id="addr">Address</label>
<input type="text" id="addr_in" disabled class="field">
</div>
<div class="entry">
<label id="tel">TelephoneNumber</label>
<input type="text" id="tel_in" disabled class="field">
</div>
<div class="entry">
<label id="iden">Identity Number</label>
<input type="text" id="identity_in" disabled class="field">
</div>
<div class="entry">
<label id="cpny">Company</label>
<input type="text" id="com_in" disabled class="field">
</div>
<div class="entry">
<label id="job">Job Title</label>
<input type="text" id="job_in" disabled class="field">
</div>
</div>
</div>
make your labels inline block, give them a width (as large as the largest text) and then align them right:
label {
display: inline-block;
width: 7.75em;
text-align: right;
margin-right: 2em;
}
<div class="entry">
<label id="name">Name</label>
<input type="text" id="name_in" disabled class="field">
</div>
<div class="entry">
<label id="addr">Address</label>
<input type="text" id="addr_in" disabled class="field">
</div>
<div class="entry">
<label id="tel">TelephoneNumber</label>
<input type="text" id="tel_in" disabled class="field">
</div>
<div class="entry">
<label id="iden">Identity Number</label>
<input type="text" id="identity_in" disabled class="field">
</div>
<div class="entry">
<label id="cpny">Company</label>
<input type="text" id="com_in" disabled class="field">
</div>
<div class="entry">
<label id="job">Job Title</label>
<input type="text" id="job_in" disabled class="field">
</div>
Add margin: auto to .inner_frame if you want it to take the size of the content and add the code below to adjust the lines
.inner_frame{ margin:auto }
.entry{
display:flex
justify-content: space-between;
margin:1em
}
You can fix the width of your labels and then align them to the right:
.entry label {
display: inline-block;
width: 200px;
text-align: right;
margin-right: 10px;
}
Adding the below definition to your inner-frame class will fix the issue
margin:auto; //will center the div
if you need to align it to a different area, use exact values to the margin
margin: 10px 50px 20px 0;
Read more on the topic on the MDN site
I am making a copy of a pen-and-paper character sheet for a RPG, as a way of learning html/css. However I got stuck right at the beginning when trying to style a form, holding some background information about the character.
Currently I've managed to make my form of labels and input-fields to look like the picture to the left. However the pen-and-paper character sheet (and the desired look) is formatted like the one on the right.
Below is the code I'm using.
.sheet-character-background form input,
label {
margin-bottom: 10px;
}
.age-input {
width: 60px;
}
<div class="sheet-character">
<div class="sheet-character-background">
<form>
<label>Name</label>
<input type="text" name="attr_name">
<br>
<label>Race</label>
<input type="text" name="attr_race">
<br>
<label>Gender</label>
<input class="gender-input" type="text" name="attr_gender">
<label>Age</label>
<input class="age-input" type="number" name="attr_age" min="0">
<br>
<label>Religion</label>
<input type="text" name="attr_religion">
<br>
<label>Occupation</label>
<input type="text" name="attr_occupation">
<br>
<label>Archetype</label>
<input type="text" name="attr_archetype">
<br>
<label>Environment</label>
<input type="text" name="attr_environment">
<br>
<label>Background</label>
<input type="text" name="attr_backgrund">
</form>
</div>
</div>
What are the steps for going from what I have to what I want? I played around with surrounding each "row" with a <div> and class and setting their width in css. However this didn't work out so I reverted to my initial version and got stuck.
Many people would probably suggest to get a css framework, but what you want can be done with some simple css.
First, your html basically consists of a form with a series of rows, except for one row where it consists of two fields in one row. So I modified your html slightly that each row is wrapped by a div with a class as .form-row and delete the <br> (let css to do the rendering instead of using html tag):
To achieve what you want will then come down to set a width for the form, and how each row will behave, and set the width of input, and last override the setting for the special case of .age-input.
This is just a 'quick-and-dirty' way to achieve what you want, hopefully it provide you some ideas and suggestions in your learning.
form {
width: 300px;
}
.form-row {
display:flex;
}
input {
width: 100%;
}
.age-input {
width: 60px;
}
<form>
<div class="form-row">
<label>Name</label>
<input type="text" name="attr_name">
</div>
<div class="form-row">
<label>Race</label>
<input type="text" name="attr_race">
</div>
<div class="form-row">
<label>Gender</label>
<input type="text" name="attr_gender">
<label>Age</label>
<input class="age-input" type="number" name="attr_age" min="0">
</div>
<div class="form-row">
<label>Religion</label>
<input type="text" name="attr_religion">
</div>
<div class="form-row">
<label>Occupation</label>
<input type="text" name="attr_occupation">
</div>
<div class="form-row">
<label>Archetype</label>
<input type="text" name="attr_archetype">
</div>
<div class="form-row">
<label>Environment</label>
<input type="text" name="attr_environment">
</div>
<div class="form-row">
<label>Background</label>
<input type="text" name="attr_backgrund">
</div>
</form>
I want to center align my form w.r.t. page, but if i use the following, only text input field is getting aligned but label remains at left. How to resolve it?
<div id="passCode"></div>
<form class="form-horizontal">
<fieldset>
<legend style="color:#145FAC">Please Fill in the Online Form</legend>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control formWidth" id="inputName" placeholder="Nam" />
</div>...</div>
</fieldset>
</form>
text-align: left is applied to control-label therefore it overrides "center" applied to the parent element. Try using this css below
.control-label, .form-control {
text-align: center;
}
Use this CSS for the form:
.form-horizontal {
margin: 0 auto;
width: 70%; //Change it according to the design.
}
Demo:http://jsfiddle.net/lotusgodkk/GCu2D/722/
You can use the center tag, since you want the label to be centered.
<center>
<div id="passCode"></div>
<div class="container "> <!--center_div or center-block-->
<form class="form-horizontal">
<fieldset>
<legend style="color:#145FAC">Please Fill in the Online Form</legend>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control formWidth" id="inputName" placeholder="Name" required>
</div>
</div>
</fieldset>
</form>
</div>
</center>
Bootstrap comes with a helper class .center-block. Try adding it to the label.
you could apply this CSS to form-control:
text-align: center !important;
text-align: -webkit-center !important
I have added Bootply sample to you please check this it may works for you http://www.bootply.com/wokazmuDbv
I want to add "month" after the input in bootstrap, in the side of it.
I've tried span, pull-left nothing worked. Months is always below
<form role="form">
<div class="form-group">
<label for="exampleInputEmail1">Months</label>
<input type="email" class="form-control" style="width: 50%" id="exampleInputEmail1" placeholder="Months"> months
</div>
</form>
JSFIDDLE
Just add form-inline to your form..
<form role="form" class="form-inline">
<div class="form-group">
<label for="exampleInputEmail1">Months</label>
<input type="email" class="form-control" style="width: 50%" id="exampleInputEmail1" placeholder="Months"> months
</div>
</form>
Demo: http://www.bootply.com/119625
Try wrapping the elements and specifying the column widths:
HTML
<form role="form">
<div class="form-group">
<div class="pull-left col-xs-9">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
<span class="col-xs-3">months<span>
</div>
</form>
CSS
span{
margin-top: 25px;
}
JS Fiddle: http://jsfiddle.net/7rYp7/2/
putting style="display:inline" into the actual input element in question has worked for me.
Listen, I know we are supposed to avoid using style and only use classes defined in CSS but I tried all the example above and this is the only thing that worked.
You can set the following in your CSS (overwriting the bootstrap.css)
.form-group input {
display:inline;
width: 50%;
margin: 5px;
}
You can also use a different selector to be more specific (instead of overwriting it for all inputs) UPDATED:
#exampleInputEmail1{
display:inline;
width: 50%;
margin: 5px;
}
.form-group label {
display: block;
}
I have tried everything to align these boxes, so they start from the same place downwards.
I'm not sure which div to put in my stylesheet
<div class="boxes">
<p class="h3"> You are able to add up to 3 addresses.
Please select the type of address, using the following guide
<ul>
<li>H: Permanent home address</li>
<li>P: Postal address (where you will be from June to September)</li>
<li>L: Local address (where you currently live)</li>
</ul>
</p>
<div id="address">
<div id="input1" style="margin-bottom:4px;" class="input">
Street<span class="required">*</span>
<input name="Street[]" type="text" >
</div>
<div id="input2" style="margin-bottom:4px;" class="input">
Line2
<input name="Line2[]" type="text" >
</div>
<div id="input3" style="margin-bottom:4px;" class="input">
Line3
<input name="Line3[]" type="text" >
</div>
Any ideas?
Having amended your HTML, to wrap the label/associated text in actual label elements, added a for attribute to those elements and a corresponding id attribute to the input elements:
<div class="boxes">
<p class="h3">
You are able to add up to 3 addresses. Please select the type of address, using the following guide
<ul>
<li>H: Permanent home address</li>
<li>P: Postal address (where you will be from June to September)</li>
<li>L: Local address (where you currently live)</li>
</ul>
</p>
<div id="address">
<div id="input1" style="margin-bottom:4px;" class="input">
<label for="street">Street<span class="required">*</span></label><input name="Street[]" id="street" type="text">
</div>
<div id="input2" style="margin-bottom:4px;" class="input">
<label for="line2">Line2</label><input id="line2" name="Line2[]" type="text">
</div>
<div id="input3" style="margin-bottom:4px;" class="input">
<label for="line3">Line3</label><input id="line3" name="Line3[]" type="text">
</div>
</div>
</div>
The following CSS works:
#address label {
display: inline-block;
width: 5em;
text-align: right;
padding-right: 0.5em;
}
#address input {
display: inline-block;
}
JS Fiddle demo.
In the above, once the text was wrapped in a tag (to become the label element), it could then be assigned display: inline-block; and could then be given a width. Also, white-space was removed from between the close of the label and the opening of the input, in order to prevent white-space in the HTML file causing any space between the two elements.