Place button inside input - html

I need to place a button, with an icon, an input so I tried the HTML:
(JSFiddle Example: https://jsfiddle.net/mdmoura/zup3b24e/12/):
<form>
<div class="wrapper">
<input type="text">
<button type="submit">
<i class="fa fa-search"></i>
</button>
</div>
</form>
With the following CSS:
form {
width: 400px;
}
.wrapper {
position: relative;
}
input {
font-size: 18px;
padding: 10px;
width: 100%;
}
button {
background-color: white;
border: none;
font-size: 24px;
position: absolute;
right: 0;
}
But this does not place the button inside the input.
How can this be done?

All you need to do is to add bottom: 8px; to the button so it is moved up by 8px, visually into the input box.
button {
background-color: white;
border: none;
font-size: 24px;
position: absolute;
right: 0;
bottom: 8px;
}
form {
width: 400px;
}
.wrapper {
position: relative;
}
input {
font-size: 18px;
padding: 10px;
width: 100%;
}
button {
background-color: white;
border: none;
font-size: 24px;
position: absolute;
right: 0;
bottom: 8px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<form>
<div class="wrapper">
<input type="text">
<button type="submit">
<i class="fa fa-search"></i>
</button>
</div>
</form>
Updated JSFiddle: https://jsfiddle.net/zup3b24e/14/

A simpler way to build an input form with font awesome inside if you want to go with this direction
input[type="text"] {
width: 400px;
height: 20px;
padding: 10px;
}
input[type="submit"] {
font-family: FontAwesome;
font-size: 24px;
margin-left: -50px;
background-color: white;
border: none;
-webkit-appearance: none;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<input type="text"><input type="submit" value="">

Related

Problem positioning customized X in a square in the same row

I have a simple square with a yes or no label:
.yesNoSquare {
width: 10px;
height: 10px;
border: 1px solid;
display: inline-block;
}
.yesNoSquare-space {
padding-right: 20px;
}
<div class="textCenter">
<span class="yesNoSquare"></span>
<span class=" yesNoSquare-space itemsTableHeader"> YES</span>
<span class="yesNoSquare"></span>
<span class="itemsTableHeader"> NO</span>
</div>
I want to add an "X" inside the square to do something like this:
.yesNoSquare {
width: 10px;
height: 10px;
border: 1px solid;
display: inline-block;
}
.yesNoSquare-space {
padding-right: 20px;
}
.yesNoSquare-cross {
height: 10px;
width: 10px;
/*background-color: #FA6900;*/
position: relative;
border: 1px solid;
}
.yesNoSquare-cross:after {
position: absolute;
top: -45px;
bottom: 0;
left: 0;
right: 2px;
content: "\2716";
line-height: 100px;
text-align: center;
color: #000000;
}
<div class="textCenter">
<div class="yesNoSquare-cross"></div>
<span class=" yesNoSquare-space itemsTableHeader"> YES</span>
<span class="yesNoSquare"></span>
<span class="itemsTableHeader"> NO</span>
</div>
I used div instead of span because span did not display the square correctly, but when I try it, the square with the "X" does not display in the same line.
The desired result:
Just add display: inline-block; to .yesNoSquare-cross.
.yesNoSquare {
width: 10px;
height: 10px;
border: 1px solid;
display: inline-block;
}
.yesNoSquare-space {
padding-right: 20px;
}
.yesNoSquare-cross {
height: 10px;
width: 10px;
/*background-color: #FA6900;*/
position: relative;
border: 1px solid;
display: inline-block;/*the new code*/
}
.yesNoSquare-cross:after {
position: absolute;
top: -45px;
bottom: 0;
left: 0;
right: 2px;
content: "\2716";
line-height: 100px;
text-align: center;
color: #000000;
}
<div class="textCenter">
<div class="yesNoSquare-cross"></div>
<span class=" yesNoSquare-space itemsTableHeader"> YES</span>
<span class="yesNoSquare"></span>
<span class="itemsTableHeader"> NO</span>
</div>
All that is needed are two standard checkboxes or two standard radio buttons. You can customize the look, once you decide which one you want.
<input type="checkbox" id="check-yes">YES
<input type="checkbox" id="check-no">NO
<hr />
<input type="radio" id="radio-yes" name="yesno">YES
<input type="radio" id="radio-no" name="yesno">NO
Use the semantically correct tags which are <label> and <input type="checkbox"> or <input type="radio">. The example below shows how to customize labels, and checkbox/radio buttons. I used radio buttons since the boxes in OP were labeled "YES" and "NO". By assigning each radio button the same name value (in this case name="yn"), the radio button group become mutually exclusive, meaning that only one radio button can be checked while the other(s) must be unchecked.
html {
font: 300 2ch/1.25 'Segoe UI'
}
fieldset {
display: flex;
align-items: center;
width: max-content;
border-radius: 2px;
}
legend {
font-size: 1.1rem;
}
input {
font: inherit;
font-size: 100%;
}
label {
display: inline-flex;
align-items: center;
margin-right: 1rem;
cursor: pointer;
}
label:first-of-type {
margin-left: 0.45rem;
}
input.x {
display: none;
}
label b {
position: relative;
display: inline-flex;
align-items: center;
margin-right: 0.5rem;
padding: 3px;
border: 0.5px inset black;
border-radius: 2px;
transform: scale(1.75);
}
input.x:checked+label b::before {
content: '\2716';
position: absolute;
z-index: 1;
margin-left: -0.3rem;
font-style: oblique;
font-weight: 900;
font-size: 0.65rem;
line-height: 0.5;
color: #F00;
}
<fieldset>
<legend>Custom Radio Button Group</legend>
<input id='yes' class='x' name='yn' type='radio'>
<label for='yes'><b></b> YES</label>
<input id='no' class='x' name='yn' type='radio'>
<label for='no'><b></b> NO</label>
</fieldset>

I have a problem with form input and links

I don't have that much experience in HTML/CSS. As it says in the title, I have a problem with the input (where it says "What do you think about ?"). I left click on input field so I can write something inside it but when I click the submit logo it is not clickable. And the other problem is with Create account. It is not recognized as a link. The other links work but this one doesn't. It is also not clickable. After I added more CSS code those problems appeared.
Can someone help me with this problem?
P.S : This is a project for a non-programmer friend.
* {
box-sizing: border-box;
}
body {
background: url(images/backgroundWallpaper.jpg) fixed no-repeat center center;
background-size: cover;
margin: 0;
}
#font-face {
font-family: "myFont";
src: url("fonts/coolvetica\ rg.ttf")
}
/* ************************************ HOME PAGE ************************************ */
.header {
background-color: rgb(19, 25, 33);
width: 100%;
height: 140px;
}
.searchbar {
position: relative;
margin-left: 265px;
bottom: 63px;
}
#input {
width: 750px;
height: 48px;
font-size: 17px;
}
#searchbarBtn {
position: relative;
height: 48px;
width: 48px;
font-size: 21px;
top: 2px;
}
#loginBtn {
position: relative;
padding-left: 1140px;
bottom: 95px;
color: white;
font-size: 17px;
}
.logoImg {
width: 240px;
padding-left: 15px;
padding-top: 15px;
}
.viewCart {
color: white;
font-size: 40px;
position: relative;
padding-left: 1370px;
bottom: 128px;
}
.cartBtn {
font-size: 17px;
position: relative;
left: 5px;
bottom: 5px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: blue;
}
nav {
display: inline;
position: relative;
bottom: 37px;
padding-left: 18px;
word-spacing: 15px;
}
.navBtn {
font-size: 17px;
}
header {
background: url(images/headerWallpaper.jpg) center center;
width: 100%;
height: 750px;
margin-top: -20px;
position: relative;
z-index: 1;
}
.main {
padding: 0px 130px;
}
footer {
background-color: rgb(19, 25, 33);
clear: both;
color: white;
text-align: center;
font-size: 17px;
height: 50px;
padding-top: 15px;
font-family: "myFont";
}
<!DOCTYPE html>
<html>
<head>
<title>Danube</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<section class="header">
<img class="logoImg" src="images/logo.png">
<div class="searchbar">
<form>
<input id="input" type="text" placeholder="What do you think about ?" name="search">
<button id="searchbarBtn" type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<div id="loginBtn">Hello, Create account</div>
<div class="viewCart">
<i class="fa fa-shopping-cart"></i>
<a class="cartBtn" href="#">My Basket</a>
</div>
</section>
<nav>
<a class="navBtn" href="#">Home</a>
<a class="navBtn" href="#">Offers</a>
<a class="navBtn" href="#">Products</a>
<a class="navBtn" href="#">Showrooms</a>
<a class="navBtn" href="#">Contact</a>
</nav>
<div class="main">
<header>
</header>
</div>
<footer>
<div>S.C. DANUBE ROMANIA S.R.L. este inregistrata cu numarul 000 / 2022 in registrul de evidenta a prelucrarilor de date cu caracter personal</div>
</footer>
</body>
</html>
There's a lot of problems with the code. Try avoiding fixed values like px for things. Keep your website responsive - you can use flex or something for maintaining a responsive layout.
It is easier to see the problem when you inspect it using Firefox's(or any other browsers) inspecting tool.
You can fix the problems you stated by implementing suggestions told by us here but they may break something else since we don't know the whole code.
Firstly, you can see that the header element is above the search bar and hence the search bar is unfocusable. You can either change the z-index of the header element to -1 or something or you can set the search bar's z-index to a bigger value.
The Create Account link has the same problem as well. In this case,the element with the viewCart class is overlapping the link. What you need to do is in it's style change the padding-left property to margin-left and it will stop overlapping.
Again, try to keep things simple by using a more dynamic way so that elements are positioned and sized automatically instead of you having to specify the sizes yourself.
First of all, the button always have a default cursor, if you want to change the cursor to the pointer on hovering you must add this: button:hover {cursor: pointer}
Second of all, you're using positions wrongly and don't understand them. Read about positions here.
I deleted all of the position relatives and top & bottom.
* {
box-sizing: border-box;
}
body {
background: url(images/backgroundWallpaper.jpg) fixed no-repeat center center;
background-size: cover;
margin: 0;
}
#font-face {
font-family: "myFont";
src: url("fonts/coolvetica\ rg.ttf")
}
/* ************************************ HOME PAGE ************************************ */
.header {
background-color: rgb(19, 25, 33);
width: 100%;
height: 140px;
}
.searchbar {
margin-left: 265px;
}
#input {
width: 750px;
height: 48px;
font-size: 17px;
}
#searchbarBtn {
height: 48px;
width: 48px;
font-size: 21px;
}
/* EDITED HERE */
#searchbarBtn:hover {
cursor: pointer
}
#loginBtn {
padding-left: 1140px;
color: white;
font-size: 17px;
}
.logoImg {
width: 240px;
padding-left: 15px;
padding-top: 15px;
}
.viewCart {
color: white;
font-size: 40px;
position: relative;
padding-left: 1370px;
bottom: 128px;
}
.cartBtn {
font-size: 17px;
position: relative;
left: 5px;
bottom: 5px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: blue;
}
nav {
display: inline;
position: relative;
bottom: 37px;
padding-left: 18px;
word-spacing: 15px;
}
.navBtn {
font-size: 17px;
}
header {
background: url(images/headerWallpaper.jpg) center center;
width: 100%;
height: 750px;
margin-top: -20px;
position: relative;
z-index: 1;
}
.main {
padding: 0px 130px;
}
footer {
background-color: rgb(19, 25, 33);
clear: both;
color: white;
text-align: center;
font-size: 17px;
height: 50px;
padding-top: 15px;
font-family: "myFont";
}
<!DOCTYPE html>
<html>
<head>
<title>Danube</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<section class="header">
<img class="logoImg" src="images/logo.png">
<div class="searchbar">
<form>
<input id="input" type="text" placeholder="What do you think about ?" name="search">
<button id="searchbarBtn" type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<div id="loginBtn">Hello, Create account</div>
<div class="viewCart">
<i class="fa fa-shopping-cart"></i>
<a class="cartBtn" href="#">My Basket</a>
</div>
</section>
<nav>
<a class="navBtn" href="#">Home</a>
<a class="navBtn" href="#">Offers</a>
<a class="navBtn" href="#">Products</a>
<a class="navBtn" href="#">Showrooms</a>
<a class="navBtn" href="#">Contact</a>
</nav>
<div class="main">
<header>
</header>
</div>
<footer>
<div>S.C. DANUBE ROMANIA S.R.L. este inregistrata cu numarul 000 / 2022 in registrul de evidenta a prelucrarilor de date cu caracter personal</div>
</footer>
</body>
</html>
both are incorrectly positioned, they are pushing to the top and some element is overlapping over them.
I recreated your code by positioning them slightly lower using position: relative; top : 100px and then input box was accepting clicks and create link was working.
box-sizing: border-box;
}
body {
background: url(images/backgroundWallpaper.jpg) fixed no-repeat center center;
background-size: cover;
margin: 0;
}
#font-face {
font-family: "myFont";
src: url("fonts/coolvetica\ rg.ttf")
}
/* ************************************ HOME PAGE ************************************ */
.header {
background-color: rgb(19, 25, 33);
width: 100%;
height: 140px;
}
.searchbar {
position: relative;
margin-left: 265px;
bottom: 63px;
}
#input {
width: 750px;
height: 48px;
font-size: 17px;
position: relative;
top: 100px;
}
#searchbarBtn {
position: relative;
height: 48px;
width: 48px;
font-size: 21px;
top: 2px;
}
#loginBtn {
position: relative;
padding-left: 1140px;
color: white;
font-size: 17px;
}
.logoImg {
width: 240px;
padding-left: 15px;
padding-top: 15px;
}
.viewCart {
color: white;
font-size: 40px;
position: relative;
padding-left: 1370px;
bottom: 128px;
}
.cartBtn {
font-size: 17px;
position: relative;
left: 5px;
bottom: 5px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: blue;
}
nav {
display: inline;
position: relative;
bottom: 37px;
padding-left: 18px;
word-spacing: 15px;
}
.navBtn {
font-size: 17px;
}
header {
background: url(images/headerWallpaper.jpg) center center;
width: 100%;
height: 750px;
margin-top: -20px;
position: relative;
z-index: 1;
}
.main {
padding: 0px 130px;
}
footer {
background-color: rgb(19, 25, 33);
clear: both;
color: white;
text-align: center;
font-size: 17px;
height: 50px;
padding-top: 15px;
font-family: "myFont";
}```
Please check the changes in #loginBtn and #input

HTML style into simple search funtion

Im creating one simple html page as a firefox default homepage. I got the search function working, but now i want to add style into the page.
This is my funtion:
<form action="" onsubmit="return false">
<input name="term_1" size="38" maxlength="50" value="" id="searchbox" placeholder="Enter search term.."><br />
<select name="field_1" id="option">
<option value="t" selected="selected">Title</option>
<option value="a">Author</option>
<option value="s">Subject</option>
<option value="call_number">Call Number</option>
<option value="p">Publisher</option>
</select>
<input value="Submit" type="button" onclick=search()>
<input value="Reset" type="reset">
</form>
<script>
function search()
{
var search_input=document.getElementById("searchbox").value;// value of search box
var option=document.getElementById("option").value; //value of select
window.open('http://webpac.kdu.edu.my/search/query?match_1=MUST&field_1=' + option + '&term_1=' + search_input + '&facet_loc=20000&sort=relevance&theme=kdu', 'bswindow'); //proceed with search
}
</script>
I would like style something like this
https://www.w3schools.com/code/tryit.asp?filename=GAQ6A12ICCQF
In order to style something, you must apply CSS.
As per WW3 Schools Search Button Styling
I've modified your HTML code in the following ways to achieve this:
Changed your Submit input to type button to permit an inner text item (which is used for the magnifying glass search symbol).
Converted your Reset input to type button for the same reason as above.
Moved your input[type="term1"] after your select to be inline with the styling brief you supplied.
Included a reference to the FontAwesome library in the head so the refresh & magnifying glass symbols can be utilised
Referenced the refresh & magnifying glass symbols in an <i> tag inside the relevant <button's
Here is the updated HTML with CSS:
* {
font-size: 14px;
}
select {
height: 35px;
border: 1px solid grey;
background: #f1f1f1;
}
input[type="text"] {
height: 30px;
text-indent: 10px;
border: 1px solid grey;
background: #f1f1f1;
}
form {
display: flex;
flex-direction: row;
width: 100%;
}
input[name="term_1"] {
width: 100%;
}
button {
width: 100px;
background-color: #2196F3;
border: 1px solid grey;
color: white;
}
button:hover {
cursor: pointer;
background-color: #0b7dda;
}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<form action="" onsubmit="return false">
<select name="field_1" id="option">
<option value="t" selected="selected">Title</option>
<option value="a">Author</option>
<option value="s">Subject</option>
<option value="call_number">Call Number</option>
<option value="p">Publisher</option>
</select>
<input type="text" name="term_1" size="38" maxlength="50" value="" id="searchbox" placeholder="Enter search term.."><br />
<button type="submit" onclick=search()><i class="fa fa-search" aria-hidden="true"></i></button>
<button type="reset"><i class="fa fa-refresh" aria-hidden="true"></i>
</button>
</form>
<script>
function search() {
var search_input = document.getElementById("searchbox").value; // value of search box
var option = document.getElementById("option").value; //value of select
window.open('http://webpac.kdu.edu.my/search/query?match_1=MUST&field_1=' + option + '&term_1=' + search_input + '&facet_loc=20000&sort=relevance&theme=kdu', 'bswindow'); //proceed with search
}
</script>
Here is a JSFiddle for reference as well.
See W3schools css page for more styles
https://www.w3schools.com/howto/howto_css_searchbar.asp
<div id="cover">
<form method="get" action="">
<div class="tb">
<div class="td"><input type="text" placeholder="Search" required></div>
<div class="td" id="s-cover">
<button type="submit">
<div id="s-circle"></div>
<span></span>
</button>
</div>
</div>
</form>
</div>
*
{
outline: none;
}
html, body
{
height: 100%;
min-height: 100%;
}
body
{
margin: 0;
background-color: #ffd8d8;
}
.tb
{
display: table;
width: 100%;
}
.td
{
display: table-cell;
vertical-align: middle;
}
input, button
{
color: #fff;
font-family: Nunito;
padding: 0;
margin: 0;
border: 0;
background-color: transparent;
}
#cover
{
position: absolute;
top: 50%;
left: 0;
right: 0;
width: 550px;
padding: 35px;
margin: -83px auto 0 auto;
background-color: #ff7575;
border-radius: 20px;
box-shadow: 0 10px 40px #ff7c7c, 0 0 0 20px #ffffffeb;
transform: scale(0.6);
}
form
{
height: 96px;
}
input[type="text"]
{
width: 100%;
height: 96px;
font-size: 60px;
line-height: 1;
}
input[type="text"]::placeholder
{
color: #e16868;
}
#s-cover
{
width: 1px;
padding-left: 35px;
}
button
{
position: relative;
display: block;
width: 84px;
height: 96px;
cursor: pointer;
}
#s-circle
{
position: relative;
top: -8px;
left: 0;
width: 43px;
height: 43px;
margin-top: 0;
border-width: 15px;
border: 15px solid #fff;
background-color: transparent;
border-radius: 50%;
transition: 0.5s ease all;
}
button span
{
position: absolute;
top: 68px;
left: 43px;
display: block;
width: 45px;
height: 15px;
background-color: transparent;
border-radius: 10px;
transform: rotateZ(52deg);
transition: 0.5s ease all;
}
button span:before, button span:after
{
content: '';
position: absolute;
bottom: 0;
right: 0;
width: 45px;
height: 15px;
background-color: #fff;
border-radius: 10px;
transform: rotateZ(0);
transition: 0.5s ease all;
}
#s-cover:hover #s-circle
{
top: -1px;
width: 67px;
height: 15px;
border-width: 0;
background-color: #fff;
border-radius: 20px;
}
#s-cover:hover span
{
top: 50%;
left: 56px;
width: 25px;
margin-top: -9px;
transform: rotateZ(0);
}
#s-cover:hover button span:before
{
bottom: 11px;
transform: rotateZ(52deg);
}
#s-cover:hover button span:after
{
bottom: -11px;
transform: rotateZ(-52deg);
}
#s-cover:hover button span:before, #s-cover:hover button span:after
{
right: -6px;
width: 40px;
background-color: #fff;
}
Demo for the search bar. You can follow this.
or
if you want more different ones. You can check this: https://freefrontend.com/css-search-boxes/

Insert logo in input

am trying to create a field of research. I want to add a logo in the input bar.
Here is my code:
.display-new-chat-window {
.new-chat-window {
display: block;
text-align: center;
z-index: 2;
input:focus {
outline-color: $blue;
}
.new-chat-window-input {
border: 1px solid #ccc;
line-height: 30px;
margin-top: 10px;
padding-left: 15px;
width: 200px;
z-index: 1;
}
}
}
<div class="new-chat-window">
<i class="fa fa-search"></i>
<input type="text" class="new-chat-window-input" id="new-chat-window-input" placeholder="Rechercher" />
</div>
Probably something like this, where L is the logo:
.new-chat-window {
position: relative;
width: 200px;
display: block;
margin: 10px auto;
text-align: center;
z-index: 2;
}
.new-chat-window .fa {
position: absolute;
top: 7px;
left: 10px;
font-weight: bold;
font-style: normal;
}
input:focus {
outline-color: $blue;
}
.new-chat-window-input {
border: 1px solid #ccc;
line-height: 30px;
padding-left: 30px;
width: 100%;
z-index: 1;
}
<div class="new-chat-window">
<i class="fa fa-search">L</i>
<input type="text" class="new-chat-window-input" id="new-chat-window-input" placeholder="Rechercher" />
</div>
You can accomplish this using the background property:
input {
background: url(https://path.to/image);
}
.display-new-chat-window .new-chat-window {
display: block;
text-align: center;
z-index: 2;
}
.display-new-chat-window .new-chat-window input:focus {
outline-color: $blue;
}
.display-new-chat-window .new-chat-window-input {
border: 1px solid #ccc;
line-height: 30px;
margin-top: 10px;
padding-left: 15px;
width: 200px;
z-index: 1;
background: url(https://unsplash.it/15) no-repeat scroll 0 center;
}
<div class="display-new-chat-window">
<div class="new-chat-window">
<i class="fa fa-search"></i>
<input type="text" class="new-chat-window-input" id="new-chat-window-input" placeholder="Rechercher" />
</div>
</div>
Sorry If I misunderstand your point of your question
In this example, I use my own code
html
<input type="text" class="input-logo" placeholder="Paypal id/email">
css
.input-logo{
background-image:url(https://fx-
rate.net/images/favi_transfer/paypal.com.png);
background-position:right;
background-repeat:no-repeat;
padding-left:1px;
font-size: 16px;
width: 200px;
}
for your code, you add my input-logo class and you can style it from there.
Look at:
https://codepen.io/ronalto7777/pen/rzPjoR

Having problems with responsive widths

I tried to make a search block that need to be looking like this:
Now i want when someone will resize the window, the search button will still be in the same line, so i did:
CSS:
.search {
background-color: #23507c;
border: none;
outline: none;
font-size: 18px;
width: 92%
}
#searchButton {
width: 8%;
color: #555555;
font-size: 16px;
}
HTML:
<div id="search">
<form action="search.php" method="POST">
<span class="glyphicon glyphicon-search" style="font-size: 20px;"></span>
<span style="width: 100%;padding:0;margin:0;">
<input type="text" class="search" name="search" placeholder="search for diamonds" />
<button type="submit" id="searchButton"><span class="glyphicon glyphicon-search"></span>
Search</button>
</form>
</span>
</div>
https://jsfiddle.net/kL1m9a8x/15/
What i try to do, is to insert the input and the button to a span that take the width of the blue block execept the glypicon, and than give to the input 80% from the parent element and the button have 20%, but its not working. The line break and the button found in the next line... even when the window is big...
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
#search{
position: relative;
margin: 5%;
}
.search-inner{
display: table;
width: 100%;
background-color: #23507c;
border: none;
outline: none;
font-size: 18px;
}
.search-item{
display: table-cell;
vertical-align: middle;
}
.search-item-1{
width: 82%;
color: #fff;
}
.search-item-1 .glyphicon{
position: absolute; top: 50%; left: 10px;
-webkit-transform: translate(0,-50%);
-ms-transform: translate(0,-50%);
transform: translate(0,-50%);
}
.search-item-2{
text-align: right;
}
input,
button{
border: none;
outline: none;
font-size: 18px;
padding: 10px;
display: inline-block;
}
input{
background-color: #23507c;
color: #fff;
padding-left: 35px;
width: 100%;
}
button{
width: 110px;
}
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">
<div id="search">
<form action="search.php" method="POST">
<div class="search-inner">
<div class="search-item search-item-1">
<span class="glyphicon glyphicon-search"></span>
<input type="text" class="search" name="search" placeholder="search for diamonds" required />
</div>
<div class="search-item search-item-2">
<button type="submit" id="searchButton"><span class="glyphicon glyphicon-search"></span> Search
</button>
</div>
</div>
</form>
</div>
Here is how i would do it:
Basically making the input transparent, giving color to the form element and positioning the button absolutely over it. Note the position:relative on the form element, as position:absolute is always relative to the closest explicitly relative positioned parent.
*, *:before, *:after {
padding:0;
margin:0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
}
form {
background-color: #23507c;
display: block;
padding: 10px 15px;
width: 100%;
color: #fff;
font-size: 16px;
line-height: 24px;
position: relative;
}
form input {
background: transparent;
border: none;
outline: none;
color: #fff;
font-size: 16px;
line-height: 24px;
padding-left: 10px;
}
form button {
display: block;
position: absolute;
top: 10px;
right: 10px;
border: none;
outline: none;
height: 24px;
}
<!-- FontAwesome for icons -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<!-- relevant code -->
<form action="search.php" method="POST">
<i class="fa fa-search"></i>
<input type="text" class="search" name="search" placeholder="search for diamonds" />
<button type="submit" id="searchButton"><i class="fa fa-search"></i> Search
</button>
</form>