简体   繁体   English

如何隐藏HTML部分而不删除它?

[英]How do I hide a section of HTML without removing it?

I want to hide a section of HTML, and stop it being viewable from the webpage itself without removing it. 我想隐藏HTML的一部分,并阻止它在不删除的情况下从网页本身可见。 Is this possible in HTML or CSS, or can anyone recommend a Javascript library capable of doing this? 在HTML或CSS中是否可行,或者有人可以推荐一个能够做到这一点的Javascript库? The part that needs hiding looks similar to this: 需要隐藏的部分类似于以下内容:

<p>text1<strong>text2</strong></p>

I don't want it to display on the website but I do want it viewable when looking at the code directly. 我不希望它显示在网站上,但我希望直接查看代码时可以看到它。

Any ideas? 有任何想法吗?

Add a "hidden" class to select the target HTML and use display: none in CSS: 添加一个“隐藏”类以选择目标HTML并使用display: none在CSS中display: none

HTML: HTML:

<p class="hidden">text1<strong>text2</strong></p>

CSS: CSS:

.hidden {
  display: none;
}

...or you could inline it directly: ...或者您可以直接内联它:

<p style="display:none">text1<strong>text2</strong></p>

您可以使用CSS显示:无

<p style="display: none;">text1<strong>text2</strong></p>

There's a visibility property in CSS: http://www.w3schools.com/cssref/pr_class_visibility.asp CSS中有一个可见性属性: http : //www.w3schools.com/cssref/pr_class_visibility.asp

You could wrap whatever elements you want hidden in a <div> and set it's visibility to hidden. 您可以将要隐藏的任何元素包装在<div> ,并将其可见性设置为hidden。 This property can also be changed dynamically with Javascript. 也可以使用Javascript动态更改此属性。

You could also look into using jQuery, which has animated hide() and show() functions 您也可以考虑使用jQuery,它具有动画的hide()show()函数

I'm not sure what exactly you need, but you can try commenting it out, like: 我不确定您到底需要什么,但是您可以尝试将其注释掉,例如:

 <!--<p>text1<strong>text2</strong></p>-->

Or, add a class/id then select it and on css: 或者,添加一个类/ id,然后在css上选择它:

.myhidden{
display: none;
}
<p class="myhidden">text1<strong>text2</strong></p>

Add a class to that section of html and give that class property to be hidden. 将一个类添加到html的该部分,然后将该类属性隐藏。

Example : 范例:

 .hidden { display:none; } 
 <div class="hidden"> <a href="product.html"><img title="Necklace" alt="Necklace" src="image/product/05-necklace-60x60.jpg"></a> </div> 

我还想向CSS-Tricks推荐这段最近的视频,概述并解释了许多使用CSS隐藏元素的技术: CSS-Tricks截屏视频#142:使用CSS隐藏事物

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 显示其他部分时如何隐藏部分? - How do I hide a section when I show a different section? 如果数据为空,如何隐藏可折叠 FAQ 的一部分? - How do I hide a section of a collapsible FAQ if the data is empty? 如何在不占用空间的情况下隐藏x时间的html元素? - How do I hide html elements for x time without them taking up space? 在我的HTML页面的部分外部单击时如何隐藏部分? - How to hide a section when click outside the section in my HTML page? HTML/jQuery - 如何动态突出显示当前页面或部分? - HTML/jQuery - How do I dynamically highlight the current page or section? 如何显示和隐藏不同 <section> 使用jQuery我的html页面? - How can I show and hide different <section> of my html page using jquery? 如何在iOS上将状态栏透明化而不在Ionic 3中将其删除? - How do I make the statusbar transparent on iOS without removing it in Ionic 3? 单击链接到页面某个部分的菜单项时,如何隐藏一个汉堡菜单? - How do I get a hamburger menu to hide when clicking a menu item that links to a section on the page? 如何在不从图例中删除饼图的情况下将饼图的切片隐藏在HighCharts中? - How Can I Hide a Pie Chart's Slice in HighCharts Without Removing It From the Legend? 如何隐藏与没有jQuery时单击的元素最接近的元素? - How do I hide the closest element to the element that was clicked without jQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM