2012-07-04 70 views
9

我想隐藏段落中的文本,但其上有一个图像和一些文本。当我使用CSS来显示没有,所以所有的段落都隐藏了......但我只想隐藏文字而不是图像。 这是代码。只隐藏html段落中的文本

<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> 
+3

代码比这个图像预览更好。 – SVS

+0

@svs你没有OCR? –

+0

得到了jsfiddle? – starbeamrainbowlabs

回答

12

尝试:

p { 
    font-size: 0; 
} 

,并指定字体大小为你想要的任何可见的后代元素。

+2

注意。小心IE浏览器。它会失败的:) :) – PeeHaa

+0

@PeeHaa在IE9中工作,但IE8仍然显示小文本。 –

+0

我知道..... :-) – PeeHaa

8

根据您的布局的休息,是否需要坚持display: none;隐藏的内容,你可以visbility: hidden;在下面的示例中使用,如:

p { 
    visibility: hidden; 
} 

img { 
    visibility: visible; 
} 

见例如拨弄here

+0

这实际上是一个非常好的答案,但重点必须放在布局的其余部分上,因为“visibility:hidden”元素仍然可以占用页面上的空间。 “display:none”必然是遗传的,尽管我认为它更有意义。 –

+0

thnks David Thomas其工作效率更高... – asif

+1

@asif因此,您应该接受他的回答以显示其他问题,解决您的问题。 – Sirko

3

另一种选择:

p{ 
     text-indent: -1000px; 
    } 
    img{ 
     position: absolute; 
     left:10px; /*obviously position how you like*/ 
    } 
+0

如果文本很长,'letter-spacing:-negative value'也可以帮助 – biziclop

0

你可以把你的文本跨度并使其显示:无;希望这将帮助你:)

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> 
1

许多选项存在,

  1. 文字和背景颜色相同
  2. 字号0像素
  3. 显示无
  4. visibility:hidden的 和许多更多...

如果帮助,很好。 谢谢,