可以使用 display:none 隐藏任何内容吗?

发布于 2024-08-22 05:27:24 字数 294 浏览 4 评论 0原文

使用 display:none 可以暂时或永久隐藏任何内容吗?在动态站点中,页面的许多组件来自不同的插件等,很多时候,如果客户端不需要页面上的任何内容,那么我使用 dispaly:none 来隐藏页面中的内容。我不会从实际源中删除东西,因为客户可以回来要求再次启用该东西。

那么,如果我永远使用 Display:none 保持任何元素隐藏,那么让东西从 display:none 中隐藏的优点和缺点是什么?

在搜索引擎优化、屏幕阅读器、辅助功能等方面有什么缺点吗?

Is it ok to hide any thing temporarily or forever using display:none? in dynamic site where many component of page coming from different plugins etc and many time if client doesn't want any thing on page then i use dispaly:none to hide things from page . I do not remove thing from actual source because client can come back ask to enable that thing again.

so what are pros and cons to keep things hide from display:none if i keep any element hide using Display:none forever?

is there any cons in terms of SEO, Screen reader, Accessibility etc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

假装不在乎 2024-08-29 05:27:25

这里可能还值得一提的是,一些搜索引擎(例如谷歌)确实会评估隐藏内容。

使用 display:none; 隐藏大量文本是许多搜索引擎认为是关键字垃圾邮件的事情之一。

:)

It's probably also worth mentioning here that some search engines (Google for example) do take stock of hidden content.

Hiding huge amounts of text using display:none; is one of the things many search engines pick up on as keyword spamming.

:)

我纯我任性 2024-08-29 05:27:25

当您执行客户端 Ajax 时,使用“display:none”隐藏/显示内容是有意义的。这样您就可以切换视图/选项卡,而无需进行服务器往返。

当存在安全隐患时,需要从页面标记中实际删除某些内容。如果用户无权查看某些敏感信息,那么当他们单击“显示源”时,这些信息就不应该出现。

It makes sense to hide/show stuff with 'display:none' when you do client-side Ajax. This way you can switch views/tabs without doing server round-trip.

It is needed to actually remove something from the page markup when there are security implications. If a user doesn't have the right to see some sensitive information, it shouldn't be there when they click "Display source".

时光倒影 2024-08-29 05:27:25

display: none 适合在人们关闭 CSS 或使用不支持 CSS 的浏览器时隐藏您希望可见的内容。

display: none is good to hide things you want visible when people turn css off or use browsers that doesnt support css.

咆哮 2024-08-29 05:27:25

就可访问性而言,很有可能用“display: none;”隐藏了一些东西。屏幕阅读器不会读取。如果您打算这样做,这可能是可以接受的。

仅隐藏屏幕阅读器/css-offers 内容的可能替代方法是使用此类:

.offscreen {
    position: absolute;
    left: -9000px;
    width: 0;
    overflow: hidden;
}

以及以下 HTML:

<h3 class="offscreen">Site Navigation</h3>

有关隐藏技术的完整信息:
http://www.access-matters.com /2005/04/23/屏幕阅读器测试结果/

As far as accessibility goes, there is a strong chance that something hidden with "display: none;" will NOT be read by a screen-reader. This may be acceptable if you intend for it to be that way.

A possible alternative to hiding content for screen-readers/css-offers only is to use this class:

.offscreen {
    position: absolute;
    left: -9000px;
    width: 0;
    overflow: hidden;
}

And the following HTML:

<h3 class="offscreen">Site Navigation</h3>

For full information on hiding techniques:
http://www.access-matters.com/2005/04/23/screen-reader-test-results/

情绪操控生活 2024-08-29 05:27:24

如果客户希望将其删除,请创建该页面的备份,并发布实际已删除该页面的页面。不要用 CSS 代替实际删除项目。如果他们决定将来需要它,那么就进去将您的备份交换为实时副本。如果您正在处理动态输出(在 PHP 或类似技术的情况下),您可以使用注释来停止该特定输出,这样它们就不会包含在响应中。

If the client wants it removed, then create a backup of the page, and post a page that actually has it removed. Don't substitute CSS for actually removing an item. If they decide they want it in the future, then go in and swap your backup for your live copy. If you're dealing with dynamic output (in the case of PHP or a comparable technology) you could stop that particular output with comments so they're never included in the response.

许一世地老天荒 2024-08-29 05:27:24

优点:非常容易做到

缺点:

  • 您仍在服务器端加载组件,客户端将下载它们。浏览器根本不会“显示”它们。
  • 任何使用“查看源代码”的人都可以看到“隐藏”的值。所以永远不要用它来隐藏敏感信息。

您可以简单地在服务器端“注释”这些部分,以节省服务器上的大量处理、带宽等。

Pros: Very easy to do

Cons:

  • You are still loading the components on the server side and the client will download them. The browser will simply not "show" them.
  • Anyone using "view source" will be able to see the values that are "hidden". so never use it to hide sensitive information.

You can simply "comment" these section server side to save a lot of processing on the server, bandwidth, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文