HTML form submit button is not vertically centered - html

This is my first time posting, so I hope I'm doing this right.
I want to style a search bar like this one
The problem is, the submit button is always a little off vertically in comparison to the text-input. No matter what I do, there is always at least 1px offset. Help is MUCH appreciated!
I have the following code:
.searchfield{
-webkit-appearance:none;
border: 3px solid #1a5087;
border-right: 0px;
border-radius: 3px;
height: 30px;
font-size: 20px;
margin: 0px;
margin-top: 0px;
outline: 0;
display: inline;
}
.searchbutton{
-webkit-appearance:none;
background-color: #ffb800;
height: 36px;
border: 3px solid #ffb800;
width: 40px;
color: white;
margin-left: -25px;
cursor: pointer;
outline: 0;
background-repeat:no-repeat;
background-position: 2px 2px;
margin-top: 5px;
display: inline;
}
<form action="action.php" method="post">
<input type="number" name="name" placeholder="placeholder" required class="searchfield">
<input type="submit" value="search" class="searchbutton">
</form>

I have tried to rebuilt the same in fiddle. Have a look here
<form class="form-wrapper cf">
<input type="text" placeholder="Search here..." required>
<button type="submit">Search</button>
</form>

A couple of CSS changes should fix the alignment:
Add vertical-align: middle; to both .searchfield and .searchbutton to align them to the middle of each other
Add padding: 0; to .searchfield to remove any padding that the browser may apply to it by default
Remove margin-top: 5px; from .searchbutton to stop it from being pushed down
.searchfield{
-webkit-appearance:none;
border: 3px solid #1a5087;
border-right: 0px;
border-radius: 3px;
height: 30px;
font-size: 20px;
margin: 0px;
margin-top: 0px;
outline: 0;
display: inline;
padding: 0;
vertical-align: middle;
}
.searchbutton{
-webkit-appearance:none;
background-color: #ffb800;
height: 36px;
border: 3px solid #ffb800;
width: 40px;
color: white;
margin-left: -25px;
cursor: pointer;
outline: 0;
background-repeat:no-repeat;
background-position: 2px 2px;
/*margin-top: 5px;*/
display: inline;
vertical-align: middle;
}
<form action="action.php" method="post">
<input type="number" name="name" placeholder="placeholder" required class="searchfield">
<input type="submit" value="search" class="searchbutton">
</form>

Related

Form input shows only borders, they don't focus nor show placeholder html&css

I've been on checking on google still cant find solution for my problem.. whereby my form doesn't work input fields do not respon onfocus, also they don't show placeholders nor value. I'll appreciate if someone can show me the problem if it's my code themselves.
#searchForm {
display: block;
width: 100%;
float: left;
margin: 5px auto 0 auto;
border-top: 0.3px solid white;
}
#searchForm form {
display: block;
width: 100%;
height: auto;
padding: 5px 15px;
float: left;
color: black;
border: 2px solid red;
}
#searchForm form input[type=text] {
display: block;
width: 100%;
height: 35px;
border: 1px solid white;
text-align: center;
background-color: transparent;
}
#searchForm form input[type=submit] {
display: block;
margin: auto;
width: auto;
padding: 3px 5px;
font size: 16px;
color: black;
background-color: transparent;
}
<div id="searchForm">
<form action="header.php" method="POST">
<input type="text" name="que" placeholder="Enter your query and search.." required autofocus />
<input type="submit" name="search" value="Search" />
</form>
</div>

Two inputs without space [duplicate]

