tags:

views:

49

answers:

2

I have a container that looks like this

<div id="container">This container has a <a href="#">link</a> in it</div>

I want to hide everything in it except the link.

I've tried

#container {display:none;} 
#container a { display:block; }

But that doesn't work.

It's a user style, so I have access only to the CSS. No Javascript. No markup.

A: 

It’s not possible with the code you’re currently using. Because the text fragments are text nodes that are only represented by anonymous inline boxes that can not be styled with display separately.

But if you put the text that’s surrounding the a element also in elements, e.g. spans:

<div id="container"><span>This container has a </span><a href="#">link</a><span> in it</span></div>

Then you can do this:

#container span { display: none; }
#container a { display: block; }
Gumbo
Extra markup won't work here as the OP does not have access to the page.
atxryan
That looks right. But since this is for a user style, I don't have access to the markup. Thanks, though.
Morten J
@Morten J: It depends on what you’re trying to do if your efforts will be successful.
Gumbo
A: 

Using visibility will work here if you don't mind the invisible, non-linked text still taking up space.

#container {
 visibility: hidden;  
}
#container a {
 visibility:visible;  
}

And if you do need to mimic the display block style, you can try:

#container {
 visibility: hidden;   
 position: relative;
}
#container a {
 visibility:visible;  
 position: absolute;
 top: 0;
 left: 0;
}
atxryan
Best suggestion so far. I adjusted the font-size in #container to 0%. Good enough for this one. Thanks.
Morten J