如何隐藏未包含在或中的文本?

时间:2022-11-13 19:59:21

I have html where I only want to hide the text portion, but what complicates it is that it is not wrapped in anything. Below is an example:

我有html我只想隐藏文本部分,但让它变得复杂的是它没有包装在任何东西中。以下是一个例子:

<div class="content">

    Give comfortable and durable place to work with a desk.
    Lock the center drawer and all of the drawers lock,
    keeping your files and supplies secure.

    <table cellpadding="4" cellspacing="0">
        <tbody>
            <tr>
                <th align="right">Available Options:</th>
                <td>Desktop Color: Fusion Maple, Gray Nebula...</td>
            </tr>
            <tr>
                <th align="right">Book Box Construction:</th>
                <td>Not applicable</td>
            </tr>
        </tbody>
    </table>
</div>

How can I hide the "Give comfortable and durable..." portion above without changing the html at all? I was hoping to do it via CSS and maybe Javascript if necessary. CSS only would be perfect though. Can anyone help?

如何在不更改html的情况下隐藏上面的“给予舒适和耐用...”部分?我希望通过CSS做到这一点,如果有必要可能是Javascript。但CSS只是完美的。有人可以帮忙吗?

6 个解决方案

#1


3  

Look ma', no hands scripts!

看马',没有手脚本!

CSS only solution

.content
{
    text-indent: -1000em;
}

.content *
{
    text-indent: 0;
}

/* This one's pure cherry on top ;) */
/* Remove excess vertical space */
.content *:first-child
{
    margin-top: -1em;
}

JSFiddle demo.

#2


2  

CSS defines the appearance of the contents of a tag. No tag, no styling.

CSS定义标记内容的外观。没有标签,没有造型。

You need to modify the HTML. Sorry.

您需要修改HTML。抱歉。

#3


2  

This removes the text node, which is a container for the text:

这将删除文本节点,该节点是文本的容器:

var div = document.getElementsByTagName('div')[0];
div.removeChild(div.firstChild);

#4


1  

Using javascript (and jQuery in my case):

使用javascript(和我的情况下的jQuery):

var table = $('.content table'); //copy the table
$('.content').html(table); //replace the html of div.content with table

If you have multiple classes of content then you'll need to rewrite this a bit to work over a collection

如果你有多个类的内容,那么你需要重写一下来处理一个集合

#5


0  

There is no easy way for that. You'll have to write an html stripper on JavaScript or simply modify your html by hands.

没有简单的方法。你必须在JavaScript上编写一个html脱衣舞,或者只是手工修改你的html。

#6


0  

CSS:

#content {
  visibility: hidden;
}

JavaScript:

document.getElementsByTagName("div")[0].style.visibility = "hidden";
or:
document.getElementsByClassName("content")[0].style.visibility = "hidden";

#1


3  

Look ma', no hands scripts!

看马',没有手脚本!

CSS only solution

.content
{
    text-indent: -1000em;
}

.content *
{
    text-indent: 0;
}

/* This one's pure cherry on top ;) */
/* Remove excess vertical space */
.content *:first-child
{
    margin-top: -1em;
}

JSFiddle demo.

#2


2  

CSS defines the appearance of the contents of a tag. No tag, no styling.

CSS定义标记内容的外观。没有标签,没有造型。

You need to modify the HTML. Sorry.

您需要修改HTML。抱歉。

#3


2  

This removes the text node, which is a container for the text:

这将删除文本节点,该节点是文本的容器:

var div = document.getElementsByTagName('div')[0];
div.removeChild(div.firstChild);

#4


1  

Using javascript (and jQuery in my case):

使用javascript(和我的情况下的jQuery):

var table = $('.content table'); //copy the table
$('.content').html(table); //replace the html of div.content with table

If you have multiple classes of content then you'll need to rewrite this a bit to work over a collection

如果你有多个类的内容,那么你需要重写一下来处理一个集合

#5


0  

There is no easy way for that. You'll have to write an html stripper on JavaScript or simply modify your html by hands.

没有简单的方法。你必须在JavaScript上编写一个html脱衣舞,或者只是手工修改你的html。

#6


0  

CSS:

#content {
  visibility: hidden;
}

JavaScript:

document.getElementsByTagName("div")[0].style.visibility = "hidden";
or:
document.getElementsByClassName("content")[0].style.visibility = "hidden";