首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在HTML中的表格单元格内添加图像

在HTML中的表格单元格内添加图像
EN

Stack Overflow用户
提问于 2012-11-20 00:10:17
回答 7查看 542.1K关注 0票数 41

很抱歉,我不能做这个简单的事情。我无法在表格单元格中添加图像。下面是我写的代码:

代码语言:javascript
复制
 <html>
   <head>CAR APPLICATION</head>
   <body>

    <table border = 5 bordercolor = red align = center>
    <th colspan = 14>ABCD</th>
    <tr>
        <th colspan = 4>Name</th>
        <th colspan = 4>Origin</th>
        <th colspan = 4>Photo</th>
    </tr>
    <tr>
        <td colspan = 4>Bugatti Veyron Super Sport</th>
        <td colspan = 4>Molsheim, Alsace, France</th>
        <td colspan = 4><img src="C:\Pics\H.gif" alt="" border=3 height=100 width=100></img></td>
    </tr>
    <tr>
        <td colspan = 4>SSC Ultimate Aero TT  TopSpeed</td>
        <td colspan = 4>United States</td>
        <td colspan = 4 border=3 height=100 width=100>Photo1</td>
    </tr>
    <tr>
        <td colspan = 4>Koenigsegg CCX</td>
        <td colspan = 4>Ängelholm, Sweden</td>
        <td colspan = 4 border=4 height=100 width=300>Photo1</td>
    </tr>
    <tr>
        <td colspan = 4>Saleen S7</td>
        <td colspan = 4>Irvine, California, United States</td>
        <td colspan = 4 border=3 height=100 width=100>Photo1</td>
    </tr>
    <tr>
        <td colspan = 4> McLaren F1</td>
        <td colspan = 4>Surrey, England</td>
        <td colspan = 4 border=3 height=100 width=100>Photo1</td>
    </tr>
    <tr>
        <td colspan = 4>Ferrari Enzo</td>
        <td colspan = 4>Maranello, Italy</td>
        <td colspan = 4 border=3 height=100 width=100>Photo1</td>
    </tr>
    <tr>
        <td colspan = 4> Pagani Zonda F Clubsport</td>
        <td colspan = 4>Modena, Italy</td>
        <td colspan = 4 border=3 height=100 width=100>Photo1</td>
    </tr>
</table>
 </body>
<html>

我做错了什么?这是我的输出屏幕:

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2012-11-20 16:18:40

这对我很有效:

代码语言:javascript
复制
 <!DOCTYPE html> 
  <html>
  <head>
<title>CAR APPLICATION</title>
 </head>
 <body>
<center>
    <h1>CAR APPLICATION</h1>
</center>

<table border="5" bordercolor="red" align="center">
    <tr>
        <th colspan="3">ABCD</th> 
    </tr>
    <tr>
        <th>Name</th>
        <th>Origin</th>
        <th>Photo</th>
    </tr>
    <tr>
        <td>Bugatti Veyron Super Sport</th>
        <td>Molsheim, Alsace, France</th>
                <!-- considering it is on the same folder that .html file -->
        <td><img src=".\A.jpeg" alt="" border=3 height=100 width=300></img></th>
    </tr>
    <tr>
        <td>SSC Ultimate Aero TT  TopSpeed</th>
        <td>United States</th>
        <td border=3 height=100 width=100>Photo1</th>
    </tr>
    <tr>
        <td>Koenigsegg CCX</th>
        <td>Ängelholm, Sweden</th>
        <td border=4 height=100 width=300>Photo1</th>
    </tr>
    <tr>
        <td>Saleen S7</th>
        <td>Irvine, California, United States</th>
        <td border=3 height=100 width=100>Photo1</th>
    </tr>
    <tr>
        <td> McLaren F1</th>
        <td>Surrey, England</th>
        <td border=3 height=100 width=100>Photo1</th>
    </tr>
    <tr>
        <td>Ferrari Enzo</th>
        <td>Maranello, Italy</th>
        <td border=3 height=100 width=100>Photo1</th>
    </tr>
    <tr>
        <td> Pagani Zonda F Clubsport</th>
        <td>Modena, Italy</th>
        <td border=3 height=100 width=100>Photo1</th>
    </tr>
