Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8874937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:50:56+00:00 2026-06-14T18:50:56+00:00

I have some HTML code I need to style that is being automatically generated

  • 0

I have some HTML code I need to style that is being automatically generated by a web service. Part of the code I’m given looks something like this:

<input type='text' id='txtField001' class='txtField150'>foo</input>    
<input type='text' id='txtField002' class='txtField10'>bar</input>
<input type='text' id='txtField001' class='txtField142'>sum</input>

Now, here comes the “weird” part: the numbers that follow the class name (i.e.: 150, 10 and 142) are, in fact, the max. number of characters the text field accepts, slo it gives me a “hint” as to how wide the text field should render: wide for 150, shorter for 10; since this number varies wildly (it’s user defined by whomever is calling the web service) it is not practical to have “n” classes to comply with all possible values.

So: is there a way to have a “ranged class” or something like that – keeping in mind that, theoretically, I cannot change whatever the web service is delivering, and that I don’t really want to evaluate things with javascript?

Concretely, is there any way to declare something like this (I know it’s somewhat wild):

.txtField1 ... .txtField50 {
    width: 50px;
}

.txtField50 ... .txtField100 {
    width: 80px;
}

.txtField100 ... .txtField150 {
    width: 120px;
}

(how I’m reading this in my mind: “for any class txtField ranging from 1 to 50, use a 50px width… and so on)

Thanks for any help. I know it’s a long shot, and that my best option is to use javascript, but hey, I had to ask 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:50:57+00:00Added an answer on June 14, 2026 at 6:50 pm

    Yes, with Limits

    I have been pondering a solution that is similar to cimmanon’s, only I knew it needed to be far more refined than that (which is why it has taken some time to answer).

    Let me state up front that this probably needs a practical limit (I don’t know if there is a limit on the number of characters that it can be in your situation). As you can see in my example fiddle, anything 300+ fails to resolve to larger sizes. If there is a high or unknown upper limit, then javascript is really going to be your best solution. My example works for less than 300, and perhaps up to 999 could be made with not too much more code. But 1000+ I think would be unreasonable.

    CSS

    /* set default as small size */
    [class ^= "txtField"] {
        width: 50px;
    }
    
    /* weed out 50-99, making sure not to get 5-9 */
    [class *= "d5"]:not([class $= "d5"]),
    [class *= "d6"]:not([class $= "d6"]),
    [class *= "d7"]:not([class $= "d7"]),
    [class *= "d8"]:not([class $= "d8"]),
    [class *= "d9"]:not([class $= "d9"])
    {
        width: 80px;
    }
    
    /* weed out 100-199, making sure not to get 1 or 10-19
       NOTE: this becomes a highly specific selector
    */
    [class *= "d1"]:not([class $= "d1"]):not([class $= "d10"]):not([class $= "d11"]):not([class $= "d12"]):not([class $= "d13"]):not([class $= "d14"]):not([class $= "d15"]):not([class $= "d16"]):not([class $= "d17"]):not([class $= "d18"]):not([class $= "d19"])
    {
        width: 120px;
    }
    
    /* weed out 150-199, making sure not to get 15-19
       NOTE: because the previous selector is so specific, this one
       needed the !important flag (which I hate to use, but here
       seemed to be the best and only solution)
    */
    [class *= "d15"]:not([class $= "d15"]),
    [class *= "d16"]:not([class $= "d16"]),
    [class *= "d17"]:not([class $= "d17"]),
    [class *= "d18"]:not([class $= "d18"]),
    [class *= "d19"]:not([class $= "d19"])
    {
        width: 150px !important;
    }
    
    /* weed out 200-299, making sure not to get 2 or 20-29
       NOTE: again high specificity
    */
    [class *= "d2"]:not([class $= "d2"]):not([class $= "d20"]):not([class $= "d21"]):not([class $= "d22"]):not([class $= "d23"]):not([class $= "d24"]):not([class $= "d25"]):not([class $= "d26"]):not([class $= "d27"]):not([class $= "d28"]):not([class $= "d29"])
    {
        width: 180px;
    }
    
    /* weed out 250-299, making sure not to get 25-29
       NOTE: !important needed again;
       also, anything 300+ reverts back to smallest size unless
       one keeps going... maybe 999 could be reached "reasonably"
    */
    [class *= "d25"]:not([class $= "d25"]),
    [class *= "d26"]:not([class $= "d26"]),
    [class *= "d27"]:not([class $= "d27"]),
    [class *= "d28"]:not([class $= "d28"]),
    [class *= "d29"]:not([class $= "d29"])
    {
        width: 210px !important;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML Code: <html> <head> <title>css test</title> <style type=text/css> .box{width:100%;float:left;background:red} </style> </head>
I have some auto-generated HTML code. When I add a float:left; on the shared
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have some PHP code that generates a calendar and then outputs html to
I have a jquery line of code that outputs some HTML to a div.
I'm reading some data that has already been converted to html style υ code.
I have some html code and I load it to WebView. I need to
I have inherited some HTML code and have been asked to align the two
I have some HTML errors in my output source code, coming from one of
I have a td-element which can contain some HTML code, e.g. &lt; . This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.