matt
matt

Reputation: 77

Shortening html IDs to use in CSS

Is there any way to shorten a HTML element tag like this:

<input id=ctl00_ctl32_g_9bd32d9e_a30e_48f8_af0e_4c4b7e8ba1f5_createSuggestion>

In CSS so that I don't have to reference the entire thing and just use the createSuggestion part of it like this:

input createSuggestion{
margin-left:10%;
}

For instance, when producing a SQL query, sometimes a 'like %createSuggestion' would be used. Any ideas?

Upvotes: 2

Views: 129

Answers (2)

SLaks
SLaks

Reputation: 887275

Add ClientIdMode="Static" in your server-side control to prevent that entirely.

Upvotes: 2

Hashem Qolami
Hashem Qolami

Reputation: 99464

You could achieve that by attribute selector as follows:

input[id$="createSuggestion"] {
    margin-left: 10%;
}

6.3.2. Substring matching attribute selectors

[att$=val] Represents an element with the att attribute whose value ends with the suffix "val". If "val" is the empty string then the selector does not represent anything.

Upvotes: 7

Related Questions