473,383 Members | 1,855 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,383 software developers and data experts.

putting an image link into the CSS

I want to move the image for a link from the HTML to the CSS, but
cannot figure out how to do it. Here is the old HTML:

<a href="somewhere.html"><img src="anImage.gif"/></a>

The image is 18x48

Sep 22 '07 #1
9 2531
On 2007-09-22, Cartoper wrote:
I want to move the image for a link from the HTML to the CSS, but
cannot figure out how to do it.
CSS is for presentation, not content. You cannot do it with CSS
unless you want it to be a background image.
Here is the old HTML:

<a href="somewhere.html"><img src="anImage.gif"/></a>

The image is 18x48

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Sep 22 '07 #2
On Sep 22, 7:30 pm, "Chris F.A. Johnson" <cfajohn...@gmail.comwrote:
>
CSS is for presentation, not content. You cannot do it with CSS
unless you want it to be a background image.
Exactly, I am trying to figure out how to make it the background image
of the link. What I am trying to do is move all the presentation
formatting to the CSS, including the images. The ultimate objective
is to be able to change the CSS file and change the whole theming of
the site.

Sep 23 '07 #3
In article
<11**********************@r29g2000hsg.googlegroups .com>,
Cartoper <ca******@gmail.comwrote:
On Sep 22, 7:30 pm, "Chris F.A. Johnson" <cfajohn...@gmail.comwrote:

CSS is for presentation, not content. You cannot do it with CSS
unless you want it to be a background image.

Exactly, I am trying to figure out how to make it the background image
of the link. What I am trying to do is move all the presentation
formatting to the CSS, including the images. The ultimate objective
is to be able to change the CSS file and change the whole theming of
the site.
If your images are just for decoration, and you want them to be
background, then that is simple enough, the image will fit in the
element if the latter is dimensioned sufficiently. Something
like:

background: #fffcdf url("pics/montageStrip50.jpg");

But your initial desire to making the image a link will have to
be modified to wanting to make some other content of the element
a link. You will find it not easy to make the whole area taken up
by the background a link without playing tricks and having it
work well cross browser. But someone may have a simple answer for
you? I say, put in the pic as foreground and make it a link if it
is meaningfully something that people will understand. Or leave
images as background but make other provisions that people will
understand as meaningfully a link (like some text).

--
dorayme
Sep 23 '07 #4
Cartoper wrote:
On Sep 22, 7:30 pm, "Chris F.A. Johnson" <cfajohn...@gmail.comwrote:
> CSS is for presentation, not content. You cannot do it with CSS
unless you want it to be a background image.

Exactly, I am trying to figure out how to make it the background image
of the link. What I am trying to do is move all the presentation
formatting to the CSS, including the images. The ultimate objective
is to be able to change the CSS file and change the whole theming of
the site.
Wrong approach.

Your `img' element requires an (here: non-empty) `alt' attribute value in
either case, for validity and accessibility. Which clearly indicates that
an image that is the content of an a[href] element is not presentational, it
is content. You will have to replace that content with something else if
you use a background image, because otherwise that link will no longer be
accessible for people and ignored by search engines. (There is no way to
specify a textual alternative for background images.)

But if you use text and a background image, it is likely that you will run
into accessibility issues in the case CSS is supported and the
"presentational" background image can be perceived by the user (e.g. bad
contrast and scaled fonts).

And if you put the text into the image and make the content transparent to
avoid that, it is not unlikely that this will be (mis)recognized by search
engines as an attempt to trick them, therefore being ignored as well and
your site maybe blacklisted.

So you you better stick with the `img' element, and provide the `alt'
attribute. And if theming is an issue, there is server-side scripting.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Sep 23 '07 #5
Thomas 'PointedEars' Lahn wrote:
>
But if you use text and a background image, it is likely that you will run
into accessibility issues in the case CSS is supported and the
"presentational" background image can be perceived by the user (e.g. bad
contrast and scaled fonts).
?

If you mean the text is in the background image, then that can most
definitely be a problem.

However, plain text links styled with a background image can be very
accessible, providing they are done correctly. A patterned bg can
certainly pose a readability problem, but common effects like drop
shadows are not. Look up 'CSS sliding doors' for example.
And if you put the text into the image and make the content transparent
Are you referring to image replacement? That's the common term for
hiding foreground text with background images via various CSS
techniques. IR was originally developed strictly to benefit search
engines and pretty much all methods have some kind of accessibility problem.
it is not unlikely that this will be (mis)recognized by search
engines as an attempt to trick them, therefore being ignored as well and
your site maybe blacklisted.
I wouldn't go that far, though keyword spamming may get you blacklisted
no matter how you do it.
So you you better stick with the `img' element, and provide the `alt'
attribute.
I think it really depends on the context, which the OP hasn't provided.

