When making a web page with HTML, what is the basic codes for...

2008-08-05 10:37 pm
I can't figure out how to place a link (picture link) next to a regular picture.
The top of the page is a picture, then below is the link. I am trying to make the link right next to the picture. When I type <div align="left"> it doesn't work. How can I get both to be on the same line. I noticed pictures in a row...like 3..they're on the same line, , but when your trying to make 2 different kind of items on the same line it doesn't work the same.

回答 (8)

2008-08-05 10:43 pm
✔ 最佳答案
You need to float your elements.

<div style="float: left;">

or

div {
float: left;
}
2008-08-06 12:44 pm
Never, ever, ever, EVER use tables for laying out a web page. Only the lazy do that. Use table tags only to present tabular data. DIVs and CSS will do a much better presentation for your page(s).

<div style="width: 388px; height: 262px; margin: 0 auto;">
<img src="image1.gif" style="width: 128px; height: 131px;" alt="" /><a href="URL path" title="Mouseover Description"><img src="image2.gif" style="width: 128px; height: 131px;" alt="" /></a><img src="image3.gif" style="width: 128px; height: 131px;" alt="" /></div>

Style and change as you need. Just be sure to set DIV width to include all images and any borders (left and right) you use.

Checked in browsers and works.

Ron
2008-08-06 6:06 am
Here's an example of how to get, for example, three pictures next to each other with some margins on either side of them...
The HTML
---------------
<div id="content">
  <div class="pic">
    <a href="#"> <img src="myIMG.jpg" /> </a>
  </div>
  <div class="pic">
    <a href="#"> <img src="myIMG.jpg" /> </a>
  </div>
  <div class="pic">
    <a href="#"> <img src="myIMG.jpg" /> </a>
  </div>
</div>

The CSS
----------------
#content {
border: 1px solid red;
width: 430px;
padding: 10px;
}

.pic {
border: 1px solid red;
width: 125px;
display: inline;
text-align:center;
margin: 0px 5px 0px 5px;
padding: 3px;
}

.pic img a {
border: none;
}


This will give you a box, with 3 boxes inside. The 3 boxes inside are displayed in a line next to each other and have hyperlinked images in them. You can place whatever you like in these boxes, or style them however you choose.

Note that I placed a red border around each element to show you how each element is layed out. Feel free, like I said, to style however you wish.

=)

Edit:
-------------
I changed the div id of "pic" to div class "pic". You can only reference an ID once in valid HTML....therefore, it is better to use class instead.
2008-08-06 5:46 am
You can do this: <a href="websiteurl"><img src="imageurl"></a> to make the image into a link, or do this: <img src="imageurl"> then put this: <a href="websiteurl">text</a>.
2008-08-06 5:43 am
A div is a block-level element. It will always appear on its own line unless you override this behavior with a stylesheet.

Do you need to put your link inside a div element for some reason? If not, don't bother.
2008-08-06 7:16 am
<table border="0">
<tr valign="bottom">
<td><img src="IMG_FILE"></td>
<td><a href="URL">name of link</a></td>
</tr>
</table>

This will place the link next to the image, both aligned at the bottom of the table, ie. the link will be in line with the bottom edge of the image.

If you want the image and the link to be aligned on top (ie. link aligned with top edge of the image), change valign="bottom" to valign="top"



2008-08-06 5:43 am
You can try to use a table to lay out the thing the way you want, and hide the table border so it doesn't "look" like its a table. People do this all the time.

<table border='0'>
<tr>
<td><img src='YOUR_NON_LINKED_IMAGE_HERE.jpg' /></td>
<td><a href='LINK_GOES_HERE.html'>THE LINK TEXT</a></td>
<td><img src='ANOTHER_IMAGE_GOES_HERE.jpg' /></td>
</tr>
</table>

Hope that helps


收錄日期: 2021-05-03 13:58:48
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080805143725AAuOJzg

檢視 Wayback Machine 備份