473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

CSS property for printing alternative text?

Hi

I have a title with a title gif:

<h1><img src="mytitle.gif" alt="This is my title"></h1>

So this is text-based browser and search-engine friendly and can be easily
formatted with a style sheet.

Now I have a separate stylesheet for media="print". As the title gif does
not look very good when printed it would be very nice to have a CSS property
that outputs the text in the alt attribute.

display:none makes the image disappear without a replacement. I could
duplicate the h1 tag and give both instances class names that can be defined
as display:none in the appropriate style sheet, but that would confuse
non-CSS browsers of all kinds. I would love something like display:alttext.

Is there a way to do that?

Thanks for every hint.

Markus
Jul 20 '05 #1
24 8020
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote:
Now I have a separate stylesheet for media="print". As the title gif does
not look very good when printed it would be very nice to have a CSS property
that outputs the text in the alt attribute.


img:after{display:block;content:attr(alt)}

Won't work in IE.

--
Spartanicus
Jul 20 '05 #2
On Thu, 26 Feb 2004, Markus Ernst wrote:
I have a title with a title gif:

<h1><img src="mytitle.gif" alt="This is my title"></h1>

So this is text-based browser and search-engine friendly


No, it isn't. <h1> is empty for search engines.

Jul 20 '05 #3
On Thu, 26 Feb 2004 18:21:09 +0100, Markus Ernst <derernst@NO#SP#AMgmx.ch>
wrote:
Hi

I have a title with a title gif:

<h1><img src="mytitle.gif" alt="This is my title"></h1>

So this is text-based browser and search-engine friendly and can be
easily
formatted with a style sheet.

Now I have a separate stylesheet for media="print". As the title gif does
not look very good when printed it would be very nice to have a CSS
property
that outputs the text in the alt attribute.


Messy, but it works.

<h1 class="noscreen">This is my title</h1>
<h1 class="noprint"><img src="mytitle.gif" alt="This is my title"></h1>

And the style is obviously noscreen {display:none;} in the screen css and
noprint {display:none;} in the print css.
Jul 20 '05 #4
Andreas Prilop wrote:
<h1><img src="mytitle.gif" alt="This is my title"></h1>
<h1> is empty for search engines.


Only very badly written search engines which ignore alt text. Google
certainly supports this.

--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #5
David Dorward <do*****@yahoo.com> wrote:
Only very badly written search engines which ignore alt text.
Then all search engines are very badly written. But I don't agree.
ALT texts would then be misused for search engine spamming.
Google certainly supports this.


No. More exactly:
www.google.com indexes ALT text only inside <A HREF>.
images.google.com indexes ALT text always.

--
Top-posting.
What's the most irritating thing on Usenet?
Jul 20 '05 #6
Andreas Prilop wrote:
David Dorward <do*****@yahoo.com> wrote:
Only very badly written search engines which ignore alt text. Then all search engines are very badly written. But I don't agree.
ALT texts would then be misused for search engine spamming.


Just becuase a feature can be abused, doesn't mean that it always is, and I
imagine search engines have routines that attempt to deal with it.
Google certainly supports this.


No. More exactly:
www.google.com indexes ALT text only inside <A HREF>.
images.google.com indexes ALT text always.


OK... the google routine to do this sucks. (My previous test to see this
only considered an image which was also a link, there are very few images
on my site which are not links)

--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #7
Markus Ernst <derernst@NO#SP#AMgmx.ch> wrote:
<h1><img src="mytitle.gif" alt="This is my title"></h1>

So this is text-based browser and search-engine friendly and can be
easily formatted with a style sheet.
Not entirely, but for the most part the point will get across.
Is there a way to do that?


http://www.stopdesign.com/also/articles/replace_text/ provides a more
structurally correct method.
--
Michael Wilcox
mjwilco at yahoo dot com
Essential Tools for the Web Developer - http://mikewilcox.t35.com
Jul 20 '05 #8
Spartanicus <me@privacy.net> wrote:
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote:
Now I have a separate stylesheet for media="print". As the title gif does
not look very good when printed it would be very nice to have a CSS property
that outputs the text in the alt attribute.


img:after{display:block;content:attr(alt)}

Won't work in IE.


Should not work in any browser. A Mozilla bug that has been warmly
greeted as an "advanced CSS feature".

Is of no use to the OP as it won't hide the image. Adding:

img {dislay: none}

- also removes the img:after, of course.
Jul 20 '05 #9
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote:
<h1><img src="mytitle.gif" alt="This is my title"></h1> .... Now I have a separate stylesheet for media="print". As the title gif does
not look very good when printed it would be very nice to have a CSS property
that outputs the text in the alt attribute.

display:none makes the image disappear without a replacement. I could
duplicate the h1 tag and give both instances class names that can be defined
as display:none in the appropriate style sheet, but that would confuse
non-CSS browsers of all kinds. I would love something like display:alttext.

Is there a way to do that?


h1 img {
content: attr(alt); /* Only works in Opera 7 */
}

Unlike the Mozilla img:after bug, this really is an advanced (CSS3
proposal) feature.

--
Karl Smith.
Jul 20 '05 #10
Karl Smith <go************@kjsmith.com> wrote:
Should not work in any browser. A Mozilla bug that has been warmly
greeted as an "advanced CSS feature".


This is a valid CSS3 construct. Mozilla correctly interprets it.
--
Michael Wilcox
mjwilco at yahoo dot com
Essential Tools for the Web Developer - http://mikewilcox.t35.com
Jul 20 '05 #11
go************@kjsmith.com (Karl Smith) wrote:
img {dislay: none}

- also removes the img:after, of course.


I can't find the dislay property in the CSS spec. Is it new?

;-)

Just getting you back for "publically published", though I'm still not
sure if it's the erroneous/variant (according to m-w.com, my OED
doesn't list it) spelling or the tautology that you were pointing out,
or both.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #12
On Thu, 26 Feb 2004 18:21:09 +0100, "Markus Ernst"
<derernst@NO#SP#AMgmx.ch> wrote:
Hi

I have a title with a title gif:

<h1><img src="mytitle.gif" alt="This is my title"></h1>

So this is text-based browser and search-engine friendly and can be easily
formatted with a style sheet.

Now I have a separate stylesheet for media="print". As the title gif does
not look very good when printed it would be very nice to have a CSS property
that outputs the text in the alt attribute.

display:none makes the image disappear without a replacement. I could
duplicate the h1 tag and give both instances class names that can be defined
as display:none in the appropriate style sheet, but that would confuse
non-CSS browsers of all kinds. I would love something like display:alttext.

Is there a way to do that?


I guess you could use the Fahrner image replacement technique:

<h1><span>This is my title</span></h1>

then in your screen stylesheet:

h1
{
background: #ffffff url(mytitle.gif) no-repeat;
height: 100px;
/*or whatever dimension you need*/
}
h1 span
{
display: none;
}

That part seems to work in IE5.5, Mozilla 1.4, and Opera 7.1 when I
made an example page.

Then you could use a print stylesheet to suggest the appropriate
rendering for printing.

BTW, the scuttlebut is that some screen readers won't read your <h1>
styled this way, though.

Nick

--
Nick Theodorakis
ni**************@hotmail.com
nicholas_theodorakis [at] urmc [dot] rochester [dot] edu
Jul 20 '05 #13
Steve Pugh <st***@pugh.net> wrote:
go************@kjsmith.com (Karl Smith) wrote:
img {dislay: none}

- also removes the img:after, of course.
I can't find the dislay property in the CSS spec. Is it new?


