Google Answers Logo
View Question
 
Q: Writing a simple HTML code ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Writing a simple HTML code
Category: Computers
Asked by: baab-ga
List Price: $5.00
Posted: 31 Jul 2002 14:07 PDT
Expires: 30 Aug 2002 14:07 PDT
Question ID: 47651
I need to overlay an image (on a URL web page) with another smaller image;
the FIG and OVERLAY tags used to work?  (<FIG SRC>   <OVERLAY SRC>  etc.
so simple!)  why were these taken away? Are they gone?  will they come back?
in the bye, HOW DO I do a simple overlay!?
bob mackey   smackey549@aol.com
Answer  
Subject: Re: Writing a simple HTML code
Answered By: j_philipp-ga on 31 Jul 2002 15:36 PDT
Rated:5 out of 5 stars
 
Hello Baab,

The FIG element was part of HTML3.0. This standard however never
officially made it and was superceded by HTML3.2 during the so-called
browser wars, in which browser vendors abandoned parts of the official
recomendations, while pushing proprietary elements in hopes of a
bigger market share. As to wether or not the FIG element will come
back; it's unlikely at the moment, but you can never know.

In the meantime: these days, we have HTML4 and XHTML1, which are both
intended to just define the logical document structure, while style
sheets (CSS2, Cascading Style Sheets Level 2) are used to suggest
presentational aspects -- for better cross-browser & cross-media
compatibility.

This brings us to your desired effect, of overlaying a bigger image
with a smaller one. I will present you with one possible solution.
First, in the HTML (here, XHTML1) we can define two wrapping elements
(divisors):

<div class="figure"><img src="big.jpg" alt="" /></div>
<div class="caption"><img src="small.gif" alt="" /></div>

Now to style this, put the following line into the "head" section of
your HTML document:

<link rel="stylesheet" href="screen.css" type="text/css"
media="screen" />

This links to "screen.css" (which you can give another name), a style
sheet to be used for the screen (defined by the "media" attribute).
Please create this CSS file with a text editor at the same location as
the HTML file, and put the following in it:

.caption
{
    position: relative;
    top: -20px;
    left: 20px;
}

Above means: every element with the class attribute-value "caption"
should be positioned relative to the context, with the top and left
pixel values as defined.
This works in most modern browsers (such as Internet Explorer 5+,
Netscape 4, 6/ Mozilla 1, and Opera 4+), but it also degrades well for
browsers ignoring the style sheet.


Hope that helps!


References:

The World Wide Web Consortium
http://www.w3.org

Specifications at the W3C

  HTML 3.0 (historical)
  http://www.w3.org/MarkUp/html3/html3.txt

  HTML 3.2 (historical)
  http://www.w3.org/TR/REC-html32

  HTML 4.0
  http://www.w3.org/TR/1998/REC-html40-19980424/

  XHTML 1.0
  http://www.w3.org/TR/xhtml1/

  CSS2
  http://www.w3.org/TR/REC-CSS2/

Validators at the W3C

  HTML Validation
  http://validator.w3.org/

  CSS Validation
  http://jigsaw.w3.org/css-validator/

Request for Answer Clarification by baab-ga on 03 Aug 2002 22:41 PDT
My question ID: 47651
Hello, in trying/using the code as suggested by researcher, it works well;
however, I have discovered that the (ref: below) top and left values viz:
-20 and 20 (px) do not put the overlay image at top left of underside image!
the "left" (20) is ok, the "top" (-20 pixels) had to be changed to -380;
as if the origin (0,0 upper left) is really bottm-left of under image.
This is with Internet EXplorer 5.5, where the little image places itself at
top left of under image IF I USE left=20 top= -380;  with any NETSCAPE (4.7
to 6.2)  I cannot get the little image to go on top of the big image AT ALL!
It seems to ignore the values in screen.css entirely and always puts the
little image DOWN UNDER the big image.  Does Netscape(s) recognize and know
what to do with the "screen css routine"?
I can live with the funny 20,-380   but I need to have Netscape do it as well
as IE,   thanx in advance   bob mackey   baab-ga    smackey549@aol.com

Clarification of Answer by j_philipp-ga on 04 Aug 2002 04:25 PDT
Hello Baab,

The approach described works in Netscape 6 (as well as Internet
Explorer).
Here's a complete sample:

----

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Sample</title>
    <style media="screen"><!--
    .caption 
    {
        position: relative;
        top: -80px;
        left: 20px;
    }
    --></style> 
</head>
<body>

<div class="figure"><img src="big.jpg" alt="" /></div> 
<div class="caption"><img src="small.gif" alt="" /></div>

<div class="figure"><img src="big.jpg" alt="" /></div> 
<div class="caption"><img src="small.gif" alt="" /></div>

</body>
</html>

----

Unfortunately Netscape 4 ignores the positioning. However, you can use
"position: absolute;" in the CSS, which Netscape 4 understands. But
then you have to give the values as absolute values (from top left),
instead of the relative values (which, as you correctly noticed, are
relative from the bottom of the bigger image). See the following
sample:

----

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Sample</title>
    <style media="screen"><!--
    .figure
    {
        position: absolute;
        top: 20px;
        left: 20px;
    }

    .caption 
    {
        position: absolute;
        top: 80px;
        left: 60px;
    }
    --></style>
</head>
<body>

<div class="figure"><img src="big.jpg" alt="" /></div> 
<div class="caption"><img src="small.gif" alt="" /></div>

</body>
</html>

----

The relative positioning works better for you if you have many figures
with captions in the normal text-flow. I suggest you include the
stylesheets as described in the original answer, as the method above
is just for sample purposes.


I hope this helps!
baab-ga rated this answer:5 out of 5 stars
From baab-ga!  (47651)  It worked almot first time I tried it!  One q:
in the css file screen.css I was given left=20 (perfect) and top = -20
(pixels) to use; to get the lil file over on to the big file, i had touse
 top = -380! (not -20)  its as if the origin is not at top left o the big
file but rather the bottom left! no matter, i just played with "x,y" til
i got it where i want it!  thanx! def 5 stars!   smackey549@aol.com

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy