CSS - Styling Form Elements With Pure Css?
Is it possible to style form elements (specifically checkboxes) with pure CSS, and without JS?
I'm thinking of something similar to this (but without the JS): http://ryanfait.com/resources/custo...-radio-buttons/ Similar TutorialsI have this code that works fine in firefox and MSIE and the whole page validates with tidy (Green checkmark). I can't post a URL because its on a private server. The part that isn't quite right on safari is these: I have a table load of these that are part of a big form named commit. <td width="30" bgcolor ="#e7e7e7"><input type ='submit' class='button_notdone' value='2' onclick="javascript:mapbutt(document.commit,2)" /></td> This is the javascript code for mapbutt function mapbutt(myform,dex) { myform.action.value='map'; myform.qnum.value=dex; } The javascript does not return false so after clicking and setting the action and qnum values it is supposed to fall through to the form's serverside action, which it does. The problem is the styling of the submits. On every other browser they are whatever color I specify in the style I assign to them. Here is the style for button_notdone .button_notdone { font-family: monospace; font-weight: bold; width: 28px; height: 22px; color:#ffffff; background:#000000; } The background color in this case is supposed to be black and the text color is supposed to be white, and on safari it is black text on grey. I tried changing "input" to "button" which does indeed display the background color but unlike a submit it does not display the value. I need the text of the value to show in the text color over the button or submit or whatever it ends up being. How can I get these submits to look like what I want on safari. Thank you. What I want is a result that looks like this: 1. (+2) --2. (+2) ----3. (+2) ------4. (+2) -------4.1. (+1) --------4.2. (+1) Where "-" is 1px, So: all parents should be positioned +2px relative to the previous parent item. All childs should be positioned +1 relative to their parent. What would be very very cool is to implement math function (eg each parent item should be previous indent * 4). I guess that one can not create a kind of dynamic indent (as in to write it all in one 'simple' statement). I assume that I should indeed write the css for each item. Is their a way to add such a code (something like 'padding-left: (ul li) * 2; and so forth... Given the following list: Code: <ul id="navbar"> <li>1.<ul> <li>2.</li> <li>3.</li> <li>4.</li> <li>4.1.</li> <li>4.2.</li> </ul></li> </ul> How does one get that kind of result and is it possible in the first place? Is is possible to style each type of input elements individually without the use of classes? Currently I use classes to make the borders of buttons appear differently from that of text fields. Chrome and Firefox aren't styling any of the span elements I have-in IE they load fine. For example the css..I'll check back in this book I have and online to see if I can find the issue. I appreciate any help. For example heres a span I have. Code: .title {background-color:CCCCCC; font-family:Verdana; margin:0px; padding:0px; border:2px double blue; height:70px; width:200px; } the html.. Code: <div id="menu"> <span class="button"> <a href="www.google.com">home</a> </span> <span class="button"> <a href="www.google.com">home</a> </span> </div> <div id="content"> <div id="sidebar"> <p>sidebar to the right</p> <h2>text</h2> </div> <span class="title"> <h2>Title of something</h2> </span> <p>some text sdfdsdsfdsf</p> </div> It may be that the divs and spans are conflicting because of their properties or that they are not properly nested or named..? Here's my whole css document. Code: #container {margin-left:25%; margin-right:25%; } #header {text-align:center; background-color:grey; border:solid; border-width:2px; border-color:black; margin-bottom:20px; } #menu {background-color:white; border:solid; border-color:black; border-width:1px; font-family:Verdana; padding:8px; margin:0px; } .button {background-color:#FFFFCC; margin:3px; width:90px; border:solid; padding:2px; border-width:1px; border-color:black; text-decoration:none; color:grey; text-align:center; font-family:Verdana; font-size:small; } #content{background-color:white; font-family:Verdana; padding-left:20px; padding-top:0px; padding-bottom:0px; border:1px solid grey; margin-right:0px; margin-top:20px; height:900px; } .title {background-color:#CCCCCC; font-family:Verdana; border:2px double #000000; height:70px; width:200px; } #footer{align:center; background-color:grey;font-size:.60em;} #sidebar {float:right; width:150px; height:900px; background-color:white; border-left:1px double grey; margin-left:0px; padding:8px; } Hi guys, For a pure CSS site, is it depreciated to have a border="0" tag in <img elements? (My reasoning is that if one browser doesn't support CSS, it will show the user images with ugly borders... that's anyway the default behavior in IE and FF). Thank you I'm reading around, wondering how I get form fields to change style and the text that is inserted in the form fields to change style (font/size).. Is there an easy way to do this? for example http://member.classifieds.com/userjoin.php the entry boxes are smaller, and the text is smaller.. I looked at their code and I'm not quite sure how they achieved this. Im having trouble with styling a web form, im trying to manipulate the textarea width and have the following CSS code textarea { width: 400px; height: 250px; margin-top: 5px; margin-bottom: 5px; padding: 0; } The width is fine in Internet Explorer yet in Opera it seems to completely ignore the width attribute. The form itself is in a <div> which has no width attribute. Anyone got any ideas? I've seen some text inputs with pretty snazzy styling, such as borders with rounded corners. How is this done? im trying to get an effect like this one, where when a textfield or form area is selected, the div around changes bgcolor WooFoo I think i might be able to use the pseudo selectors but not sure if ie will take it. Anyways i would love some suggestions! Is it possible to differentiate between various types of input field, e.g. assign a width to text inputs but leave buttons to find their own width based on content. I know I can do this by assigning certain elements a class but I'd prefer not to have to do this. Thanks I have form located below the google map on this page - http://www.hometowntrans.com/map_hours.asp I want to style it such that it has a 3d look to it if you will, with a gray background and black text. Im trying to get an input field and form button to line up to the right of an <li> tagged menu and not sure of the approach i should take. I'd prefer not to use a table if possible, and the table im using now is a bit buggy anyway. this is a page with the menu as it shows right now.... http://www.seesawusa.com/products/ this is the page with the basic idea of what im trying to do http://www.seesawusa.com/pages/74/ Things i'v tried 1. put the form inside a LI tag.... This results in putting the search box below the list of menu items across all my test browsers. 2. put the UL and the FORM inside a table with 2 cells... in FF, i get the result i want... except the LI and INPUT field are not aligned to the right in IE6 & 7 I get it lined up the way i want it. But the table pushes the the height and width of the containing div to an unacceptable level I've seen this type of thing before and in my searching other sites i've only found complicated table based layouts that use it. Does anyone know an approach that would allow me to leave out tables, or at the very least only use one? Thanks for the glance. P.S. Interestingly enough, the page you are reading has a menu and text field configuration that im wanting to use, but it is very table oriented. I'm missing something here. I want to change the color of the default value for this text field, without changing the overall color of the input field. For example, the default value of 170 will be gray, but when a user overwrites the data with their own numerical value, it will be black. I know how to change the color of the input field when a user types in data, but is there a way to change the color of the value= ? <input type="text" name="trans1_1" size="6" value="170"/> Any ideas? Seems like a simple task, but can't figure it out. Thanks in advance for the time. Hi guys, sorry if its newbie question, don't work with CSS so long. I've just read a nice article about styling CSS forms (Fancy Form Design) and it looked really nice, so I tried to apply it immediately. However, some problems occured, things are never so easy I guess . First problems occurs with styling of group of form elements: they are dropped one line down (below its label, resp. legend) in IE 5.5/6.0 and also moved to the right (in IE 5.5-7.0) for some reason. Also, styling of fieldsets' legends works odd: first legend is styled differently than the others (one would guess that all of them will be styled in same way). Could you give me pls a little hint on these problems? Here's the test page with applied form styling: http://147.32.122.251/hsh2t/index.php. General CSS: http://147.32.122.251/hsh2t/forms.css IE (5.5-6.0) only CSS: http://147.32.122.251/hsh2t/forms-ie.css hello everyone, 'tis my frist post... Just had'a quick question I'm working on a page, and l'm trying to create a text input with a background image, that has NO border, so that it nests inside of a table cell with no excess fluff. However the input has a 1 pixel high "line" that spans across the top of the element, and a 1 pixel high "line" across the bottom as well. I can't seem to get rid of it, is it possible? here's the code, l was trying to get to work with this: Code: <HTML> <HEAD> <style> /*Left searchBar Cap*/ td.leftCap{ background-color: #c0c0c0; background-image: url('images/searchBar_1x1.gif'); background-position: 0px 0px; width: 28; height: 50; padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0; } /*right searchBar Cap*/ td.rightCap{ background-color: #c0c0c0; background-image: url('images/searchBar_1x3.gif'); background-position: 0px 0px; width: 34; height: 50; padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0; } /*searchBar Top bar*/ td.searchTop{ background-color: #c0c0c0; background-image: url('images/searchBar_1x2.gif'); background-repeat: repeat-x; background-position: 0px 0px; width: 425; height: 16; padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0; } /*searchBar Bottom*/ td.searchBottom{ background-color: #c0c0c0; background-image: url('images/searchBar_3x1.gif'); background-repeat: repeat-x; background-position: 0px 0px; padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0; width: 425; height: 15; } /*center of searchBar*/ td.searchCen{ background-color: limegreen; background-position: 0px 0px; width: 425; height: 19; padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0; } BODY { background-color: #c0c0c0; background-attachment: scroll; margin-top: 0; margin-bottom: 0; margin-right: 0; margin-left: 0; } /*input*/ .input { background-image: url('images/searchBar_2x1.gif'); color: #191919 border-width: 0px; padding: 0px; border-style: hidden; border: 0; border-top-width: 0px; border-bottom-width: 0px; font-family: Comic Sans MS (cursive); font-weight: extra-bold; font-size: 10pt; width: 425; height: 19; } </style> </HEAD> <BODY> <center> <form> <table cellpadding="0" cellspacing="0"> <tr><td> <table cellpadding="0" cellspacing="0"> <tr> <td class="leftCap"> </table> <td> <table bgcolor="#c0c0c0" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="searchTop"> <tr> <td class="searchCen"> <input type="text" size="40" class="input" value="search google ... "> <tr><td class="searchBottom"> </table> <td> <table cellpadding="0" cellspacing="0"> <tr> <td class="rightCap"> </table> <td> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td bgcolor="#c0c0c0" align="center"> <a onClick="javascript:searchGoogle();" href="#"> <img border="0" src="images/searchBar_1x4.gif" width="113" height="50"></a> </table></table> </form> <script> query = document.forms[0].elements[0].value; function searchGoogle(){ if(query){ url = "http://www.google.com/search?hl=en&lr=&q="+query+"&btnG=Search"; window.open(url); }} </script> </BODY> </HTML> Thanks for your help! Samantha G. Hello all. I'm trying to get the form layout to mimic a table like structure so that all the input elements line up. I have the following: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Search Home</title> <style type="text/css"> .csc-mailform-field label { width: 10em; } #mailformformtype_mail { margin-top: 1em; } </style> </head> <body> <form action="contact/contact-form/" id="mailform" enctype="multipart/form-data" method="post" onsubmit="return validateForm('mailform','First_Name,First%20Name,Last_Name,Last%20Name,Email,Email,Email_Message,Ema il%20Message','','','')"> <fieldset class="csc-mailform"> <div class="csc-mailform-field"> <label for="mailformFirst_Name">First Name</label> <input type="text" name="First_Name" id="mailformFirst_Name" size="14" value="" /> </div> <div class="csc-mailform-field"> <label for="mailformLast_Name">Last Name</label> <input type="text" name="Last_Name" id="mailformLast_Name" size="14" value="" /> </div> <div class="csc-mailform-field"> <label for="mailformSuffix">Suffix (e.g. Ph.D., M.D.)</label> <input type="text" name="Suffix" id="mailformSuffix" size="14" value="" /> </div> <div class="csc-mailform-field"> <label for="mailformEmail">Email</label> <input type="text" name="Email" id="mailformEmail" size="14" value="" /> </div> <div class="csc-mailform-field"> <label for="mailformPhone_Number">Phone Number</label> <input type="text" name="Phone_Number" id="mailformPhone_Number" size="14" value="" /> </div> <div class="csc-mailform-field"> <label for="mailformCompany">Company/Institution</label> <input type="text" name="Company" id="mailformCompany" size="14" value="" /> </div> <div class="csc-mailform-field"> <label for="mailformEmail_Message">Email Message</label> <textarea name="Email_Message" id="mailformEmail_Message" cols="14" rows="5"></textarea> </div> <div class="csc-mailform-field"> <input type="submit" name="formtype_mail" id="mailformformtype_mail" value="Send Message" class="csc-mailform-submit" /> </div> </fieldset> </form> </body> </html> I thought that by setting the width of the labels, it would force the inputs to all line up but apparently this does nothing. Also I did not place the size attributes on the input, this is a form generated by a CMS. Hi, If I place an input field or select box in a div and set the display to none - will that variable still be sent when the form is submitted? Thanks, Anyone able to guide me to find where to edit form elements? I want to change the 'check box' and 'drop down menu's' Suppose I have: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> //********************************************************** // This function adds another field to the form based on // what field name is passed in. //********************************************************** function add_item(field) { if(!document.getElementById) return; //Prevent older browsers from getting any further. var field_area = document.getElementById(field + '_field'); var all_inputs = field_area.getElementsByTagName("input"); //Get all the input fields in the given area. // Find the count of the last element of the list. It will be in the format '<field><number>'. If the // field given in the argument is 'friend_' the last id will be 'friend_4'. var last_item = all_inputs.length - 1; var last = all_inputs[last_item].id; var count = Number(last.split("_")[1]) + 1; if(document.createElement) { //W3C Dom method. var li = document.createElement("li"); var input = document.createElement("input"); input.id = field+count; input.name = field+count; input.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc. li.appendChild(input); field_area.appendChild(li); } // end if(document.createElement) else { //Older Method field_area.innerHTML += "<li><input name='"+(field+count)+"' id='"+(field+count)+"' type='text' /></li>"; } // end else } // end function add_item(field) //********************************************************** </script> </head> <body> <form> <table> <tr> <td><label for="images">Images (for banner and sidebar)</label></td> <td> <ul id="images_field"> <li><input type="text" id="images_0" name="images_0" /></li> </ul> </td> <td><input type="button" id="button" value="Add another image" onclick="add_item('images');" /></td> </tr> <tr> <td colspan="3"> <label for="misc">Misc. (anything that falls outside of the above categories)</label><br /> <textarea rows="3" cols="3" id="misc" name="misc"></textarea> </td> </tr> <tr> <td colspan="3"><input type="submit" id="submit" value="Submit project" /></td> </tr> </table> </form> </body> </html> When I click the add another image button, it will create a new form field for another image. But it keeps stacking them on top of the elements below it. I would like for everything below it to be shifted down when a new element is inserted. I tried the clearfix method but couldn't get it to work. Thoughts? Edited to say that this behavior only appears in FireFox. I'm new to CSS. But I need to position four form elements in a very thin nav bar. Here is my HTML code: Code: <div id="nav"> <div id="nav_left"> <a href="index.php">Home</a> |<a href="complete.php"> Browse All Titles</a> | <a href="author.php">About Author</a></div> <div id="bookmark"><table width="307" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="64" valign="middle">Browse by</td> <td width="113" valign="middle"><form action="" method="get"> Title <select name="var" size="1"> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="E">E</option> <option value="F">F</option> <option value="G">G</option> <option value="H">H</option> <option value="I">I</option> <option value="J">J</option> <option value="K">K</option> <option value="L">L</option> <option value="M">M</option> <option value="N">N</option> <option value="O">O</option> <option value="P">P</option> <option value="Q">Q</option> <option value="R">R</option> <option value="S">S</option> <option value="T">T</option> <option value="U">U</option> <option value="V">V</option> <option value="W">W</option> <option value="X">X</option> <option value="Y">Y</option> <option value="Z">Z</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="0">0</option> </select><input type="image" class="inputbutton" src="img/input.jpg" alt="" width="15" height="15"> </form></td><td width="123" valign="middle"><form action="" method="get">Decade <select name="var" size="1"> <option value="1950">1950s</option> <option value="1960">1960s</option> <option value="1970">1970s</option> <option value="1980">1980s</option> <option value="1990">1990s</option> <option value="2000">2000s</option> </select><input type="image" class="inputbutton" src="img/input.jpg" alt="" width="15" height="15"> </form></td> </tr> </table> </div> </div> And here are the applicable styles: Code: #nav { background-image: url(../img/navback.jpg); background-repeat: no-repeat; background-position: left top; border: thin solid #7a8251; height: 25px; width: 771px; } #nav_left { width: 400px; float: left; text-align: left; padding-top: 5px; padding-right: 5px; padding-bottom: 7px; padding-left: 5px; } #bookmark { width: 300px; float: right; text-align: right; display: inline; padding-top: 5px; padding-right: 3px; padding-bottom: 5px; } .inputbutton { margin-right: 3px; margin-left: 3px; } select { display: inline-table; font-size: 75%; padding: 0px; } But, the form elements are sitting low and not aligning as needed. The input buttons are sitting too high. They sit lot in Firefox on a Mac. On IE 7, the dropdowns sit even lower. I don't know what to do! Any ideas? Jeremy |