473,748 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.gi f"/></a>

The image is 18x48

Sep 22 '07 #1
9 2560
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.gi f"/></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...@gma il.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************ **********@r29g 2000hsg.googleg roups.com>,
Cartoper <ca******@gmail .comwrote:
On Sep 22, 7:30 pm, "Chris F.A. Johnson" <cfajohn...@gma il.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...@gma il.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.de mon.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*****@codesm iths.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***********@c l.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
27771
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 different border color for a mouse hover effect over the image. With Mozilla, I can simply specify img:hover {...}, but IE allows hover only for <a>. So now I'm looking for a way to set the border for my <a> element rather than the <img>, but...
2
1814
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= "http://localhost/images/200411081456170.Nenuphars.jpg">Image</a> The same application can be launched for any image link. Thank you. Wlad
2
17575
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 enables people to type bold.
5
1702
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
1840
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
27502
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 image when I roll over a thumbnail. I've tried some things, but can't make it work. See here (Warning: adult matter):
6
5854
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: http://groups.google.com/group/comp.infosystems.www.authoring.stylesheets/browse_thread/thread/e9a21d6f46ac7168/40b2599e189fce58?hl=en#40b2599e189fce58 Jim's stylesheet made everything work beautifully in FF; and in IE, too. But when I changed his stylesheet to display thumbnails...
3
6119
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 comuter/Virtual directory/test.jpg /it's working but I can't use this because the image path is in DB with phisycal location. Thanks
3
2853
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: none; which I use to remove the underline from links, but this did not remove the box around the image link. Any thoughts?
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9552
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9326
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8245
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.