5

I want to hide this input element. In fact I have few of them and I have to use their names.

<input type="image" alt="Storage Administration" src="App_Themes/Default/topmenu$store$png$ffffff$000000.IconHandler.axd" title="Storage Administration" id="ctl00_ctl00_TopMenuCph_btnAdm" name="ctl00$ctl00$TopMenuCph$btnAdm">

Could someone suggest how to use full title or alt?

[title ~= "Storage"] { 
    display: none; 
} 

That works well but, this doesn't work in firefox and chrome.

[title ~= "Storage Administration"] { 
    display: none; 
}

If I cannot use the full title, then how can I narrow the selection if the input element in inside .topMenu > div > li?

<ul class="topMenu">
    <div id="ctl00_ctl00_TopMenuCph_panTab">
        <li><input type="image" alt="Storage Administration" src="App_Themes/Default/topmenu$store$png$ffffff$000000.IconHandler.axd" title="Storage Administration" id="ctl00_ctl00_TopMenuCph_btnAdm" name="ctl00$ctl00$TopMenuCph$btnAdm"></li>
        <li><input type="image" alt="Envelope Templates" src="App_Themes/Default/topmenu$envelope$png$ffffff$000000.IconHandler.axd" title="Envelope Templates" id="ctl00_ctl00_TopMenuCph_btnEnv" name="ctl00$ctl00$TopMenuCph$btnEnv"></li>
        <li><input type="image" alt="My Documents" src="App_Themes/Default/topmenu$mydocuments$png$ffffff$000000.IconHandler.axd" title="My Documents" id="ctl00_ctl00_TopMenuCph_btnMyD" name="ctl00$ctl00$TopMenuCph$btnMyD"></li>
    </div>
</ul>
Radek
  • 13,813
  • 52
  • 161
  • 255
  • I know it's different, but can you use `nth-of-type()`? – Stickers Jul 08 '15 at 02:17
  • no, I cannot. I need to hide all li with specific title. In some cases the whole ul gets replaced with different set of li and I need to leave them. In some cases I need to hide all li's – Radek Jul 08 '15 at 02:19
  • OK, by the way
    directly under
      is invalid html.
    – Stickers Jul 08 '15 at 02:20
  • :-) I am not the author of html. I am just fixing something ... – Radek Jul 08 '15 at 02:21
  • This comment is off-topic but, the only "legal" direct descendants of `
      ` elements are `
    • ` elements, `
      ` elements are not allowed as direct descendants of `
        ` elements.
    –  Jul 08 '15 at 02:25

1 Answers1

10

The attribute selector that you are using doesn't work the way you are expecting it to work. When you put [title~="Storage Administration"], CSS is looking for elements that have a title of either exactly "Storage" or exactly "Administration".CSS will not match anything.

Take a look at the attribute selector spec for a more thorough description:

http://www.w3.org/TR/CSS21/selector.html#attribute-selectors

If you want to look, specifically, for elements with "Storage Administration" as the title attribute, then use [title="Storage Administration"]. Note that the ~ (tilde) is removed from the equation.

In CSS3, there are some additional attribute selectors, such as the *= substring match (see: spec on CSS3 selectors). Other people are trying similar things in this other StackOverflow answer.

Here's an example using their logic. No idea if this works for you, but play around with these other options. Be sure to check browser compatibility, as I'm not sure what the support is for these yet.

[title^='Storage'], [title*=' Storage']{
    display: none;
}
Community
  • 1
  • 1
jeffjenx
  • 17,041
  • 6
  • 57
  • 99
  • Thank you. Does that mean that `[title ~= "Storage"]` will not select element with title Storage2? Is there any way to have one line of css code to select elements with title "Storage", "Storage2" etc? – Radek Jul 08 '15 at 04:01
  • I updated the answer with some additional comments. You are correct `~="Storage"` will not match "Storage2". I think you may be able to accomplish it using either `^=` or `*=` or a combination of both. Let me know if either of them work for you and I'll update the answer for future visitors. – jeffjenx Jul 08 '15 at 04:35
  • 1
    Actually, `[title~="Storage Administration"]` is an invalid selector. As mentioned in the spec that you link to, "If this selector is used, the words in the value must not contain spaces (since they are separated by spaces)." – BoltClock Jul 08 '15 at 07:12
  • 1
    Also, both of your spec links are out of date. The current CSS2.1 spec is here: http://www.w3.org/TR/CSS21/selector.html And [Selectors 3 has been out of draft for several years now](http://www.w3.org/TR/css3-selectors). The current draft is Selectors 4. I'm not entirely sure how the 2013 ED of Selectors 3 differs from the 2011 REC however (not even in the errata). – BoltClock Jul 08 '15 at 07:18
  • Cheers @BoltClock. Thank you clarifying the `~=` functionality for me, I misunderstood the description. I've updated my answer to reflect this and updated the spec links. I'm guessing it is probably safe to use them in all browsers with ongoing support. Appreciate you chiming in. – jeffjenx Jul 08 '15 at 13:34