This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 5 years ago.
I just created a mailchimp form for my website and want to change the design. But between the email input and the button is a little white empty space. I played already a lot with the css code but I can't fix it by myself. I think it's not a big change but I don't get it correct.
Can you guys help me to remove the space and let me know, where is the issue in my code?
Thanks,
Chris
#mce-EMAIL {
display: inline-block;
padding: 8px 0;
width: 70%;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 1em;
color: #343434;
padding: .7em 9em .7em 2em;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
background-color: rgb(240, 240, 240);
background-image: none;
background-repeat: repeat;
background-attachment: scroll;
background-clip: border-box;
background-origin: padding-box;
background-position-x: 0%;
background-position-y: 0%;
background-size: auto auto;
font-family: "Arial" inherit;
color: #737373;
letter-spacing: 1px;
text-indent: 5%;
border-radius: 5px 0 0 5px;
border-top-left-radius: 5px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 5px;
opacity: 0.9;
border-style: solid;
border: none;
}
/* Input Styles */
.button {
clear: both;
display: inline-block;
width: 25%;
letter-spacing: .03em;
padding: .7em 2em;
border: none;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
height: 46px;
background: #fc2;
font-family: "Arial" inherit;
font-weight: bold;
color: inherit;
letter-spacing: 1px;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background .3s ease-in-out;
}
/* Button Styles */
#mc-embedded-subscribe {
display: inline-block;
width: 20%;
margin: 0;
padding: 0;
}
#mc_embed_signup .mc-field-group input {
/*display: block;*/
/*width: 100%;*/
/*padding: 8px 0;*/
text-indent: 2%;
width: 200px;
}
#mc_embed_signup input.mce_inline_error {
border-color: #6B0505;
}
#mc_embed_signup input {
border: 0px solid #999;
-webkit-appearance: none;
}
#mc_embed_signup .mc-field-group label {
display: block;
margin-bottom: 3px;
}
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="//utz-benkel.us10.list-manage.com/subscribe/post?u=9684bbce9ec8413a5614ca7c3&id=116fd11541" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="NAME#EXAMPLE.COM">
<input type="submit" value="Senden" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_9684bbce9ec8413a5614ca7c3_116fd11541" tabindex="-1" value=""></div>
<div class="clear text-center"></div>
</div>
</form>
</div>
<!--End mc_embed_signup-->
this is because the browser refers to line items as words in the text. and between words it is necessary to put an inter-word interval.
just put a comment between the input, so that there is not a single blank or a line break between them.
#mce-EMAIL {
display: inline-block;
padding: 8px 0;
width: 70%;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 1em;
color: #343434;
padding: .7em 9em .7em 2em;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
background-color: rgb(240, 240, 240);
background-image: none;
background-repeat: repeat;
background-attachment: scroll;
background-clip: border-box;
background-origin: padding-box;
background-position-x: 0%;
background-position-y: 0%;
background-size: auto auto;
font-family: "Arial" inherit;
color: #737373;
letter-spacing: 1px;
text-indent: 5%;
border-radius: 5px 0 0 5px;
border-top-left-radius: 5px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 5px;
opacity: 0.9;
border-style:solid;
border: none;
} /* Input Styles */
.button {
clear: both;
display: inline-block;
width: 25%;
letter-spacing: .03em;
padding: .7em 2em;
border: none;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
height: 46px;
background: #fc2;
font-family: "Arial" inherit;
font-weight: bold;
color: inherit;
letter-spacing: 1px;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background .3s ease-in-out;
} /* Button Styles */
#mc-embedded-subscribe{
display: inline-block;
width: 20%;
margin: 0;
padding: 0;
}
#mc_embed_signup .mc-field-group input {
/*display: block;*/
/*width: 100%;*/
/*padding: 8px 0;*/
text-indent: 2%;
width: 200px;
}
#mc_embed_signup input.mce_inline_error {
border-color: #6B0505;
}
#mc_embed_signup input {
border: 0px solid #999;
-webkit-appearance: none;
}
#mc_embed_signup .mc-field-group label {
display: block;
margin-bottom: 3px;
}
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="//utz-benkel.us10.list-manage.com/subscribe/post?u=9684bbce9ec8413a5614ca7c3&id=116fd11541" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="NAME#EXAMPLE.COM"><!--
--><input type="submit" value="Senden" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_9684bbce9ec8413a5614ca7c3_116fd11541" tabindex="-1" value=""></div>
<div class="clear text-center"></div>
</div>
</form>
</div>
<!--End mc_embed_signup-->
I think best solution is display: flex. No more additional css.. It remove white space and make both input height equal.
Basic concepts of flexbox
.mc-field-group {
display: flex;
}
.mc-field-group {
display: flex;
}
#mce-EMAIL {
display: inline-block;
padding: 8px 0;
width: 70%;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 1em;
color: #343434;
padding: .7em 9em .7em 2em;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
background-color: rgb(240, 240, 240);
background-image: none;
background-repeat: repeat;
background-attachment: scroll;
background-clip: border-box;
background-origin: padding-box;
background-position-x: 0%;
background-position-y: 0%;
background-size: auto auto;
font-family: "Arial" inherit;
color: #737373;
letter-spacing: 1px;
text-indent: 5%;
border-radius: 5px 0 0 5px;
border-top-left-radius: 5px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 5px;
opacity: 0.9;
border-style:solid;
border: none;
} /* Input Styles */
.button {
clear: both;
display: inline-block;
width: 25%;
letter-spacing: .03em;
padding: .7em 2em;
border: none;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
height: 46px;
background: #fc2;
font-family: "Arial" inherit;
font-weight: bold;
color: inherit;
letter-spacing: 1px;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background .3s ease-in-out;
} /* Button Styles */
#mc-embedded-subscribe{
display: inline-block;
width: 20%;
margin: 0;
padding: 0;
}
#mc_embed_signup .mc-field-group input {
/*display: block;*/
/*width: 100%;*/
/*padding: 8px 0;*/
text-indent: 2%;
width: 200px;
}
#mc_embed_signup input.mce_inline_error {
border-color: #6B0505;
}
#mc_embed_signup input {
border: 0px solid #999;
-webkit-appearance: none;
}
#mc_embed_signup .mc-field-group label {
display: block;
margin-bottom: 3px;
}
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="//utz-benkel.us10.list-manage.com/subscribe/post?u=9684bbce9ec8413a5614ca7c3&id=116fd11541" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="NAME#EXAMPLE.COM">
<input type="submit" value="Senden" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_9684bbce9ec8413a5614ca7c3_116fd11541" tabindex="-1" value=""></div>
<div class="clear text-center"></div>
</div>
</form>
</div>
<!--End mc_embed_signup-->
The issue is the white space between your two elements. The input element are inline elements and the white space between them is displayed as a single space. There are several ways to solve it and you can even use a different design like is suggested in the other answer, but you solve it in your current design by simply removing all the white space between the two elements, like this:
#mce-EMAIL {
display: inline-block;
padding: 8px 0;
width: 70%;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 1em;
color: #343434;
padding: .7em 9em .7em 2em;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
background-color: rgb(240, 240, 240);
background-image: none;
background-repeat: repeat;
background-attachment: scroll;
background-clip: border-box;
background-origin: padding-box;
background-position-x: 0%;
background-position-y: 0%;
background-size: auto auto;
font-family: "Arial" inherit;
color: #737373;
letter-spacing: 1px;
text-indent: 5%;
border-radius: 5px 0 0 5px;
border-top-left-radius: 5px;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 5px;
opacity: 0.9;
border-style: solid;
border: none;
}
/* Input Styles */
.button {
clear: both;
display: inline-block;
width: 25%;
letter-spacing: .03em;
padding: .7em 2em;
border: none;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 0;
height: 46px;
background: #fc2;
font-family: "Arial" inherit;
font-weight: bold;
color: inherit;
letter-spacing: 1px;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background .3s ease-in-out;
}
/* Button Styles */
#mc-embedded-subscribe {
display: inline-block;
width: 20%;
margin: 0;
padding: 0;
}
#mc_embed_signup .mc-field-group input {
/*display: block;*/
/*width: 100%;*/
/*padding: 8px 0;*/
text-indent: 2%;
width: 200px;
}
#mc_embed_signup input.mce_inline_error {
border-color: #6B0505;
}
#mc_embed_signup input {
border: 0px solid #999;
-webkit-appearance: none;
}
#mc_embed_signup .mc-field-group label {
display: block;
margin-bottom: 3px;
}
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="//utz-benkel.us10.list-manage.com/subscribe/post?u=9684bbce9ec8413a5614ca7c3&id=116fd11541" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="NAME#EXAMPLE.COM"><input type="submit" value="Senden" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;"><input type="text" name="b_9684bbce9ec8413a5614ca7c3_116fd11541" tabindex="-1" value=""></div>
<div class="clear text-center"></div>
</div>
</form>
</div>
<!--End mc_embed_signup-->
Although this is a simple solution, it is not very elegant to have many elements on one long line. To split the line, you can make use of one HTML features which ignores the white space inside the tags, so just split inside the tags like this:
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="NAME#EXAMPLE.COM"
><input type="submit" value="Senden" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
Or like this:
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="NAME#EXAMPLE.COM"><
input type="submit" value="Senden" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
Or you can convert the white space to a comment like this:
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="NAME#EXAMPLE.COM"><!--
--><input type="submit" value="Senden" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
Please note that most editors may break those solutions when they reformat your HTML, so either avoid reformatting or reapply the fix afterwards.

