Form input, when focused, causes submit button to move slightly - css

thanks for the help, I bet this is an easy fix.
I've applied a custom :focus to my input which removes the default outline (glow) and adds a box shadow and border. The only problem is that when the input field is focused, because of the border and box shadow, the submit button, which rests to the right of the input, jumps to the right about a pixel or two. Very annoying.
JSFiddle: http://jsfiddle.net/D3k3B/
<form action="#" method="get">
<input type="text" name="email" placeholder="Your email">
<input type="Submit" name="submit" value="Go">
</form>
form {
position: absolute;
bottom: 20%;
width: 400px;
left: 50%;
margin-left: -125px;
}
input[name="email"] {
font-family: "Prosto One";
width: 200px;
height: 25px;
font-size: 14px;
background-color: rgba(0,0,0,.4);
border: none;
border-radius: 10px;
color: white;
}
input:focus {
outline: none;
border: 1px solid yellow;
box-shadow: 0px 0px 10px yellow;
}
input[name="submit"] {
margin: -5px;
width: 50px;
}
Thanks!

set border 1px solid transparent to input[name="email"]
input[name="email"] {
font-family: "Prosto One";
width: 200px;
height: 25px;
font-size: 14px;
background-color: rgba(0,0,0,.4);
border: 1px solid transparent;
border-radius: 10px;
color: white;
}

You need to match your border css with a transparent value so they don't move when applied
input[name="email"] {
font-family: "Prosto One";
border: 1px solid transparent;
width: 200px;
height: 25px;
font-size: 14px;
background-color: rgba(0,0,0,.4);
border-radius: 10px;
color: white;
}
working example:
http://jsfiddle.net/whiteb0x/D3k3B/3/

Related

Aligning form elements on right side - text fields and submit button

I have tried many things to try to get the right side of these text fields to align with the submit button, but to no avail.
The button seems to be okay (correct spacing between the button and the frameset border, but the text fields go over.
What could be the problem?
#loginform {
width: 580px;
background-color: rgb(200,200,200);
opacity: 0.8;
font-size: 1.5em;
border: #00a0d0 5px solid;
padding: 30px;
}
.logintextfield {
font-size: 1em;
width: 100%;
}
.loginbutton {
font-size: 1em;
height: 2em;
background-color: #689C41;
width: 100%;
border-top: lightgreen;
border-left: lightgreen;
border-right: darkgreen;
border-bottom: darkgreen;
border-style: solid;
border-width: 2px;
}
Include box-sizing:border-box for all elements in your CSS to specify they should have padding and border included in the element's total width and height
* {
box-sizing: border-box;
}
#loginform {
width: 580px;
background-color: rgb(200,200,200);
opacity: 0.8;
font-size: 1.5em;
border: #00a0d0 5px solid;
padding: 30px;
}
.logintextfield {
font-size: 1em;
width: 100%;
}
.loginbutton {
font-size: 1em;
height: 2em;
background-color: #689C41;
width: 100%;
border-top: lightgreen;
border-left: lightgreen;
border-right: darkgreen;
border-bottom: darkgreen;
border-style: solid;
border-width: 2px;
}
<form id="loginform">
<fieldset>
<legend>SIGN IN</legend>
<input type="text" class="logintextfield"><br>
<input type="text" class="logintextfield"><br>
<input type="submit" class="loginbutton" value="submit">
</fieldset>
</form>

HTML5 / CSS input field with image as submit-button inside the input field

