Positioning reCAPTCHA widget with CSS - html

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.

Related

Independant margin for the submit button and the text input

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/

Why is this div completely broken?

I have no idea whats going on here. Have a form contained in a div, and the div has a background color.
It works on one part of my website, but just doesn't work at all on another. Here's a Jsfiddle of whats going on
Also the affected code posted here:
form {
text-align: center;
}
input {
font-family: 'Cabin', sans-serif;
}
.submit-button {
text-decoration: none;
width: 80%;
background-color: white;
text-align: center;
height: 35px;
border-radius: 10px;
display: inline-block;
}
.input-half {
width: 40%;
display: inline-block;
float: left;
margin-left: 5%;
margin-right: 5%;
}
.input-half-2 {
width: 40%;
display: inline-block;
float: right;
margin-left: 5%;
margin-right: 5%;
}
input[type=text]:focus {
background-color: lightblue;
}
.contact-contain {
background-color: lightgray;
max-width: 100%;
}
.image-back {
width: 100%;
}
#back-img {
width: 100%
}
.cont-textarea {
resize: none;
width: 80%;
height: 110px;
}
<div class="contact-contain" id="link-c"><br>
<h1>Contact Over The Horizon:</h1><br><br>
<form>
<div class="input-half">
<label for="contname">Your Name</label><br>
<input class="input-box" type="text" name="contname"><br>
<label for="eaddress">Your Email</label><br>
<input class="input-box" type="text" name="eaddress"><br>
<label for="subj">Message Subject</label><br>
<input class="input-box" type="text" name="subj">
</div>
<div class="input-half-2">
<label for="contactmsg">Message Content</label><br><br>
<textarea class="cont-textarea"></textarea><br><br>
<button class="submit-button" type="submit" name="submitq" value="Send"><span>Submit Quote</span></button><br>
</div>
</form>
</div><br>
Wild guess: You want your div to contain your form (which has zero height). Do this:
.contact-contain {
overflow: hidden;
}
Demo
Trust me you will get better with time, but I think, to achieve what you want you can simply set a custom body background-color like this
body {background-color: lightgray;}
and you should be good

Positioning textarea label above (with or without table)

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!

Align multiple labels to left of form input

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;}

The content of a HTML date input field is shifting to the left when I input data in it

I don't know how to fix this problem. In my HTML form I have 2 ´input[type="date"]` fields like this:
<div class="search-wrapper">
<div class="advanced-search">
<form>
<input type="text" placeholder="Dateiname">
<input type="text" placeholder="Benutzer">
<input type="date" placeholder="Erstelldatum">
<input type="date" placeholder="Änderungsdatum">
<textarea placeholder="Erste Zeile"></textarea>
<select>
<option disabled selected>Kategorie</option>
<option>Rechnungen</option>
<option>Notizen</option>
</select>
<select>
<option disabled selected>Projekt</option>
</select>
<img id="advSearchSubmit" src="icons/search.png" />
</form>
</div>
</div>
And the corresponding SCSS:
.search-wrapper {
position: fixed;
.advanced-search {
display: none;
float: right;
width: 600px;
padding: 40px 10px 10px 10px;
background-color: $accent-color;
color: $font-color-secondary;
overflow: hidden;
img {
vertical-align: top;
width: 25px;
height: 25px;
margin-top: 10px;
cursor: pointer;
}
input[type="text"], input[type="date"], select, textarea {
vertical-align: top;
width: 110px;
height: 25px;
margin: 10px;
padding: 2px;
background: $data-background-color;
color: #555;
border: 1px solid $background-color;
outline-color: $main-color;
font-size: 100%;
}
textarea {
height: 2em;
width: 41.2em;
}
}
}
As soon as I enter a date in the input field it gets shifted to the left and is not fully visible. Here is what it looks like when I don't have anything entered in the input field and when there is something entered:
Date Input Screenshot
How do I fix this behaviour?
I managed to fix it myself. I just had to increase the width of the input[type="date"] field to at least 120px
.search-wrapper and .advanced-search missing closing braces
remove display none property if you are using it without js
.search-wrapper {
position: fixed;
}
.advanced-search {
float: right;
width: 600px;
padding: 40px 10px 10px 10px;
background-color: $accent-color;
color: $font-color-secondary;
overflow: hidden;
}
img {
vertical-align: top;
width: 25px;
height: 25px;
margin-top: 10px;
cursor: pointer;
}
input[type="text"], input[type="date"], select, textarea {
vertical-align: top;
width: 110px;
height: 25px;
margin: 10px;
padding:0px 4px;
box-sizing: border-box;
padding: 2px;
background: $data-background-color;
color: #555;
border: 1px solid $background-color;
outline-color: $main-color;
font-size: 100%;
}
input[type="date"]{
width:140px; }
textarea {
height: 2em;
width: 41.2em;
}