Input:focus not working

At first my input focus was working just fine, now all of a sudden when I add a couple of more styles to my input, it suddenly stops working. I've only added the 'input[type="text"] and border-radius and padding and some margins since when it was working. When you click each form element, nothing happens even though I have a rule for focus(which you can find near the bottom of the code). Is there any workaround for this?
form{
position: absolute;
left: 50%;
color: white;
margin-left: -180px;
padding: 15px 30px 15px 30px;
background-color: #26004d;
border-radius: 7px;
margin-top: 10px;
width: 300px;
}
label{
float: left;
text-align: right;
margin-right: 15px;
width: 100px;
}
input:focus {
border: 2px solid #862d59;
}
input[type="submit"]{
width: 50%;
background-color: #862d59;
color: white;
margin-top: 5px;
padding: 12px 12px;
border: none;
cursor: pointer;
}
input[type="text"]{
width: 100%;
padding: 12px 12px;
margin: 4px 0;
border: 1px solid #ccc;
border-radius: 6px;
//box-sizing: border-box;
}
<div id="formholder1">
<form>
<div class="single-field">
<label for="Username">Username:</label>
<input name="Name" type="text"></input>
</div>
<div class="single-field">
<label for="Password">Password:</label>
<input name="Password" type="text"></input>
</div>
<input type="submit" value="Login">
</form>
</div>
Use this input[type="text"]:focus {
border: 2px solid #862d59;
}
learn it - http://www.w3schools.com/cssref/trysel.asp?selector=:focus
example - https://css-tricks.com/snippets/css/glowing-blue-input-highlights/
now its working
form{
position: absolute;
left: 50%;
color: white;
margin-left: -180px;
padding: 15px 30px 15px 30px;
background-color: #26004d;
border-radius: 7px;
margin-top: 10px;
width: 300px;
}
label{
float: left;
text-align: right;
margin-right: 15px;
width: 100px;
}
input[type="text"]:focus {
border: 2px solid #862d59;
}
input:focus {
border: 2px solid red;
}
input[type="submit"]{
width: 50%;
background-color: #862d59;
color: white;
margin-top: 5px;
padding: 12px 12px;
border: none;
margin-left:-10px;
cursor: pointer;
}
input[type="text"]{
width: 100%;
padding: 12px 12px;
margin: 4px 0;
border: 1px solid #ccc;
border-radius: 6px;
margin-left:-15px;
//box-sizing: border-box;
}
<div id="formholder1">
<form>
<div class="single-field">
<label for="Username">Username:</label>
<input name="Name" type="text"></input>
</div>
<div class="single-field">
<label for="Password">Password:</label>
<input name="Password" type="text"></input>
</div>
<input type="submit" value="Login">
</form>
</div>
Put Your :focus property after input.
input[type="text"]:focus {
border: 5px solid #862d59;
}
form{
position: absolute;
left: 50%;
color: white;
margin-left: -180px;
padding: 15px 30px 15px 30px;
background-color: #26004d;
border-radius: 7px;
margin-top: 10px;
width: 300px;
}
label{
float: left;
text-align: right;
margin-right: 15px;
width: 100px;
}
input[type="submit"]{
width: 50%;
background-color: #862d59;
color: white;
margin-top: 5px;
padding: 12px 12px;
border: none;
cursor: pointer;
}
input[type="text"]{
width: 100%;
padding: 12px 12px;
margin: 4px 0;
border: 1px solid #ccc;
border-radius: 6px;
box-sizing: border-box;
}
input[type="text"]:focus {
border: 5px solid #862d59;
}
<div id="formholder1">
<form>
<div class="single-field">
<label for="Username">Username:</label>
<input name="Name" type="text"></input>
</div>
<div class="single-field">
<label for="Password">Password:</label>
<input name="Password" type="text"></input>
</div>
<input type="submit" value="Login">
</form>
</div>

