Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use pure css selector to select hidden element

<td class="col" style="display:none">AAA
      <span prop="1" class=" clear-icon " style=""></span>
</td>

I want to use pure css to hide text "AAA" to show span btn. Is there a way to do it in pure css?

like image 528
9blue Avatar asked May 05 '14 20:05

9blue


People also ask

How do you select certain elements in CSS?

The CSS id Selector The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

Is there a CSS selector for elements containing certain text?

The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.

How do I select all child elements except one in CSS?

To select all the children of an element except the last child, use :not and :last-child pseudo classes.


2 Answers

If your design is not really responsive, I mean you can just need to set fixed font-size for the inner span, I think we have a clean solution like this. The idea is to set font-size of the td to 0, it will hide the text node completely:

.col[style*="display:none"] {
  display:table-cell!important;
  font-size:0;
}
.col > span {
  font-size:20px;
}

Demo.

like image 150
King King Avatar answered Oct 19 '22 16:10

King King


You can use visibility property but this will reserve the space for text "AAA":

.col {    
    visibility:hidden;
}

.clear-icon {
    visibility:visible;
}

Also, if you can't remove display:block !important; from your td tag just add !important rule in CSS

.col {
    display:block !important;
    visibility:hidden;
}
like image 21
Artem Petrosian Avatar answered Oct 19 '22 16:10

Artem Petrosian