Is it a bad practice to hide elements with CSS when you can't remove them with php?
Sometimes when I can't find the way of deactivating a function or any o开发者_如何学Gother elements with PHP, specially in PHP frameworks and PHP CMSs, I just do display: none
, I wonder if this will cause me many problems in the future or is a necessary method?
It depends on what kinds of elements they are.
Possible problems that come to mind are:
- an
img
tag or some other tag pointing to an external resource: it will be loaded nevertheless - the same applies to
iframe
tags - the embedded page will be loaded even whendisplay: none
is set - Hidden elements' contents may still turn up in search engines
- If CSS is turned off in a client, the element will still be visible
- Automated clients parsing the DOM may not realize an element is hidden
- The element will still exist in the eyes of any JavaScript doing DOM manipulations
other than these special cases, it will probably not be a problem.
精彩评论