I tried to get an input field with an submit-button inside it. Instead of using the "normal" submit button, I tried to insert a small icon into the input-field, but without any success. I wasn't able to get the image (dimensions 30*30 pixels) inside my input-field.
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
position: relative;
width: 200px;
height: 36px;
box-sizing: border-box;
border: 2px solid #4d7fc3;
border-radius: 4px;
font-size: 16px;
background-color: white;
padding: 2px 2px 2px 10px;
}
input[type=submit] {
position: absolute
width: 30px;
height: 30px;
top: 0px;
right: 0px;
/* background-color: #4d7fc3; */
border: none;
color: white;
background-image: url('file:///C|/Users/heilemann/Pictures/LoginPfeil.JPG');
display: block;
background-position: 100px 100px 100px 100px; */
/* background-repeat: no-repeat; */
/* padding: 2px 2px 2px 30px; */
z-index: -1;
margin: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<p>Input with icon:</p>
<form>
<div id="Search">
<input type="text" name="search" placeholder="Search..">
<input type="submit" value="">
</div>
</form>
</body>
</html>
It should look like this:
There were quite a few errors in the code you pasted up above which weren't doing you any favors.
You left out a ; after the position: absolute; property in your submit input. In order to then have that element positioned properly, you need the parent container to be position: relative;. In this case, the parent container was #Search.
Once that was taken care of there was quite a few properties that could be removed due to being unnecessary. See if my code below helps...
#Search {
position: relative;
display: inline-block;
}
input[type=text] {
position: relative;
width: 200px;
height: 36px;
box-sizing: border-box;
border: 2px solid #4d7fc3;
border-radius: 4px;
font-size: 16px;
background-color: white;
/* 40px padding to account for submit */
padding: 2px 40px 2px 10px;
}
input[type=submit] {
position:absolute;
width: 30px;
height: 100%;
top: 0px;
right: 0px;
border: none;
color: white;
background: url('file:///C|/Users/heilemann/Pictures/LoginPfeil.JPG') #4d7fc3 center center no-repeat;
display: block;
cursor: pointer;
}
Working codepen here.
Just a heads up that your background image for the submit is referencing a local file on your machine, so no one else can actually see it other than you. Be sure to assign it the correct path in relation from the index.html file.
Hope this helps.
Here it is done with HTML and CSS.
/*Clearing Floats*/
.cf:before, .cf:after{
content: "";
display: table;
}
.cf:after{
clear: both;
}
.cf{
zoom: 1;
}
/* Form wrapper styling */
.form-wrapper {
width: 450px;
padding: 15px;
margin: 150px auto 50px auto;
background: #444;
background: rgba(0, 0, 0, .2);
border-radius: 10px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .4) inset, 0 1px 0 rgba(255, 255, 255, .2);
}
/* Form text input */
.form-wrapper input {
width: 330px;
height: 20px;
padding: 10px 5px;
float: left;
font: bold 15px 'lucida sans', 'trebuchet MS', 'Tahoma';
border: 0;
background: #eee;
border-radius: 3px 0 0 3px;
}
.form-wrapper input:focus {
outline: 0;
background: #fff;
box-shadow: 0 0 2px rgba(0, 0, 0, .8) inset;
}
.form-wrapper input::-webkit-input-placeholder {
color: #999;
font-weight: normal;
font-style: italic;
}
.form-wrapper input:-moz-placeholder {
color: #999;
font-weight: normal;
font-style: italic;
}
.form-wrapper input:-ms-input-placeholder {
color: #999;
font-weight: normal;
font-style: italic;
}
/* Form submit button */
.form-wrapper button {
overflow: visible;
position: relative;
float: right;
border: 0;
padding: 0;
cursor: pointer;
height: 40px;
width: 110px;
font: bold 15px/40px 'lucida sans', 'trebuchet MS', 'Tahoma';
color: #fff;
text-transform: uppercase;
background: #d83c3c;
border-radius: 0 3px 3px 0;
text-shadow: 0 -1px 0 rgba(0, 0, 0, .3);
}
.form-wrapper button:hover{
background: #e54040;
}
.form-wrapper button:active,
.form-wrapper button:focus{
background: #c42f2f;
outline: 0;
}
.form-wrapper button:before { /* Left arrow */
content: '';
position: absolute;
border-width: 8px 8px 8px 0;
border-style: solid solid solid none;
border-color: transparent #d83c3c transparent;
top: 12px;
left: -6px;
}
.form-wrapper button:hover:before{
border-right-color: #e54040;
}
.form-wrapper button:focus:before,
.form-wrapper button:active:before{
border-right-color: #c42f2f;
}
.form-wrapper button::-moz-focus-inner { /* Remove extra button spacing for Mozilla Firefox */
border: 0;
padding: 0;
}
<form class="form-wrapper cf">
<input type="text" placeholder="Search..." required>
<button type="submit">Search</button>
</form>
tried both variants, both variants will work, second solution comes clothest

