Arranging inputs within a form - html

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>

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 the input and the button not taking the whole width of the div?

I have the following html code :
.my-form {
width: 100%
}
.search-wrapper {
width: 50%;
margin: 0 auto;
background: #000;
}
.search-query {
border-top-left-radius: 25px;
border-bottom-left-radius: 25px;
padding-left: 3%;
}
.search {
background: #ea7d20;
border-radius: 25px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
position: absolute;
}
<form method="GET" class="my-form">
<div class="search-wrapper">
<input type="search" class="search-query" placeholder="Search">
<input type="submit" value="search" class="search">
<div class="results"></div>
</div>
</form>
Here is a fiddle to view it live:
https://jsfiddle.net/nner02rk/2
I want the search input and submit input to take the full width of .search-wrapper or be centered inside the search-wrapper div.
Lots of ways to accomplish this depending on how you want the element widths distributed. One way is to set the width of your button and use calc to make the input 100% less the specified button width:
.my-form {
width: 100%
}
.search-wrapper {
width: 50%;
margin: 0 auto;
background: #000;
}
.search-query {
border-top-left-radius: 25px;
border-bottom-left-radius: 25px;
padding-left: 3%;
width: calc(100% - 55px);
}
.search {
background: #ea7d20;
border-radius: 25px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
position: absolute;
width: 55px;
}
<form method="GET" class="my-form">
<div class="search-wrapper">
<input type="search" class="search-query" placeholder="Search">
<input type="submit" value="search" class="search">
<div class="results"></div>
</div>
</form>
Another would be to use CSS table layout:
.my-form {
width: 100%
}
.search-wrapper {
width: 50%;
margin: 0 auto;
background: #000;
display: table;
}
.search-wrapper>span {
display: table-cell;
}
.search-query {
border-top-left-radius: 25px;
border-bottom-left-radius: 25px;
padding-left: 3%;
width: 100%;
}
.search {
background: #ea7d20;
border-radius: 25px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
width: 100%;
}
<form method="GET" class="my-form">
<div class="search-wrapper">
<span><input type="search" class="search-query" placeholder="Search"></span>
<span><input type="submit" value="search" class="search"></span>
<div class="results"></div>
</div>
</form>
You can remove your position: absolute in .search and add float: left to both .search-query and .search.
.my-form {
width: 100%
}
.search-wrapper {
width: 50%;
margin: 0 auto;
background: #000;
}
.search-query {
border-top-left-radius: 25px;
border-bottom-left-radius: 25px;
padding-left: 3%;
float: left;
}
.search {
background: #ea7d20;
border-radius: 25px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
float: left;
/* position: absolute; */
}
<form method="GET" class="my-form">
<div class="search-wrapper">
<input type="search" class="search-query" placeholder="Search">
<input type="submit" value="search" class="search">
<div class="results"></div>
</div>
</form>
Add width attribute to the search-query and search classes. Here is an example:
.search-query{
border-top-left-radius: 25px;
border-bottom-left-radius: 25px;
padding-left: 3%;
width: 200px;
}

Add image inside search box?

How can I add an image inside this search box? I'd like the image to be positioned inside and to the left of the palceholder text...
Here is the fiddle
HTML:
<div class="searchbar">
<h1>Welcome...</h1>
<div id="sb-search" class="sb-search">
<div class="search-wrapper">
<input class="search-input" placeholder="Search..." type="text" value="" name="search" id="search"/>
<img class="search-pic"src="img/search-icon.png"/>
</div>
</div>
</div>
thanks
Add this to your CSS which will position the image inside the input field.
.search-wrapper {
position: relative;
}
.search-wrapper img {
position: absolute;
top: 0px;
left: 0px;
}
Then you just need to use padding and change the top and left values to move everything about so it fits nicely and nothing is overlapped.
You might also need to set a width and height to the image so it's not too big for the input field.
You can solve it like this:
#mixin searchbar-font {}
#mixin searchbar-styles {
border: none;
outline: none;
color: $header-bg-color;
padding: 20px 65px 20px 20px;
background: transparent;
flex:1;
}
#mixin search-bar-input {
border: none;
outline: none;
}
.search-input {
border: none;
outline: none;
color: $header-bg-color;
padding: 20px 65px 20px 20px;
background: transparent;
flex:1;
}
.search-wrapper {
position: relative;
background: white;
display: flex;
align-items: center;
.search-input {
#include searchbar-font;
#include searchbar-styles;
}
.search-submit {
#include search-bar-input;
}
}
<div class="searchbar">
<h1>Welcome...</h1>
<div id="sb-search" class="sb-search">
<div class="search-wrapper">
<img class="search-pic" src="img/search-icon.png" />
<input class="search-input" placeholder="Search..." type="text" value="" name="search" id="search" />
</div>
</div>
</div>
Attached Fiddle
Technically you need to set your parent tag's position to relative, then set the image inside's position to absolute. Then you can overlay the image on your Input field. Also, one more thing to remember is you might want to set you z-index. Just in case, your image does not get behind of your input field. Make sure you are giving enough space to for your image by setting the input's padding left to somewhere around your image's width.
.search-wrapper{
.search-input{
padding-left: {image.width}px;
}
img{
position:absolute; left:0; top:0;
}
}
This should do the work.
<div class="search-container">
<input type="text" placeholder="Search...">
<img src="search-icon.png" alt="search icon">
</div>a
.search-container {
display: flex;
align-items: center;
position: relative;
}
input[type="text"] {
border: 1px solid gray;
border-radius: 20px;
padding: 10px 40px 10px 20px;
font-size: 16px;
width: 500px;
}
img {
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
height: 20px;
width: 20px;
}
<div class="search-container">
<input type="text" placeholder="Search...">
<img src="search-icon.png" alt="search icon">
</div>
.search-container {
display: flex;
align-items: center;
position: relative;
}
input[type="text"] {
border: 1px solid gray;
border-radius: 20px;
padding: 10px 40px 10px 20px;
font-size: 16px;
width: 500px;
}
img {
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
height: 20px;
width: 20px;
}

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!

Positioning reCAPTCHA widget with CSS

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.