--
Berg
Sep 23 '07 #6
On 23 Sep, 00:05, Cartoper <carto...@gmail.comwrote:
I want to move the image for a link from the HTML to the CSS, but
cannot figure out how to do it.
Don't. CSS only does "background" images, and that's probably not what
you want.

Use an <imgtag, same as you always did. CSS doesn't have a direct
equivalent for this.

Sep 24 '07 #7
Thomas 'PointedEars' Lahn wrote:
>
the `a' element contained nothing else but
the `img' element, the `img' element has to refer to a graphic providing
information about the purpose of the link.

such an image would still not be presentational (it has
*meaning*), and so CSS would be the wrong approach.
Actually, the alt text to go with that image would have meaning, not
necessarily the image itself. Seems to me the whole purpose of the OP's
inquiry was to be able to style the link independently of its content
(which is probably the alt text, not the graphic), and is *exactly* the
right job for CSS.

Such a change often requires thinking about the content differently than
the old-school way supplied by the OP. You're intentions on this subject
may be in the right place, but your advice is too narrow-minded. Look at
the problem from a different angle and you'll see more possibilities.

--
Berg
Sep 24 '07 #8
Andy Dingley <di*****@codesmiths.comwrites:
On 23 Sep, 00:05, Cartoper <carto...@gmail.comwrote:
>I want to move the image for a link from the HTML to the CSS, but
cannot figure out how to do it.

Don't. CSS only does "background" images,
Not /only/ background images:

<style>
a#muddy-the-waters:before
{ content: url("mud.png");
}
</style>

Cross-browser operation? Pardon, what was that? I heard the
"cross" bit...

--
Jón Fairbairn Jo***********@cl.cam.ac.uk
Sep 24 '07 #9
Bergamot wrote:
Thomas 'PointedEars' Lahn wrote:
>the `a' element contained nothing else but the `img' element, the `img'
element has to refer to a graphic providing information about the purpose
of the link.

such an image would still not be presentational (it has
*meaning*), and so CSS would be the wrong approach.

Actually, the alt text to go with that image would have meaning, not
necessarily the image itself.
If the image would be the only content of the `a' element as the OP stated,
the image would not be presentational, period.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Sep 24 '07 #10

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

Similar topics

33
by: Thomas Mlynarczyk | last post by:
Hi, I'm looking for a way to put a 1px solid border around the image in this link: <a href="some.html"><img src="some.gif"></a> Well, that, by itself, is simple. However, I would like to have a...
2
by: Wlad | last post by:
Hi, Does anybody knows how to make the browser lauch an external image editor (i.e. Photoshop) when the user clicks on a link like this : <a href=...
2
by: Madame Blablavatsky | last post by:
hello, i have an image that is also a link: <a href="javascript:opmaak('bold','')"><img src='bold_uit.gif name='uit'></a> when the image/link is clicked it triggers a javascript that...
5
by: Mel | last post by:
i like to place an image link on my page that stays up for 2 seconds and user can interact with. if no interaction in 2 seconds the image and the link should disapear please help
2
by: cyberclone via DotNetMonster.com | last post by:
Hi All, Please help me. How to put image to Application Settings. What kind ok type can i use for image in application settings Type Col. Thanks, Cyber Clone --
7
by: fredo | last post by:
I've studied Eric Meyer's pure css popups, version two: http://meyerweb.com/eric/css/edge/popups/demo2.html which pops up an image when I roll over a text link. Now I want to pop up a large...
6
by: fredo | last post by:
A few days ago, Jim answered (THANK YOU, Jim) my question about how to make an image pop up when an image link is hovered. That discussion is here: ...
3
by: zion | last post by:
Hello, How can I return image link with webservice that I could see it in web page? The image is on my hard disk and <img src="c:\pictures\test.jpg" /does not work. If I use <img src=http://My...
3
by: mcfly1204 | last post by:
I have an image link, an image within an anchor tag, that I would like to remove the styling of. When I say styling, I mean the default blue box around the image. I have tried: text-decoration:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.