I'm trying to position my two labels ("your message:" and "your email:") to the top-left of each of the textarea's, with "your message:" on the top textarea. Although even through this method: How will I align the label of a text area to top? I can't get it to work. Is the table required for it to work correctly? I've tried other methods to get it to function, such as grouping the form within a -p- tag but that also didn't work.
HTML
<div id="ContactUsForm">
<p>Contact Us</p>
<form>
<table>
<td>
<label for="message">your message:</label>
<textarea id="message" class="contact" name="message"</textarea>
<label for="email">your email:</label>
<textarea id="email" class="contact" name="email"></textarea>
</td>
</table>
</form>
</div>
CSS
#ContactUsForm {
position: absolute;
width: 1400px;
height: 400px;
top: 227px;
left: 42px;
border: 2px solid #E64A19;
}
#ContactUsForm p {
text-decoration: underline;
font-weight: bold;
position: absolute;
top: -15px;
left: 50px;
font-size: 30px;
}
.contact {
position: absolute;
background: white;
border: 2px solid #E64A19;
}
#message {
width: 500px;
height: 150px;
top: 100px;
left: 30px;
resize: none;
position: absolute;
}
#email {
width: 500px;
height: 70px;
position: absolute;
resize: none;
top: 300px;
left: 30px;
}
label {
vertical-align: top;
}
Get rid of position: absolute, I don't see a point of using it inside table in this case.
<div id="ContactUsForm">
<p>Contact Us</p>
<form>
<table>
<tr>
<td>
<label for="message">your message:</label>
<textarea id="message" class="contact" name="message"></textarea>
<label for="email">your email:</label>
<textarea id="email" class="contact" name="email"></textarea>
</td>
</tr>
</table>
</form>
</div>
#ContactUsForm {
width: 1400px;
height: 400px;
border: 2px solid #E64A19;
}
#ContactUsForm p {
text-decoration: underline;
font-weight: bold;
font-size: 30px;
}
.contact {
background: white;
border: 2px solid #E64A19;
}
#message {
width: 500px;
height: 150px;
top: 100px;
left: 30px;
resize: none;
display: block;
}
#email {
width: 500px;
height: 70px;
display: block;
resize: none;
top: 300px;
left: 30px;
}
label {
vertical-align: top;
}
Here's JSFiddle: https://jsfiddle.net/pa4r62eu/
You don't need to use a table for that.
You can achieve what you want with just two changes:
Remove all the position: absolute; of your code. In this way, each element will be placed above the next one (and you can remove all your left and top rules).
Add a display: block; rule to your labels. It will make your labels occupy all the width of its parent, and the textareas will be placed under them.
Looking at the snippet, you can see how much cleaner your code will be:
#ContactUsForm {
width: 1400px;
height: 400px;
border: 2px solid #E64A19;
padding: 10px;
}
#ContactUsForm p {
text-decoration: underline;
font-weight: bold;
font-size: 30px;
}
.contact {
background: white;
border: 2px solid #E64A19;
}
#message {
width: 500px;
height: 150px;
resize: none;
}
#email {
width: 500px;
height: 70px;
resize: none;
}
label {
display: block;
}
<div id="ContactUsForm">
<p>Contact Us</p>
<form>
<label for="message">your message:</label>
<textarea id="message" class="contact" name="message"></textarea>
<label for="email">your email:</label>
<textarea id="email" class="contact" name="email"></textarea>
</form>
</div>
Hope it helps!
Related
I don't know why, but my text input and my submit button margin are linked, so it's ugly and very annoying.
I have this on my main html file :
.banner {
width: 100%;
height: 100px;
display: inline-flex;
margin: 0px;
background-color: #1b2936;
}
.logo {
width: 200px;
height: 100px;
}
input[type=text] {
background-color: #10151b;
border: #10151b 5px solid;
border-radius: 7px;
height: 50px;
width: 500px;
color: white;
font-family: jetbrainsRegular;
}
.search {
width: 50px;
height: 50px;
}
.searchbtn {
margin-top: 0px;
border: #1fa2f3 5px solid;
border-radius: 30px;
background-color: #1fa2f3;
}
.nomargin {
margin-top: 0;
}
<div class="banner">
<img class="logo" src="logo.png">
<form action="query.php">
<label>
<input type="text" id="query" placeholder="Mot" class="nomargin">
</label>
<label>
<button type="submit" class="searchbtn"><img src="search.png" class="search"/></button>
</label>
</form>
</div>
I am searching for a way to unlink their margins...
There is no margin, it's an issue with your form. Try this:
form{
display:flex;
}
Or (but I don't recommend it):
input[type=text]{
float:left;
}
Flex gives you much more flexibility (pun intended) and it's much easier to work with. https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I want to add a "view password" icon inside of an html input. To do that, I added the material icons font and used one of its components. I nested it inside of the input to allow me to position it according to the input. I set the positon property of the input as "relative" and the position property of the icon as "absolute," but somehow, it still positions absolutely relative to the whole page. How can i fix this?
.auth-input {
text-align: left;
padding: 7px 10px;
background-color: #f6f6f6;
border: none;
border-radius: 5px;
font-size: 1.05em;
width: 100%;
position: relative;
}
i.material-icons {
position: absolute;
top: 0
}
<input type="password" name="password" id="password-input" class="auth-input">
<i class="material-icons">visibility</i>
</input>
You cannot have html inside an input. It is a self closing tag. You need to put both elements into a container.
.auth-input {
text-align: left;
padding: 7px 10px;
background-color: #f6f6f6;
border: none;
border-radius: 5px;
font-size: 1.05em;
width: 100%;
position: relative;
}
.auth-input input {
width: 100%;
}
i.material-icons {
position: absolute;
top: 0
}
<div class="auth-input">
<i class="material-icons">visibility</i>
<input type="password" name="password" id="password-input" />
</div>
Wrap the two. See demo https://codepen.io/yifanai/pen/MWyvJRE
.password-input-group {
position: relative;
}
.auth-input {
text-align: left;
padding: 7px 10px;
background-color: #f6f6f6;
border: none;
border-radius: 5px;
font-size: 1.05em;
width: 100%;
position: relative;
}
i.material-icons {
position: absolute;
top: 7px;
right: 10px;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel=" stylesheet">
<div class="password-input-group">
<input type="password" name="password" id="password-input" class="auth-input" />
<i class="material-icons">visibility</i>
</div>
.auth-input {
text-align: left;
padding: 7px 10px;
background-color: #f6f6f6;
border: none;
border-radius: 5px;
font-size: 1.05em;
width: 100%;
}
.layout {
position: relative;
}
i.material-icons {
position: absolute;
top: 0;
right: 20px;
z-index: 1;
}
<span class="layout">
<input type="password" name="password" id="password-input" class="auth-input"></input>
<i class="material-icons">visibility</i>
</span>
Input TAG not have child, try it.
I am working on a website but I have a problem arranging input items.
This is what I want it to look like:
but it looks like this:
My HTML code:
<div id="search">
<form action="">
<input class="search-area" type="text" name="text" placeholder="Search here">
<input class="search-btn" type="submit" name="submit" value="SEARCH">
</form>
</div>
My CSS code:
#search{
width: 650px;
float: left;
padding: 20px;
margin-left: 50px;
}
.search-area{
width: 650px;
height: 50px;
background: #fff;
border: none;
border-radius: 10px;
float: left;
padding-left: 15px;
}
.search-btn{
width: 100px;
height: 50px;
border-radius: 10px;
border: none;
color:#fff;
background: brown;
margin-left: -100px;
}
Please help me to understand the problem.
Add position:relative to your main div, which is the #search.
Then add position:absolute to the button, and right:0 in order to align it to the right of the relative element.
#search{
position:relative;
}
.search-btn{
position:absolute;
right:0
}
Maybe you will also need a top positioning of the button. You can add top:5px for example to achieve that.
Cheers
To position the search-button above another element it has to be position: absolute.
Here you go:
body {
background: lightgreen;
}
#search {
position: relative;
width: 550px;
padding: 20px;
}
.search-area {
width: 550px;
height: 50px;
background: #fff;
border: none;
border-radius: 10px;
padding-left: 15px;
}
.search-btn {
position: absolute;
top: 20px;
right: 0;
width: 100px;
height: 52px;
border-radius: 10px;
border: none;
color: #fff;
background: brown;
}
<div id="search">
<form action="">
<input class="search-area" type="text" name="text" placeholder="Search here">
<input class="search-btn" type="submit" name="submit" value="SEARCH">
</form>
</div>
I'm trying to stack two <span> tags in a form input label. At the moment, they're sitting next to each other, but I'm not sure how to move span.label-sm under the regular span. I've already set it to display: block;.
Desired outcome: http://i.imgur.com/CkOKeWl.jpg.
HTML:
<div id="appraisals-form" class="contact-form">
<form role="form" method="post" action="contact-form.php">
<label for="name"><span>Name</span><input type="text" class="input-field" name="name" required data-errormessage-value-missing="Please enter your name." /></label>
<label for="email"><span>Email</span><input type="email" class="input-field" name="email" required data-errormessage-value-missing="Please enter your email address." /></label>
<label for="email"><span>Phone</span><input type="tel" class="input-field" name="phone" required data-errormessage-value-missing="Please enter your phone number." /></label>
<label for="name"><span>Type of Artwork</span><span class="label-sm">(i.e. sculpture, painting...)</span><input type="text" class="input-field" name="name" required data-errormessage-value-missing="Please enter your item's type of artwork." /></label>
<label for="message"><span>Message</span><textarea name="message" class="textarea-field" required data-errormessage-value-missing="Please enter your message."></textarea></label>
<div class="centred-button"><input type="submit" value="" class="submit-button" /></div>
</form>
</div>
CSS:
.contact-form {
margin: 0 auto;
position: relative;
top: 50%;
transform: translateY(-50%);
max-width: 600px;
font-family: 'LinotypeUniversW01-Thin_723604', Arial, sans-serif;
font-size: 20px;
}
.contact-form label {
display: block;
margin: 0px 0px 15px 0px;
text-transform: uppercase; /* New */
}
.contact-form label > span {
padding-top: 8px;
}
.contact-form label > span, #recaptcha::before {
width: 100px;
text-align: right;
float: left;
padding-right: 20px;
content: "";
}
.contact-form input, .contact-form textarea {
margin-bottom: 15px;
padding: 10px;
border: none;
}
.contact-form input.input-field {
width: 70%;
height: 20px;
font-size: 18px;
}
.contact-form .textarea-field {
height: 250px;
margin-bottom: 11px;
}
.contact-form .textarea-field, .g-recaptcha {
width: 70%;
font-size: 18px;
display: inline-block;
}
.g-recaptcha {
height: 78px !important;
}
#recaptcha {
display: block;
margin: 0px 0px 24px 0px;
}
textarea {
resize: none;
}
textarea:focus, input:focus {
outline: 0;
}
input.submit-button {
background-image: url("../img/submit-button.jpg");
width: 225px;
height: 60px;
border: none;
}
.appraisals .section-title {
width: 100%;
}
#appraisals-form {
width: 100%;
max-width: 700px;
top: auto;
transform: none;
}
#appraisals-form label > span {
width: 150px;
font-size: 16px
}
#appraisals-form span.label-sm {
display: block;
font-size: 14px;
text-transform: none;
}
#appraisals-form input, #appraisals-form textarea {
background-color: #d7d7d7;
}
#appraisals-form textarea {
height: 100px;
}
#appraisals-form .centred-button {
text-align: center;
}
Fiddle: http://jsfiddle.net/tcap2Lcp/.
Any help would really appreciated!
As an alternative to my first answer, which uses CSS positioning properties and width adjustments to align the labels on the left of the input, this solution keeps things very simple with only HTML.
The idea is to display the small labels as placeholder text.
This element gets deleted:
<span class="label-sm">(i.e. sculpture, painting...)</span>
But the text goes into a placeholder:
<label for="name">
<span>Type of Artwork</span>
<input type="text" class="input-field" name="name" required
data-errormessage-value-missing="Please enter your item's type of artwork."
placeholder="(i.e. sculpture, painting...)" >
</label>
And that's it!
Clean, simple, reusable code (as you requested). Easy to maintain. User-friendly. And no changes to the CSS...
unless you decide you want to style the placeholder text.
You can accomplish this task with CSS positioning properties.
HTML
<!-- ADJUSTED BLOCK START -->
<label for="name" style="position: relative; width: 100%;">
<span style="width: 24%; padding: 0; position: relative; left: -2%;">
Type of Artwork</span>
<span style="width: 24%; padding: 0; position: absolute; left: -2%; bottom: 30%;"
class="label-sm">(i.e. sculpture, painting...)</span>
<input style="width: 70%" type="text" name="name"
required data-errormessage-value-missing="Please enter your item's type of artwork.">
</label>
<!-- ADJUSTED BLOCK END-->
DEMO
I used inline styles for brevity and clarity. Hope this helps.
This will nest the two <span> tags without changing the appearnce:
<span>Type of Artwork</span><span class="label-sm">(i.e. sculpture, painting...)</span></span>
I'm unsure what you are trying to achieve though, so not sure if your CSS needs a small change, possibly:
.label-sm {
display: block;
font-size: 14px;
text-transform: none;
}
If i get you right this should work for you - just add float: none; to #appraisals-form span.label-sm.
Here is the whole css:
.contact-form {
margin: 0 auto;
position: relative;
top: 50%;
transform: translateY(-50%);
max-width: 600px;
font-family: 'LinotypeUniversW01-Thin_723604', Arial, sans-serif;
font-size: 20px;
}
.contact-form label {
display: block;
margin: 0px 0px 15px 0px;
text-transform: uppercase; /* New */
}
.contact-form label > span {
padding-top: 8px;
}
.contact-form label > span, #recaptcha::before {
width: 100px;
text-align: right;
float: left;
padding-right: 20px;
content: "";
}
.contact-form input, .contact-form textarea {
margin-bottom: 15px;
padding: 10px;
border: none;
}
.contact-form input.input-field {
width: 70%;
height: 20px;
font-size: 18px;
}
.contact-form .textarea-field {
height: 250px;
margin-bottom: 11px;
}
.contact-form .textarea-field, .g-recaptcha {
width: 70%;
font-size: 18px;
display: inline-block;
}
.g-recaptcha {
height: 78px !important;
}
#recaptcha {
display: block;
margin: 0px 0px 24px 0px;
}
textarea {
resize: none;
}
textarea:focus, input:focus {
outline: 0;
}
input.submit-button {
background-image: url("../img/submit-button.jpg");
width: 225px;
height: 60px;
border: none;
}
.appraisals .section-title {
width: 100%;
}
#appraisals-form {
width: 100%;
max-width: 700px;
top: auto;
transform: none;
}
#appraisals-form label > span {
width: 150px;
font-size: 16px
}
#appraisals-form span.label-sm {
display: block;
font-size: 14px;
text-transform: none;
float: none;
}
#appraisals-form input, #appraisals-form textarea {
background-color: #d7d7d7;
}
#appraisals-form textarea {
height: 100px;
}
#appraisals-form .centred-button {
text-align: center;
}
hope it helps :)
Further explanation
The problem was caused by float: left; at .contact-form label > span which floatet your span in general.
The easyest way is to add this class to CSS :
label {float: left; width: 10em; margin-right: 1em; text-align: right;}
I'm trying to align the reCAPTCHA widget with my input fields, but styling .g-recaptcha doesn't seem to achieve much. Does anyone know of any selectors I can use?
Form HTML:
<div class="contact-form">
<form role="form" method="post" action="contact-form.php">
<label for="name"><span>Name</span><input type="text" class="input-field" name="name" required data-errormessage-value-missing="Please enter your name." /></label>
<label for="email"><span>Email</span><input type="email" class="input-field" name="email" required data-errormessage-value-missing="Please enter your email address." /></label>
<label for="message"><span>Message</span><textarea name="message" class="textarea-field" required data-errormessage-value-missing="Please enter your message."></textarea></label>
<span> </span>
<div id="recaptcha">
<div class="g-recaptcha" data-sitekey="6LcBawsTAAAAAKBPfGs1jApXNRLvR2MIPng0Fxol" style="margin: 0;"></div>
</div>
<label><span> </span><input type="submit" value="" class="submit-button" /></label>
</form>
</div>
CSS:
.contact-form {
margin: 0 auto;
position: relative;
top: 50%;
transform: translateY(-50%);
max-width: 600px;
font-family: 'LinotypeUniversW01-Thin_723604', Arial, sans-serif;
font-size: 20px;
}
.contact-form label {
display: block;
margin: 0px 0px 15px 0px;
}
.contact-form label > span {
width: 100px;
text-align: right;
float: left;
padding-top: 8px;
padding-right: 20px;
}
.contact-form input, .contact-form textarea {
margin-bottom: 15px;
padding: 10px;
border: none;
}
.contact-form input.input-field {
width: 70%;
height: 20px;
font-size: 18px;
}
.contact-form .textarea-field {
width: 70%;
height: 250px;
font-size: 18px;
}
textarea {
resize: none;
}
textarea:focus, input:focus {
outline: 0;
}
#recaptcha {
width: 304px;
margin: 0;
}
.g-recaptcha {
text-align: left;
}
input.submit-button {
background-image: url("../img/submit-button.jpg");
width: 225px;
height: 60px;
border: none;
}
Any help would be really appreciated!
Just modify your existing CSS with this:
.contact-form label, #recaptcha {
display: block;
margin: 0px 0px 15px 0px;
}
.contact-form label > span, #recaptcha::before {
width: 100px;
text-align: right;
float: left;
padding-top: 8px;
padding-right: 20px;
content:""; //Make sure you add this as well
}
.contact-form .textarea-field, .g-recaptcha {
width: 70%;
height: 250px;
font-size: 18px;
display: inline-block;
}
Pseudo elements are used here so that you don't have to change your markup. :before works as a span inside the label thus providing uniformity in your html structure and hence solving the alignment issue
To align reCAPTCHA with rest of the other form-fields you have to change your DOM structure something like this:
HTML:
<label for="captcha">
<span> </span>
<div id="recaptcha">
...
then also change/write the CSS:
#recaptcha {
margin: 0px;
width: 304px;
position: relative;
float: left;
}
#recaptcha iframe {
position: absolute;
left: 0px;
top: 0px;
}
This will do the trick for you.