Using CSS to selectively hide information
I have a table that displays information about a list of customers. I want to sel开发者_如何学JAVAectively hide certain fields of information in different pages. Is it a good practice to simply define each page as a different ID and use CSS to control what is shown. Or should I actually go into the controllers and models to control it.
For example, each customer has 3 pieces of information to it: name, phone number, address and the html, css mark up is as follows:
<style>
#SomeSpecificPage span.text-phonenumber { display: none }
</style>
<div id="SomeSpecificPage">
<span class="text-name"><% name %></span>
<span class="text-phonenumber"><% phone number %></span>
<span class="text-address"><% address %></span>
</div>
That is not a problem. Many people apply the page ID to the body
element instead, but the practice is similar and isn't something naughty.
It's up to you whether you want to use CSS with page IDs to hide the fields or control output with your server-side code. Either is fine.
You could use after: or before: with CSS3.
This takes a different approach but may achieve what you're after. This should at least keep it out of sight from web crawlers which is what I imagine is what you want to achieve by hiding it. See Fiddle:
.text-name:after{
content:'contenthere'
}
.text-phonenumber:after{
content:'phonenumberhere'
}
.text-address:after{
content:'addresshere'
}
http://jsfiddle.net/CPVeA/
Keep in mind browser support: http://caniuse.com/#feat=css-gencontent
For visibility, I like to create a class called .hidden { display: none; }
and put that on the elements I want hidden by default. Then you can use whatever language to toggle that class.
It depends on how you define "hide"... If a web-literate viewer views your source they can see everything hidden with css. Is that a problem? If not, go for it. Its a simple and effective solution.
On the other hand, is it confidential information that will get you in trouble? If so, don't even let it render, as in: alter the controls.
精彩评论