13

我想隐藏段落中的文字,但上面只有一张图片和一些文字。当我使用 css 不显示任何内容时,所有段落都被隐藏了……但我只想隐藏文本而不是图像。这是代码。

<p>
  <a href="/_blog/News_and_Inspiration/post/Cooking_up_a_storm/"><img alt="" style="border: 0px solid; width: 100px; height: 150px; float: left; margin-right: 10px; margin-bottom: 10px;" src="/images/blog/Shaun-Clouston.jpg" /></a>
    The executive chef of Wellington&rsquo;s award winning  Restaurant, Shaun Clouston is just one of the award winning New Zealand Beef and Lamb Ambassador chefs we have cooking up a storm at our Rural Women New Zealand Beef + Lamb Cooking Demonstrations over the coming months.&nbsp;
</p>

<p>
  <img src="/images/blog/Southland Life Education Trust Car 2.jpg" alt="">
  Two years ago the Southland Life Education Community Trust approached our four Southland Provincials, asking for assistance to replace their educator’s car, as the current one needed major repairs.
</p>
4

5 回答 5

18

Try:

p {
    font-size: 0;
}

And specify the font-size for any descendent elements you want visible.

于 2012-07-04T08:59:02.857 回答
10

根据布局的其余部分以及是否需要坚持display: none;隐藏内容,您可以visbility: hidden;像以下示例中那样使用:

p {
   visibility: hidden;
}

img {
    visibility: visible;
}

请参阅此处的示例小提琴。

于 2012-07-04T09:01:19.003 回答
3

另外的选择:

    p{
        text-indent: -1000px;
    }
    img{
        position: absolute;
        left:10px; /*obviously position how you like*/
    }
于 2012-07-04T09:06:20.793 回答
2

有很多选择,

  1. 文字和背景颜色相同
  2. 字体大小 0px
  3. 不显示
  4. 可见性:隐藏,还有更多...

如果有帮助,很好。谢谢,

于 2016-02-12T11:59:14.030 回答
0

您可以将您的文本放入 span 并使其显示:无;希望对你有帮助 :)

  p span {
display:none;
}

<p>
  <a href="/_blog/News_and_Inspiration/post/Cooking_up_a_storm/"><img alt="" style="border: 0px solid; width: 100px; height: 150px; float: left; margin-right: 10px; margin-bottom: 10px;" src="/images/blog/Shaun-Clouston.jpg" /></a>
  <span>The executive chef of Wellington&rsquo;s award winning  Restaurant, Shaun Clouston is just one of the award winning New Zealand Beef and Lamb Ambassador chefs we have cooking up a storm at our Rural Women New Zealand Beef + Lamb Cooking Demonstrations over the coming months.&nbsp;</span>
</p>
于 2012-07-04T11:21:36.067 回答