</table>
  </body>
  <html>
票数 13
EN

Stack Overflow用户

发布于 2012-11-20 00:20:31

您的HTML上有一些语法错误。

首先,图像的URL需要指向公共Internet上的地址。查看您的页面的用户将不会拥有您的硬盘,因此指向本地硬盘上的文件将无法工作。将C:\Pics替换为映像的实际URL,而不是开发计算机文件系统上的路径。如果您想绝对确定,请使用另一台计算机并将img tag src属性值粘贴到浏览器的地址栏中。如果它在那里工作,那你就很棒。不要认为路径可以是相对的并且仍然有效,但它需要相对于嵌入它的网页的公共URL。

第二,<title>标记。如果您需要浏览器上的标题,但无法设置标题的格式,则需要添加此标记。

第三个错误是,如果是关于<th>标记,则必须在<tr>标记内添加此标头,因为<th>需要一行(由<tr>创建)。

另一件事是,你不需要你做的所有的colspan。

我试着按照你的需要做一个有效的html。看一看:

代码语言:javascript
复制
<!DOCTYPE html> 
<html>
<head>
    <title>CAR APPLICATION</title>
</head>
<body>
    <center>
        <h1>CAR APPLICATION</h1>
    </center>

    <table border="5" bordercolor="red" align="center">
        <tr>
            <th colspan="3">SONAKSHI RAINA 10B ROLL No:-32</th> 
        </tr>
        <tr>
            <th>Name</th>
            <th>Origin</th>
            <th>Photo</th>
        </tr>
        <tr>
            <td>Bugatti Veyron Super Sport</td>
            <td>Molsheim, Alsace, France</td>
                    <!-- considering it is on the same folder that .html file -->
            <td><img src="H.gif" alt="" border=3 height=100 width=100></img></td>
        </tr>
        <tr>
            <td>SSC Ultimate Aero TT  TopSpeed</td>
            <td>United States</td>
            <td border=3 height=100 width=100>Photo1</td>
        </tr>
        <tr>
            <td>Koenigsegg CCX</td>
            <td>Ängelholm, Sweden</td>
            <td border=4 height=100 width=300>Photo1</td>
        </tr>
        <tr>
            <td>Saleen S7</td>
            <td>Irvine, California, United States</td>
            <td border=3 height=100 width=100>Photo1</td>
        </tr>
        <tr>
            <td> McLaren F1</td>
            <td>Surrey, England</td>
            <td border=3 height=100 width=100>Photo1</td>
        </tr>
        <tr>
            <td>Ferrari Enzo</td>
            <td>Maranello, Italy</td>
            <td border=3 height=100 width=100>Photo1</td>
        </tr>
        <tr>
            <td> Pagani Zonda F Clubsport</td>
            <td>Modena, Italy</td>
            <td border=3 height=100 width=100>Photo1</td>
        </tr>
    </table>
</body>
<html>
票数 14
EN

Stack Overflow用户

发布于 2012-11-20 00:16:13

在表的顶部有一个不在TR中的TH。解决这个问题。

关于您的映像问题,您引用的映像完全来自计算机的硬盘驱动器。别干那事。

你还有一个不应该出现在那里的结束标记。

它应该是:

代码语言:javascript
复制
<img src="h.gif" alt="" border="3" height="100" width="100" />

还有这一点:

代码语言:javascript
复制
<table border = 5 bordercolor = red align = center>

你的也是一团糟。您似乎只有三列,但在您的代码中有14和4列。

应该是:

代码语言:javascript
复制
<table border="5" bordercolor="red" align="center">

此外,您还没有声明DOCTYPE。您至少应该添加:

代码语言:javascript
复制
<!DOCTYPE html> 
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13457710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档