Have the submit button uncentered

I'm trying to create a login "panel" kindof.
I just want the submit button right next to the password field but without it centering with the password field.
I have tried to uncenter the Submit button but it doesn't work.
.login input:focus {
border-color: #419ebf;
outline-width: 0;
}
.login {
cursor: default;
margin-top: 100px;
text-align: center;
}
.login .fields {
background-color: rgba(0, 0, 0, 0.18);
border-color: #b8bfb7;
width: 325px;
height: 50px;
font-family:'Exo', sans-serif;
font-size: 30px;
color: White;
border-radius: 7px;
padding-left: 4px;
padding-right: 4px;
margin: 5px auto;
}
.login .submit {
width: 150px;
height: 50px;
background-color: rgba(0, 0, 0, 0.18);
border-color: #b8bfb7;
font-family:'Exo', sans-serif;
font-size: 30px;
color: White;
border-radius: 7px;
}
<form method="post" action="login.php" class="login">
<input class="fields" type="text" name="username" placeholder="Username" />
<br/>
<input class="fields" type="password" name="password" placeholder="Password" />
<input class="submit" type="submit" value="Login">
</form>
Thanks for the help
You could consider two things:
If your application is always displayed on fixed width, you might like to try use position: fixed; instead of centering all items and using newline.
If you'd like to be more flexible, find an anchestor or container element and use position: absolute;.
More information on positioning elements through CSS can be found here.
Try to delete
text-align: center;
in
.login{
cursor: default;
margin-top: 100px;
text-align: center;
}
I have removed text-align: center; from .login, added width: 500px; and changed margins to margin: 100px auto 0 auto;
.login {
cursor: default;
margin: 100px auto 0 auto;
width: 500px;
}
.login input:focus {
border-color: #419ebf;
outline-width: 0;
}
.login .fields {
background-color: rgba(0, 0, 0, 0.18);
border-color: #b8bfb7;
width: 325px;
height: 50px;
font-family:'Exo', sans-serif;
font-size: 30px;
color: White;
border-radius: 7px;
padding-left: 4px;
padding-right: 4px;
margin: 5px auto;
}
.login .submit {
width: 150px;
height: 50px;
background-color: rgba(0, 0, 0, 0.18);
border-color: #b8bfb7;
font-family:'Exo', sans-serif;
font-size: 30px;
color: White;
border-radius: 7px;
}
<form method="post" action="login.php" class="login">
<input class="fields" type="text" name="username" placeholder="Username" />
<br/>
<input class="fields" type="password" name="password" placeholder="Password" />
<input class="submit" type="submit" value="Login">
</form>

