[英]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.