I am going crazy trying to figure out how to make this work. I would like the legend to be outside of the border. How can I make this happen while keeping the legend tag? As you can see below I tried using span but it is not working.
body {
background-color: #996600;
color: black;
}
fieldset {
border: 10px solid #ffffff;
border-radius: 10px;
background-color: #999900;
box-shadow: 10px 10px 5px #888888;
position: relative;
}
legend {
font-size: 20px;
float: left;
}
legend span {
top: 0px;
left: 0px;
position: absolute;
}
input[type=text] {
border: 2px solid black;
border-radius: 10px;
background-color: #cccc80;
}
input[type=button] {
background-color: #996600;
border: 2px solid black;
border-radius: 5px;
color: #c9ae78;
font-weight: bolder;
}
p {
font-size: 12px;
font-style: italic;
}
<form method="post" id="contactForm" action="#">
<fieldset>
<legend><span>Newsletter Signup</span>
</legend>
<p>To sign up for our fabulous campaign of useless information that you will never, ever read, please submit your email address here.</p>
<label for="email" id="emailLabel">Email</label>
<input type="text" id="email" />
<input type="button" name="submit" value="Submit" id="submitButton" />
</fieldset>
</form>
Use position: absolute for your legend, and add a margin-top on your fiedset to compensate this shift:
body {
background-color: #996600;
color: black;
}
fieldset {
border: 10px solid #ffffff;
border-radius: 10px;
background-color: #999900;
box-shadow: 10px 10px 5px #888888;
position: relative;
margin-top: 35px;
}
fieldset legend {
position: absolute;
top: -35px;
left: 10px;
font-size: 20px;
}
input[type=text] {
border: 2px solid black;
border-radius: 10px;
background-color: #cccc80;
}
input[type=button] {
background-color: #996600;
border: 2px solid black;
border-radius: 5px;
color: #c9ae78;
font-weight: bolder;
}
p {
font-size: 12px;
font-style: italic;
}
<form method="post" id="contactForm" action="#">
<fieldset>
<legend>Newsletter Signup</legend>
<p>To sign up for our fabulous campaign of useless information that you will never, ever read, please submit your email address here.</p>
<label for="email" id="emailLabel">Email</label>
<input type="text" id="email" />
<input type="button" name="submit" value="Submit" id="submitButton" />
</fieldset>
</form>
Add the following to your legend:
legend {
position: absolute;
top: -1em;
width: 100%;
}
Hope this helps
You could use absolute positioning.
HTML:
<form method="post" id="contactForm" action="#">
<fieldset>
<legend>Newsletter Signup</legend>
<p>To sign up for our fabulous campaign of useless information that you will never, ever read, please submit your email address here.</p>
<label for="email" id="emailLabel">Email</label>
<input type="text" id="email" />
<input type="button" name="submit" value="Submit" id="submitButton" />
</fieldset>
</form>
CSS:
body {
background-color: #996600;
color: black;
}
form { margin-top:30px; }
fieldset {
border: 10px solid #ffffff;
border-radius: 10px;
background-color: #999900;
box-shadow: 10px 10px 5px #888888;
position: absolute;
}
legend {
font-size: 20px;
text-align: left;
position:absolute;
top:-38px;
}
input[type=text] {
border: 2px solid black;
border-radius: 10px;
background-color: #cccc80;
}
input[type=button] {
background-color: #996600;
border: 2px solid black;
border-radius: 5px;
color: #c9ae78;
font-weight: bolder;
}
p {
font-size: 12px;
font-style: italic;
}
JSFiddle
Related
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>
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>
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>
How I can delete empty space between search input box and the go button? I've prepared jsfiddle with code sample. Link - jsFiddle
Screenshot:
HTML:
<div class="blablabla">
<form id="search_mini" action="#" method="get">
<div class="form-search">
<!--<label for="search"></label>-->
<input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off">
<button type="submit" title="GO" class="button"><span><span>GO</span></span>
</button>
<div id="search_autocomplete" class="search-autocomplete" style="display: none;"></div>
</div>
</form>
CSS:
#search_mini {
width: 268px;
}
.form-search input {
border-color: #7d7c7c;
height: 30px;
width: 150px;
padding:0;
}
.form-search button.button {
background: url(../images/bg.gif) 0 0 repeat-x;
font-size: 12px;
text-align: center;
padding: 0;
height: 36px;
min-width: 84px;
}
Thank you in advance.
You may try margin-left:
#search_mini {
width: 268px;
}
.form-search input {
border-color: #7d7c7c;
height: 30px;
width: 150px;
padding: 0;
}
.form-search button.button {
background: url(../images/bg.gif) 0 0 repeat-x;
font-size: 12px;
text-align: center;
padding: 0;
height: 36px;
min-width: 84px;
margin-left: -4px;/* put as your need */
}
<div class="blablabla">
<form id="search_mini" action="#" method="get">
<div class="form-search">
<!--<label for="search"></label>-->
<input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off">
<button type="submit" title="GO" class="button"><span><span>GO</span></span>
</button>
<div id="search_autocomplete" class="search-autocomplete" style="display: none;"></div>
</div>
</form>
add float:left to you .form-search input element
example: http://jsfiddle.net/2nwp36nj/2/
#search_mini {
width: 268px;
}
.form-search input {
border-color: #7d7c7c;
height: 30px;
width: 150px;
padding:0;
float: left;
}
.form-search button.button {
background: url(../images/bg.gif) 0 0 repeat-x;
font-size: 12px;
text-align: center;
padding: 0;
height: 36px;
min-width: 84px;
}
<div class="blablabla">
<form id="search_mini" action="#" method="get" _lpchecked="1">
<div class="form-search">
<!--<label for="search"></label>-->
<input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off">
<button type="submit" title="GO" class="button"><span><span>GO</span></span>
</button>
<div id="search_autocomplete" class="search-autocomplete" style="display: none;"></div>
</div>
</form>
</div>
use float left for both of the elements input and button also you need to give a width for button as well. It looks like it is working in the below code.
http://jsfiddle.net/2nwp36nj/3/
#search_mini {
width: 368px;
}
.form-search input, .form-search button {
border-color: #7d7c7c;
height: 30px;
width: 150px;
padding:0;
float: left;
}
.form-search button.button {
background: url(../images/bg.gif) 0 0 repeat-x;
font-size: 12px;
text-align: center;
padding: 0;
height: 36px;
min-width: 84px;
}
are suggested just such a button then she together with the form DEMO
<form class="form-wrapper cf">
<input type="text" placeholder="search" required>
<button type="submit">GO</button>
</form>
.cf:before, .cf:after{
content:"";
display:table;
}
.cf:after{
clear:both;
}
.cf{
zoom:1;
}
.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-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-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 {
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 {
border: 0;
padding: 0;
}
Simply add this to your elements :
.form-search input,
.form-search button.button
{
display: block;
float: left;
}
Your space is actually due to a whitespace.
Another working solution: you must insert comment between input tag and button tag. Like this:
<input id="search" value="SEARCH" type="text" name="q" class="input-text" maxlength="128" autocomplete="off"><!--
--><button type="submit" title="GO" class="button"><span><span>GO</span></span>
Im not having sucess put my icon font inside my search input.
I already try with margin, padding, but nothing is working!
Can you give me a little help?
The fiddle with the problem:
http://jsfiddle.net/Tj7nJ/1/
My Html:
<li id="sb-search" style="float:right; list-style:none; height:20px; bottom:3px; ">
<form id="search">
<input name="q" type="text" size="40" placeholder="Pesquisar..." />
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</li>
My css:
#search {
outline:none ;
border:none ;
}
#search button[type="submit"] {
width: 20px;
background:none;
cursor:pointer;
height:20px;
}
button[type="submit"]>i:hover
{
color: #fff;
}
button[type="submit"]>i
{
background:none;
color:#ccc;
font-size:1.1em;
}
#search input[type="text"]
{
border: 0 none;
background: #141d22;
text-indent: 0;
width:110px;
padding: 6px 15px 6px 35px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
You can't put an image inside an <input type='text'> element.
However, you can remove the borders of the input with:
input[type='text'] {
background-color:transparent;
border: 0px solid;
}
and then wrap it with the icon inside a div and re-style.
Example code:
Here is a jsFiddle for you: http://jsfiddle.net/hxjY7/
Here is the code:
<style type="text/css">
#textBoxWrapper{
border: 1px solid black;
width: 172px;
height: 20px;
}
#textBox {
background-color:transparent;
border: 0px solid;
width: 150px;
height: 20px;
float:left;
}
#icon{
width: 20px;
height: 20px;
background-color: grey;
float:left;
}
</style>
<div id="textBoxWrapper">
<div id="icon"></div>
<input type="text" id="textBox" />
</div>
If you are trying to move the button inside the input field, you could set the button to position absolute (and the search wrapper to relative):
http://jsfiddle.net/Tj7nJ/3/
#search {
outline: none;
border: none;
}
#search {
position: relative;
z-index: 1;
}
#search button[type="submit"] {
width: 20px;
background: none;
cursor: pointer;
height: 20px;
z-index: 2;
position: absolute;
top: 3px;
right: 10px;
}
button[type="submit"]>i:hover {
color: #fff;
}
button[type="submit"]>i {
background: none;
color: #ccc;
font-size: 1.1em;
}
#search input[type="text"] {
border: 0 none;
background: #141d22;
text-indent: 0;
width: 110px;
padding: 6px 15px 6px 35px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
I think this is what you are trying to do. jsFilddle
HTML:
<form id="search" action="#" method="post">
<fieldset>
<input type="text" id="q" name="q" size="40" placeholder="Search..." />
<button type="submit"><i class="fa fa-search"></i>
</button>
</fieldset>
</form>
CSS:
form#search fieldset {
position: relative;
border: none;
}
form#search input[type='text'] {
padding: 4px;
}
form#search button {
position: absolute;
top: 9px;
left: 262px;
}