Quantcast
Channel: Hide element, but show CSS generated content - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by tinystride for Hide element, but show CSS generated content

$
0
0

For better browser support:

Wrap the text that should be hidden within an additional span element, and apply classes to that span to hide the text you wish to be hidden.

HTML:

<span class="addbefore"><span class="visuallyhidden">This text will not show.</span></span>

CSS:

.addbefore:before {  content: "Show this";}.visuallyhidden {  border: 0;  clip: rect(0 0 0 0);  height: 1px;  margin: -1px;  overflow: hidden;  padding: 0;  position: absolute;  width: 1px;}

The .visuallyhidden class used above is from the current version of HTML5 Boilerplate: https://github.com/h5bp/html5-boilerplate/blob/master/css/main.css

The advantages of this solution:

  • Semantic HTML
  • Complete browser support
  • No problems with tiny text like other small font-size solutions.
  • The hidden content won't take up space

See it in action here: http://jsfiddle.net/tinystride/A9SSb/


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>