简体   繁体   English

隐藏H1标签中的文本但不隐藏图像

[英]Hide text in H1 tag but not the image

I need to hide the text inside a H1 tag. 我需要隐藏H1标签内的文本。 But not the image. 但不是形象。 Problem is that i only can change the css and not the html 问题是我只能改变CSS而不是html

<h1>
<img src="img/headerimg.png" width="900" height="125"/>
Header 1 text
</h1>

Is there a way to only hide the "Header 1 text" with only css? 有没有办法只用css隐藏“标题1文本”? I'm doing this for big client and they gave me only acces to the css file. 我正在为大客户端做这个,他们只给我访问css文件。

Give a 0px font size 提供0px字体大小

​h1{ font-size:0px }​

Edit: Working sample 编辑:工作样本

Set the image as background of the <h1> , add CSS properties to the <h1> to make it the size of the image and use a negative text-indent on the headline to remove the text. 将图像设置为<h1>背景,将CSS属性添加到<h1>以使其成为图像的大小,并在标题上使用负text-indent来删除文本。 That would be the usual and ideal way to do it if you had access to the html too. 如果您也可以访问html,这将是通常和理想的方式。

Since you only have access to the CSS, you can use this: 由于您只能访问CSS,因此您可以使用:

h1 {
    font-size: 0.1px; /* 0 gets disregarded by Internet Explorer, 0.1 gets interpreted right by every browser */
}

Fiddle: http://jsfiddle.net/VGgnD/ 小提琴: http//jsfiddle.net/VGgnD/

You can do this way using CSS: 您可以使用CSS执行此操作:

<h1>
    <img src="img/headerimg.png" width="900" height="125"/>
    Header 1 text
</h1>

CSS: CSS:

h1 {
    width: 900px;
    height: 125px;
    background: url("img/headerimg.png") no-repeat center center;
    text-indent: -99em;
}

If you have access only to CSS, please display: none; 如果您只能访问CSS,请display: none; the img : img

h1 img {display: none;}

Working Fiddle: http://jsfiddle.net/sJ8JD/ 工作小提琴: http//jsfiddle.net/sJ8JD/

Well the only thing that comes to my mind is this: 那么我唯一想到的就是:

<h1 style="color: transparent; font-size: 0px; text-indent: -99em;">
<img src="http://pokit.org/get/img/18d5148ef77ef2a2d5d8193c1c8789e8.jpg" width="900" height="125"/>
Header 1 text
</h1>

Working example: 工作范例:

http://jsfiddle.net/VRQVs/2/ http://jsfiddle.net/VRQVs/2/

set font-size: 1px !important; set font-size: 1px !important; and set background color as text color 并将背景颜色设置为文本颜色

You can try position:absolute; 你可以试试position:absolute; so the text won't be visible, it will be positioned outside the page. 因此文本将不可见,它将位于页面外。 -5000px

h1 {
  margin-top:-5000px;
  position:absolute;
}
h1 img {
  position:absolute;
  margin-top:5000px;
}

Example

It could be as simple as setting the font-size to 0px 它可以像将font-size设置为0px一样简单

h1 {
   font-size: 0.1px;
}

http://jsfiddle.net/m5V2A/ http://jsfiddle.net/m5V2A/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM