I have defined Css class
form input[type="text"], form input[type="email"], form input[type="password"], form select, form textarea {
background: url("../images/input-bg.gif") repeat-x scroll 0 0 #FFFFFF;
border: 1px solid #CCCCCC;
padding: 4px 5px;
}
now when i use Input in html css affects to all input on the form
because i have used [form] in the css.
but i do not want to affect css to some input texboxes..
how can i achive this ?
I'd do it the other way, just add other classes to inputs you don't want to be affected by that rule. Something like this.
Edited adding comment suggestion
/* General rule for inputs */
form input[type="text"], form input[type="email"], form input[type="password"], form select, form textarea {
background: url("../images/input-bg.gif") repeat-x scroll 0 0 #FFFFFF;
border: 1px solid #CCCCCC;
padding: 4px 5px;
}
/* Specific rule for inputs */
form input[type="text"].reset-inputs, form input[type="email"].reset-inputs, form input[type="password"].reset-inputs, form textarea.reset-inputs, form select.reset-inputs {
background: none;
border: none;
padding: 0;
}
you can add a class for the input boxes you dont want an effect and override the other one:
<input class="noeffect"/>
form input.noeffect {
background: none;
}
Add a class to the input felds you like to affect:
html: <input class="here" ... />
css: form input.here[type="text"]
Or create a div region with your input's in it:
<div class="here">
<input /><input /><input />
</div>
css: form .here input[type="text"]
There are several properties like :nth-child() :last-child, :first-child etc:
Like this:
form input[type="text"] + form input[type="text"] {
background:none;
}
or
form input[type="text"]:nth-child(2n){
background:none;
}
or
give a class to it
form input.diff{
background:none;
}
Related
I have a search input field and a submit button direct beside the input field. They have the same padding, but Firefox adds 1px to the button padding, but not to the input padding. Line-height makes it worse. Has anyone a solution for this?
.form,
button {
padding: 5px;
font-size: 12px;
border: 1px solid black;
box-sizing: border-box;
}
<input type="text" class="form" placeholder="Text" /><button class="button">Click</button>
http://jsfiddle.net/r5y7byag/4/
This will fix it
button::-moz-focus-inner {
padding: 0;
border: 0
}
Including the border rule above is necessary for buttons to look the same in both browsers.
It also removes the dotted outline when the button is active in Firefox.
To fix it on the input elements aswell add:
input[type="reset"]::-moz-focus-inner, input[type="button"]::-moz-focus-inner, input[type="submit"]::-moz-focus-inner, input[type="file"] > input[type="button"]::-moz-focus-inner
See this fiddle
CSS:
.form,
button {
font-size: 12px;
border: 1px solid black;
box-sizing: border-box;
line-height:30px;
padding-left:5px;
}
I want to align the checkbox, label and text input in a same line using css. I can do it by using the default template of the browser.
However I really liked the simple theme given in this link. The theme has label and a input text. I wanted to add a checkbox as well at the beginning of the line. Somehow adding a checkbox inside the div makes the arrangement awry.
Though its better to look at the code in the link, I am providing a snapshot here:
HTML
<form>
<div>
<!--NEED TO ADD CHECKBOX HERE -->
<label for="pub_url">Public URL</label>
<input type="text" id="pub_url" name="pub_url" value="http://cssdeck.com">
</div>
</form>
CSS3
/* Onto the styling now. Some quick generic styles first. */
html, body {
width: 100%; height: 100%;
}
body {
font-size: 76%;
font-family: Verdana;
background: #eee;
padding: 50px 0;
}
form {
background: #fafafa;
padding: 20px;
width: 400px;
margin: 0 auto;
border: 1px solid #ffe2e3;
}
form div {
/* Float containment */
overflow: hidden;
}
/* Things are looking good now, onto the main input field
styling now! */
/*
Lets change the box model to make the label and input
contain into the 100% div.
You might want to specify the box sizing properties inside
`* {}` at the top.
Things are looking great now! Lets just spice it up a bit.
*/
form label, form input {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form label {
font-weight: bold;
background: linear-gradient(#f1f1f1, #e2e2e2);
padding: 5px 10px;
color: #444;
border: 1px solid #d4d4d4;
/* lets remove the right border */
border-right: 0;
border-bottom-left-radius: 5px;
border-top-left-radius: 5px;
line-height: 1.5em;
width: 30%;
/* takes the width properly now and also the
spacing between the label and input field got removed. */
float: left;
text-align: center;
cursor: pointer;
}
/* The label is looking good now. Onto the input field! */
/*
Everything is broken now! But we can fix it. Lets see how.
*/
form input {
width: 70%;
padding: 5px;
border: 1px solid #d4d4d4;
border-bottom-right-radius: 5px;
border-top-right-radius: 4px;
line-height: 1.5em;
float: right;
/* some box shadow sauce :D */
box-shadow: inset 0px 2px 2px #ececec;
}
form input:focus {
/* No outline on focus */
outline: 0;
/* a darker border ? */
border: 1px solid #bbb;
}
/* Super! */
p.s: It will be delightful if someone can stylize the checkbox in the same way as the example
try this one,
form input[type="checkbox"] {
width:20px;
}
<div>
<input type="checkbox" >
<label for="pub_url">Public URL</label>
<input type="text" id="pub_url" name="pub_url" value="http://cssdeck.com">
</div>
http://jsfiddle.net/KW6AY/1/
Here you go \w quick styling:
http://codepen.io/daniesy/pen/puema
alter the css to input[type="text"] and lower the width to around 60% (so it won't affect your checkbox), add a checkbox with a float left
just rename class
form input into form input[type="text"]
Good luck.
I don't like the default button style. It's really boring. I am using
<input type="submit">
type buttons. Can I style these somehow in css? If not, the other way of doing it i guess would be to use a div instead, and make it a link. How do you make those work with forms?
You can achieve your desired through easily by CSS :-
HTML
<input type="submit" name="submit" value="Submit Application" id="submit" />
CSS
#submit {
background-color: #ccc;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius:6px;
color: #fff;
font-family: 'Oswald';
font-size: 20px;
text-decoration: none;
cursor: pointer;
border:none;
}
#submit:hover {
border: none;
background:red;
box-shadow: 0px 0px 1px #777;
}
DEMO
Yeah, it's pretty simple:
input[type="submit"]{
background: #fff;
border: 1px solid #000;
text-shadow: 1px 1px 1px #000;
}
I recommend giving it an ID or a class so that you can target it more easily.
Yes you can target those specificaly using input[type=submit] e.g.
.myFormClass input[type=submit] {
margin: 10px;
color: white;
background-color: blue;
}
You can directly create your own style in this way:
input[type=button]
{
//Change the style as you like
}
You might want to add:
-webkit-appearance: none;
if you need it looking consistent on Mobile Safari...
write the below style into same html file head section or write into a .css file
<style type="text/css">
.submit input
{
color: #000;
background: #ffa20f;
border: 2px outset #d7b9c9
}
</style>
<input type="submit" class="submit"/>
.submit - in css . means class , so i created submit class with set of attributesand applied that class to the submit tag, using class attribute
input:required{
background-color:#f00;
}
input:required label{
color: #FF3434;
}
I have the above CSS code currently for my form,
I want to be able to make the label red when the field is required. My input field is:
<label for="frmComTelephone">Telephone</label>
<input type="number" name="Telephone" id="frmComTelephone"/>
<label for="frmIn1IncinTime">Time</label>
<input type="text" name="Incident Time" id="frmIn1IncinTime" required="required"/><br>
But that CSS isn't working how do I solve this?
2ND problem is I have the following CSS:
input:focus
{
background-color:yellow;
}
input[type="text"], input[type="date"],input[type="time"],input[type="number"],textarea,select
{
border-radius:5px;
border-width: 1px;
border-style: solid;
border-color: #C6C6C6;
height:41px;
background-color: #FF3434;
width: 100%;
}
But when the item is focused it doesn't change to yellow, if i remove "background-color: #FF3434;" it turns yellow on focus?
Is what I am doing not able to be done? Or am I going about this wrong?
Thanks
Issue 1:
input:required label{
color: #FF3434;
}
This won't work because the label is not a child of the input. They're siblings. To solve that you have to create a class and attach it to your label:
label.required { color: #FF3434; }
<label for="frmComTelephone" class="required">Telephone</label>
Issue 2:
Try this:
input:focus,
textarea:focus,
select:focus
{ background-color: yellow !important; }
...
UPDATE
If you're more comfortable without using !important then try this:
input[type="text"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus
{ background-color: yellow }
OR
if you have an id on your form this will also work
#formID input:focus,
#formID textarea:focus,
#formID select:focus
{ background-color: yellow }
You need to put the input:focus rule behind the input[type="number"] rule or use input[type="number"]:focus.
Otherwise its overwritten by input[type="number"] as it's more specific.
Problem 2:
CSS selectors by attribute, like input[type="number"] and pseudo-elements like :focus have equal specifity. This means that your input:focus rule gets overridden by the following input[type="number"] background.
There are two ways to fix this:
Higher specifity in the first selector:
form input:focus
{
background-color:yellow;
}
input[type="text"]
{
background-color: #FF3434;
}
Better: Correct rule order, more important one comes second
input[type="text"]
{
background-color: #FF3434;
}
form input:focus
{
background-color:yellow;
}
CSS specifity seems hard, but it's worth understanding it properly. There are a lot of resources about it, try this introduction: http://coding.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
How can I create a borderless HTML textbox to work in Google Chrome browser? I would prefer to do this in CSS, if possible.
CSS 3 might help here:
input[type=text],
input[type=text]:hover,
input[type=text]:focus,
input[type=text]:active
{
border: 0;
outline: none;
outline-offset: 0;
}
You can use the following to remove the border and the focus outline out of the text boxes.
input[type=text], textarea {
border: 0;
}
input[type=text]:focus, textarea:focus {
outline: none;
}
in css, write
input, textarea, input:focus, textarea:focus {
background:transparent;
border:0;
}
it is important to make sure no border appears on focus
A textarea? Like:
HTML: <textarea></textarea>
CSS: textarea { border: none 0; }