How to apply CSS to a textbox?
19,982
Solution 1
You can give it a CSS class, like this:
<asp:TextBox ID="txtPais" runat="server" CssClass="textbox" />
Then just use add what you need in your CSS:
.textbox { color: red; }
The CssClass
property doesn't get mangled like the ID and name attributes.
Solution 2
Why wouldn't you do this either:
input[type=text] { /* style */ } (standard)
or
input.text { /* style */ } (not as standard)
???
Solution 3
you can use jQuery and do it like this:
$('input[id$=_txt]').addClass('yourClassName maybeAnotherClassName');
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I have this code, and it renders this HTML. How can I apply CSS to my control if they are named ctrctrctr-00000 or something else like that that is only useful to the VIEWSTATE?
<!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><title> </title><link href="../global.css" rel="stylesheet" type="text/css" /> Informacion General: Paises </head> <body> <form name="aspnetForm" method="post" action="Pais.aspx" id="aspnetForm"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUyMDk1NTY2MGRkwAKu2OIV85kXfcUcAefBBNmSuRY=" /> </div> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLSha7NBAKqw7ARAvjQlaIKhJ2HMftmmOoxe/+aE4sG3D32QtA=" /> </div> <div> <input name="ctl00$ContentPlaceHolder1$txtPais" type="text" id="ctl00_ContentPlaceHolder1_txtPais" /> <input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="Button" id="ctl00_ContentPlaceHolder1_btnSubmit" /> </div> </form> </body> </html> <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Frontend._Default" %> <!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 runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h1>Prueba de Escritorio</h1> <asp:TextBox ID="txtPais" runat="server"></asp:TextBox> <asp:Button ID="btnSubmit" runat="server" Text="Guardar" onclick="btnSubmit_Click" /> </div> </form> </body> </html>
How can I use a CSS selector to target ALL textboxes on the page regardless of name?
Thank you.