No, but my keyboard is. It's not nearly as good as the one I attempted
to wash. :-(

Just getting you back for "publically published", though I'm still not
sure if it's the erroneous/variant (according to m-w.com, my OED
doesn't list it) spelling or the tautology that you were pointing out,
or both.


Both. I first wrote, "Never mind that it's repetatively tautologous, I
fear it's also misspelled." Then I got nervous about
missplet/misspelled. Then I wondered about "repetatively" (still am).
So I thought being vague was the best way to hide my ignorance.

--
Karl Smith.
Jul 20 '05 #14
"Michael Wilcox" wrote:
This is a valid CSS3 construct.
It's a valid CSS2 construct, it does not follow that:
Mozilla correctly interprets it.


Correct by what definition? CSS2, CSS2.1, or a CSS3 proposal.
Jul 20 '05 #15
In message <40***************@netnews.worldnet.att.net>, Nick
Theodorakis <ni**************@hotmail.com> writes
On Thu, 26 Feb 2004 18:21:09 +0100, "Markus Ernst"
<derernst@NO#SP#AMgmx.ch> wrote:
Hi

I have a title with a title gif:

<h1><img src="mytitle.gif" alt="This is my title"></h1>

So this is text-based browser and search-engine friendly and can be easily
formatted with a style sheet.

Now I have a separate stylesheet for media="print". As the title gif does
not look very good when printed it would be very nice to have a CSS property
that outputs the text in the alt attribute.

display:none makes the image disappear without a replacement. I could
duplicate the h1 tag and give both instances class names that can be defined
as display:none in the appropriate style sheet, but that would confuse
non-CSS browsers of all kinds. I would love something like display:alttext.

Is there a way to do that?

I guess you could use the Fahrner image replacement technique:

<h1><span>This is my title</span></h1>

then in your screen stylesheet:

h1
{
background: #ffffff url(mytitle.gif) no-repeat;
height: 100px;
/*or whatever dimension you need*/
}
h1 span
{
display: none;
}

That part seems to work in IE5.5, Mozilla 1.4, and Opera 7.1 when I
made an example page.

Then you could use a print stylesheet to suggest the appropriate
rendering for printing.

BTW, the scuttlebut is that some screen readers won't read your <h1>
styled this way, though.


Fahrner image replacement technique:
Every one -- except for the very latest update to JAWS, so far as I
understand it.
Nick


--
Jake
Jul 20 '05 #16
Thank you all for the interesting discussion, specially those who pointed me
to the Fahrner replacement method and the article on stopdesign which I like
very much.

The screen reader downside will hopefully disappear as screen readers could
check if a website or other document is coded accessibly and then prefer the
original code to the screen version. Actually I did not know about screen
readers before; it is interesting that an accessibility improvement on one
side can worsen accessibility on an other side.

BTW does somebody know how search engines handle text in elements with a
display:none or visibility:hidden property? As they started to ignore
"invisible text" already years ago they might have extended this to CSS
hiding techniques.

--
Markus
Jul 20 '05 #17
Karl Smith <go************@kjsmith.com>:

[...]
Both. I first wrote, "Never mind that it's repetatively tautologous, I
fear it's also misspelled." Then I got nervous about
missplet/misspelled. Then I wondered about "repetatively" (still am).


`repet*i*tively tautologous' is, in itself, tautologous!

b.

Jul 20 '05 #18
Ben Shimmin <ba*@monster.buffster.org.uk> wrote:
`repet*i*tively tautologous' is, in itself, tautologous!


"...is, in itself," is, in itself, inherently tautologously
repetitive. And I meant "tautologously repetitive," of course -
"repetitively tautologous," would require two tautologies.

(Unnecessary repetition was, of course, the problem the OP was trying
to avoid. Should anyone accuse me of being off-topic.)

--
Karl Smith.
Interim President,
International Global World "Jonathon Frakes
must never work in films again!" Society
Jul 20 '05 #19
On Fri, 27 Feb 2004 14:53:22 +0100, "Markus Ernst"
<derernst@NO#SP#AMgmx.ch> wrote:

[...]
BTW does somebody know how search engines handle text in elements with a
display:none or visibility:hidden property? As they started to ignore
"invisible text" already years ago they might have extended this to CSS
hiding techniques.


The last time I scanned my raw logs after a googlebot crawl, ISTR that
it did not request the style sheet, so that technique should be safe
for now. But if you do hide text by style sheets, perhaps you should
keep an eye on your logs to see if googlebot starts requesting style
sheets. Or maybe disallow those files in your robots.txt document.

Nick

--
Nick Theodorakis
ni**************@hotmail.com
nicholas_theodorakis [at] urmc [dot] rochester [dot] edu
Jul 20 '05 #20
Under Subject: Re: CSS property for printing alternative text?
Andreas Prilop <nh******@rrzn-user.uni-hannover.de> wrote:
David Dorward <do*****@yahoo.com> wrote:
Only very badly written search engines which ignore alt text.


Then all search engines are very badly written. But I don't agree.
ALT texts would then be misused for search engine spamming.


They could be misused, but I don't think it would be wrong to treat
<h1><img ... alt="foo"></h1> as equivalent to <h1>foo</h1> for the
purposes of indexing. That would very much correspond to the defined
meaning of the alt attribute. Abuse should be treated at a different
level.
Google certainly supports this.


No. More exactly:
www.google.com indexes ALT text only inside <A HREF>.
images.google.com indexes ALT text always.


Sounds interesting - and relatively natural. Is there any statement
from Google itself, or a report of an experimental study, that would
confirm this?

(Moving to c.i.w.a.misc suggested in message headers.)

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #21
go************@kjsmith.com (Karl Smith) wrote:
img:after{display:block;content:attr(alt)}

Won't work in IE.
Should not work in any browser. A Mozilla bug that has been warmly
greeted as an "advanced CSS feature".


Please explain.
Is of no use to the OP as it won't hide the image.


Are you referring to this, or do you mean that the rule proposed should
not work in the sense of producing the presentation of the img
element's alt attribute value as a text block after the image (or its
alternate presentation, the alt text!)? Why?

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #22
go************@kjsmith.com (Karl Smith) wrote:
>Now I have a separate stylesheet for media="print". As the title gif does
>not look very good when printed it would be very nice to have a CSS property
>that outputs the text in the alt attribute.