How to make below style:

I'd like to achieve something like this:
I've done this so far:
just wondering, how to make a purple area with little arrow button and once user click it, it would invoke something.
Here is the html and css code I have:
<div class="searchy">
<input type="search" name="ttsearch" data-style="mini" data-theme="d" placeholder="Search here..." class="fdSearch" value=""/>
</div>
CSS:
.searchy{
height: 60px;
background-color: #555;
color: #FFF;
margin-left: -15px;
margin-right: -15px;
}
.fdSearch{
background-color: white;
border-radius: 10px;
border: 5px solid #E5E4E2;
margin: 2px;
margin-left: -15px;
margin-right: -15px;
height: 40px;
vertical-align: middle;
padding: 20px;
margin-top: 15px;
width: 85%;
}
===================update==========================
Thank you guys....They all works. I just pick up one for the right answer.
I've learnt a lot from codes with different version of answers below. Thank you for your help again.
Fiddle: http://jsfiddle.net/hBdMz/
Css:
.form-wrapper {
width: auto;
padding:4px;
background: #555;
clear:both;
display:table;
}
/* Form text input */
.form-wrapper input {
width: 330px;
height: 20px;
padding: 10px 5px;
float: left;
border: 0;
background: white;
border-radius: 3px 0 0 3px;
outline:none;
}
/* Form submit button */
.form-wrapper button {
overflow: visible;
position: relative;
float: right;
border: 0;
padding: 0;
cursor: pointer;
height: 40px;
width: 110px;
color: black;
text-transform: uppercase;
background: #9B30FF;
border-radius: 0 3px 3px 0;
text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3);
}
.form-wrapper button:before {
content: '';
position: absolute;
border-width: 8px 8px 8px 0;
border-style: solid solid solid none;
border-color: transparent #9B30FF transparent;
top: 12px;
left: -6px;
}
Html:
<div class="form-wrapper">
<input type="text" placeholder="Search here..." required>
<button type="submit">Search</button>
</div>
Adapted from: speckyboy
Check This Fiddle
HTML
<div class="searchy">
<input type="search" name="ttsearch" data-style="mini" data-theme="d" placeholder="Search here..." class="fdSearch"
value=""/>
<button type="submit">Submit</button>
</div>
CSS
.searchy {
background: grey;
padding: 50px 20px;
}
input {
border:none;
background: none;
border-top: 3px solid #e1e1e1;
border-left: 3px solid #e1e1e1;
border-bottom: 3px solid #e1e1e1;
padding: 10px 3px;
}
button {
border:none;
background: #4fd577;
padding: 9px 10px;
margin-left: -5px;
border-top: 3px solid #e1e1e1;
border-right: 3px solid #e1e1e1;
border-bottom: 3px solid #e1e1e1;
}
button { position: relative; background: #4fd577; }
button:after { right: 100%; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; }
button:after { border-color: rgba(79, 213, 119, 0); border-right-color: #4fd577; border-width: 7px; top: 50%; margin-top: -7px; }
Use this tool to create css arrows :- http://cssarrowplease.com/
Inside your form create a division containing a division with the word SEARCH and an img with a unique class.
Position your out division to absolute, top minus the height of your textbox.
Float your Search division to the right, float, your img to the left.
Asign your search division a width and height.
http://jsfiddle.net/5BwLC/22/
HTML
<div class="searchy">
<div class="searc">
<input type="search" name="ttsearch" data-style="mini" data-theme="d" placeholder="Search here..." class="fdSearch" value=""/>
<div class="search-button" onclick="f()">
Search
</div>
</div>
</div>
CSS
.searchy{
min-height: 60px;
background-color: #555;
color: #FFF;
margin-left: -15px;
margin-right: -15px;
overflow:hidden;
}
.fdSearch{
float:left;
background-color: white;
border-radius: 10px;
border: 5px solid #E5E4E2;
margin: 2px;
margin-left: -15px;
margin-right: -15px;
min-height: 40px;
vertical-align: middle;
padding: 20px;
margin-top: 15px;
width: 85%;
}
.searc
{
width:85%;
overflow:hidden;
}
.search-button
{
margin-top:15px;
margin-left:-40px;
min-height:40px;
width:10%;
background-color:purple;
float:left;
padding:20px;
vertical-align: middle;
border-radius: 10px;
border: 5px solid #E5E4E2;
}
Would you like the arrow too?
demo: http://jsfiddle.net/gxXYC/
.searchy{
position:relative;
height: 60px;
width:480px;
background-color: #555;
color: #FFF;
}
.searchy:before, .searchy:after{
position:absolute;
top:0;
}
.searchy:before{
content:"";
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right:10px solid blue;
right:100px;
top:20px;
}
.searchy:after{
content: "search";
color:white;
text-align:center;
width: 96px;
height: 84%;
top: 5px;
font-size: 23px;
line-height: 44px;
background: blue;
right: 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.fdSearch{
background-color: white;
border-radius: 10px;
border: 5px solid #E5E4E2;
height: 100%;
vertical-align: middle;
padding: 20px;
width: 100%;
float:left;
}
the markup
<div class="searchy">
<input type="search" name="ttsearch" data-style="mini" data-theme="d" placeholder="Search here..." class="fdSearch" value=""/>
</div>
if you want to use a submit button the git it an absolute position right width the same dimenssion as :after and an opacity :0;
http://jsfiddle.net/gxXYC/2/
Not sure why I'm adding my answer to the heaps, but here it is:
HTML:
<div class="searchy">
<div class="search-wrap">
<input type="search" name="ttsearch" data-style="mini" data-theme="d" placeholder="Search here..." class="fdSearch" value="" />
<button type="submit">Search</button>
</div>
</div>
CSS:
.searchy {
height: 60px;
background-color: #555;
color: #FFF;
position: relative;
padding: 0 6%;
}
.searchy:after {
content:'';
height: 100%;
display: inline-block;
vertical-align: middle;
}
.search-wrap {
background-color: white;
border-radius: 10px;
border: 5px solid #E5E4E2;
margin: 2px;
height: 40px;
vertical-align: middle;
width: 85%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
overflow: hidden;
position: relative;
display: inline-block;
}
.search-wrap > input, .search-wrap > button {
margin: 0;
height: 100%;
border: 0;
}
.search-wrap input[type="search"] {
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
width: 100%;
}
/* Unfortunately these have to be separate: http://css-tricks.com/snippets/css/style-placeholder-text/ */
.search-wrap input[type="search"]::-webkit-input-placeholder {
font-style: italic;
}
.search-wrap input[type="search"]:-moz-placeholder {
/* Firefox 18- */
font-style: italic;
}
.search-wrap input[type="search"]::-moz-placeholder {
/* Firefox 19+ */
font-style: italic;
}
.search-wrap input[type="search"]:-ms-input-placeholder {
font-style: italic;
}
.search-wrap button[type="submit"] {
position: absolute;
top: 0;
bottom: 0;
right: 0;
background: #7c7aa9;
color: #fff;
text-transform: uppercase;
padding: 0 10px;
}
.search-wrap button[type="submit"]:before {
position: absolute;
content:'';
border: 6px solid transparent;
border-right-color: #7c7aa9;
height: 0;
top: 0;
bottom: 0;
margin: auto 0;
left: -10px;
}
There's no one 'right' answer to this. Here's how I would do it:
Make the purple box/arrow a background image of the input.
Put the search text/button in an absolutely positioned DIV positioned above the right side of the input box.

Whitespace around Image

Can't figure out how I"m getting this extra white space around my image:
The markup:
<div id="member-name" hidden="true">
<button type="submit" id="btnExpandSection"><img src="~/Content/Images/plus.jpg" /></button><p id="member-fullName"></p>
</div>
the styles:
input, textarea
{
border: 1px solid #e2e2e2;
background: #fff;
color: #333;
font-size: .9em;
margin: 5px 0 6px 0;
padding: 5px 2px 5px 5px;
width: 300px;
}
img
{
display: block; /* gets rid off any unexpected margins round the image */
border: 0px;
}
input[type="submit"], input[type="button"], button
{
background-color: #ffffff;
cursor: pointer;
font-size: 11px;
font-weight: 600;
width: auto;
vertical-align: middle;
border: 0px;
}
td input[type="submit"], td input[type="button"], td button { font-size: 1em; }
UPDATE:
There's also this style in there:
#member-name
{
margin: 30px 0px 0px 0px;
height: 30px;
font-weight: bold;
color: white;
padding: 1px 1px 0px 1px;
background-color: #d28105;
border: 1px solid darkgray;
}
#member-fullName { margin: 0px 0px 0px 20px;}
#member-fullName p{ display: inline;float: left;overflow: hidden;}
Can't you just provide the image as a background to the button element?
#btnExpandSection {
background: #ffffff url('/Content/Images/plus.jpg') no-repeat center center;
height: /* image height */;
width: /* image width */;
}
I would start with this, and build it back from here...
button,
#member-fullName,
#member-name,
#btnExpandSection,
#btnExpandSection img {
margin: 0;
padding: 0;
}
But the following would definitely be preferably to an image nested between <button></button> tags. Replace 32px with actual width and height values of your image.
button {
background-image: url(~/Content/Images/plus.jpg);
width: 32px;
height: 32px;
}

White space around image issue [duplicate]

Can't figure out how I"m getting this extra white space around my image:
The markup:
<div id="member-name" hidden="true">
<button type="submit" id="btnExpandSection"><img src="~/Content/Images/plus.jpg" /></button><p id="member-fullName"></p>
</div>
the styles:
input, textarea
{
border: 1px solid #e2e2e2;
background: #fff;
color: #333;
font-size: .9em;
margin: 5px 0 6px 0;
padding: 5px 2px 5px 5px;
width: 300px;
}
img
{
display: block; /* gets rid off any unexpected margins round the image */
border: 0px;
}
input[type="submit"], input[type="button"], button
{
background-color: #ffffff;
cursor: pointer;
font-size: 11px;
font-weight: 600;
width: auto;
vertical-align: middle;
border: 0px;
}
td input[type="submit"], td input[type="button"], td button { font-size: 1em; }
UPDATE:
There's also this style in there:
#member-name
{
margin: 30px 0px 0px 0px;
height: 30px;
font-weight: bold;
color: white;
padding: 1px 1px 0px 1px;
background-color: #d28105;
border: 1px solid darkgray;
}
#member-fullName { margin: 0px 0px 0px 20px;}
#member-fullName p{ display: inline;float: left;overflow: hidden;}
Can't you just provide the image as a background to the button element?
#btnExpandSection {
background: #ffffff url('/Content/Images/plus.jpg') no-repeat center center;
height: /* image height */;
width: /* image width */;
}
I would start with this, and build it back from here...
button,
#member-fullName,
#member-name,
#btnExpandSection,
#btnExpandSection img {
margin: 0;
padding: 0;
}
But the following would definitely be preferably to an image nested between <button></button> tags. Replace 32px with actual width and height values of your image.
button {
background-image: url(~/Content/Images/plus.jpg);
width: 32px;
height: 32px;
}

Resources