Chrome display issue with input tag

I have the following code:
.searchdiv {
width: 140px;
height: 35px;
margin-left: 17px;
margin-top: 12px;
border-width: 2px;
border-style: solid;
border-radius: 4px;
border-color: #707070;
}
.searchbox {
padding: 3px;
font-size: 16px;
font-weight: bold;
background-color: #121212;
color: #6b6b6b;
border-color: #121212;
width: 100px;
height: 25px;
}
.searchbox:focus {
outline: none;
}
.maglass {
position: fixed;
top: 57px;
left: 125px;
}
.maglass:focus {
outline: none;
}
<div class="searchdiv">
<form action="/search.njs" method="GET">
<input class="searchbox" type="text" name="query" value="" />
<input class="maglass" type="image" src="/res/maglass.png">
</img>
</form>
</div>
When I run this, It outputs as:
I would like to know what causes the black border, since none of the colors I specified include it.
I tried removing the border-color property, but that causes the entire border to be grey.
Why does the black(ish) border show up on Chrome?
The issue is because of the default UA settings in Chrome for the input box. The value is by default set to inset (can be seen from the Developer Console) and this is the one that seems to be causing the blackish (it is not black, it seems to be a semi-transparent black) inset border on the element.
The problem is more apparent to see when the border and background colors are changed. I have set some high contrast colors in the below snippet to visualize it.
.searchdiv {
width: 140px;
height: 35px;
margin-left: 17px;
margin-top: 12px;
border-width: 2px;
border-style: solid;
border-radius: 4px;
border-color: #707070;
}
.searchbox {
padding: 3px;
font-size: 16px;
font-weight: bold;
background-color: #121212;
color: #6b6b6b;
border-color: #121212;
width: 100px;
height: 25px;
}
.searchbox:focus {
outline: none;
}
.maglass {
position: fixed;
top: 57px;
left: 125px;
}
.maglass:focus {
outline: none;
}
/* Just for demo */
.searchbox.contrast {
background-color: yellow;
border-color: yellow;
}
.searchdiv {
margin-top: 20px;
}
<div class="searchdiv">
<form action="/search.njs" method="GET">
<input class="searchbox" type="text" name="query" value="" />
<input class="maglass" type="image" src="/res/maglass.png">
</form>
</div>
<div class="searchdiv">
<form action="/search.njs" method="GET">
<input class="searchbox contrast" type="text" name="query" value="" />
<input class="maglass" type="image" src="/res/maglass.png">
</form>
</div>
What is the solution?
The solution to this is very simple. Just override the default border-style and set it to solid like in the below snippet.
.searchdiv {
width: 140px;
height: 35px;
margin-left: 17px;
margin-top: 12px;
border-width: 2px;
border-style: solid;
border-radius: 4px;
border-color: #707070;
}
.searchbox {
padding: 3px;
font-size: 16px;
font-weight: bold;
background-color: #121212;
color: #6b6b6b;
border-style: solid;
border-color: #121212;
width: 100px;
height: 25px;
}
.searchbox:focus {
outline: none;
}
.maglass {
position: fixed;
top: 57px;
left: 125px;
}
.maglass:focus {
outline: none;
}
/* Just for demo */
.searchbox.contrast {
background-color: yellow;
border-color: yellow;
}
.searchdiv {
margin-top: 20px;
}
<div class="searchdiv">
<form action="/search.njs" method="GET">
<input class="searchbox" type="text" name="query" value="" />
<input class="maglass" type="image" src="/res/maglass.png">
</form>
</div>
<div class="searchdiv">
<form action="/search.njs" method="GET">
<input class="searchbox contrast" type="text" name="query" value="" />
<input class="maglass" type="image" src="/res/maglass.png">
</form>
</div>