Reputation: 4822
Have HTML pages with many sections and each section has a section title displayed as an image (to use nice font). The problem is that even if I specify an 'alt' and 'title' text on each image/title the Ctrl+F browser functionality does not find the text. Thought two possible solutions but not very happy about them
Use embed fonts. Problem: Can not find the font required by client to use and not sure about copyrights.
Have the text in the image in DIV near the image but hidden from user view. Problem: Can search engines consider this keyword stuffing? Will browser find text if display:none
Does anybody has a better solution? Thanks Riga
Upvotes: 10
Views: 7038
Reputation: 133
Looks like times have changed, I came here looking for the API to style the search results lol
Upvotes: 0
Reputation: 37803
Generally the best approach to image replacement is to do so exclusively within the stylesheet.
The HTML should still look like:
<h2 id="fantastic-section-of-awesomeness"><span>This is an Ordinary Heading</span></h2>
Your CSS can then do:
h2#fantastic-section-of-awesomeness {
background: ...; /* The replacement image */
}
h2 span {
text-indent: -100000px;
}
Note that the text is not actually hidden. Some screen readers interpret display: none;
incorrectly (even when given in a media="screen"
stylesheet). Instead, we simply shift it far off the left side of the screen where it can't realistically be seen.
I have not specifically tested this for Ctrl+F, but the fact that the text is still technically visible should allow the browser to find it.
It will not be able to highlight the image as a match, however, which may still lead to confusion. There's no real way around that without using an @font-face
.
Upvotes: 2
Reputation: 2850
You could also use the z-index on elements:
<html>
<body>
...
<div>
<div style="position:absolute; z-index: 1">My Section Header</div>
<div style="position:absolute; z-index: 2"><img src="test.png"/></div>
</div>
...
</body>
</html>
The image is in front of the text so that the user sees only the image but can find the section when he searches for "My Section Header".
Upvotes: 1
Reputation: 73292
Why not try out the Google Font Directory
The Google Font Directory lets you browse all the fonts available via the Google Font API. All fonts in the directory are available for use on your website under an open source license and are served by Google servers.
Upvotes: 5
Reputation: 2694
To accomplish this I have used the typeface.js Javascript library
You can generate custom fonts for this library using this generator
These sites also have examples and usage instructions.
Upvotes: 2