img:after{display:block;content:attr(alt)}

Won't work in IE.


Is of no use to the OP as it won't hide the image. Adding:

img {dislay: none}

- also removes the img:after, of course.


I opened an old stylesheet and copied the code from there, it contained
further code, unfortunately I had forgotten what it was for so I deleted
part of it before posting, this is the full code:

body>h1.title img{visibility:hidden;width:0;height:0}
body>h1.title
img:after{display:block;visibility:visible;content :attr(alt)}

Watch the wrap.

--
Spartanicus
Jul 20 '05 #23
Spartanicus <me@privacy.net> wrote:
body>h1.title img{visibility:hidden;width:0;height:0}
body>h1.title
img:after{display:block;visibility:visible;conten t:attr(alt)}


I need to inspect code before posting it (the above contains code
specific to my site.

This may work:

body>img{visibility:hidden;width:0;height:0}
body>img:after{display:block;visibility:visible;co ntent:attr(alt)}

But as I can't remember for sure what it was for, it may also not work
:)

I presume that I added the "body>" to hide it from IE, no idea why I
needed it though :)

Looking at the code it could trip up in Opera <7.5 as it contains a
nested visibility bug (fixed in 7.5).

--
Spartanicus
Jul 20 '05 #24
"Nick Theodorakis" <ni**************@hotmail.com> schrieb im Newsbeitrag
news:40***************@netnews.worldnet.att.net...
On Fri, 27 Feb 2004 14:53:22 +0100, "Markus Ernst"
<derernst@NO#SP#AMgmx.ch> wrote:

[...]
BTW does somebody know how search engines handle text in elements with a
display:none or visibility:hidden property? As they started to ignore
"invisible text" already years ago they might have extended this to CSS
hiding techniques.


The last time I scanned my raw logs after a googlebot crawl, ISTR that
it did not request the style sheet, so that technique should be safe
for now. But if you do hide text by style sheets, perhaps you should
keep an eye on your logs to see if googlebot starts requesting style
sheets. Or maybe disallow those files in your robots.txt document.


Good idea. Anyway I try to avoid anything that spiders _could_ interpret as
an attempt to spam them, as I would not like to change all my clients'
websites everytime Google changes it's criteria. Imagine techniques like
that would be used widely to cheat spiders, then the reaction of search
engines would be for sure to stop respecting robots.txt files or at least
the lines regarding style sheets.

But OTOH - if spiders get clever enough to detect all css related cheating
techniques, they could also be clever enough to distinguish wether a hidden
element is in a relation with the visible content or not, so we are on the
safe side again.

--
Markus
Jul 20 '05 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Preston | last post by:
Admission first - I don't actually have a problem here but have noticed that a lot of people have been asking similar questions and getting very varied answers. What I've done is to sort of...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
4
by: Russ | last post by:
To ASP.NET printing experts: My Asp.net web form needs to print some reports at the client side. I've been trying to research this and find some confusing and conflicting information in previous...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
1
by: varun sharma | last post by:
i have a C# windows application in Visual Studio. I have a form which is opened in a panel.i want to print the data in various controls of the form upon clicking a PRINT button.but i don't want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.