使用span创建表

发布于 2024-10-01 00:13:21 字数 1344 浏览 4 评论 0原文

我正在尝试使用

概念创建一个表。

但桌子没有正确组合在一起。我找不到问题出在哪里。请告诉我问题是什么。我必须在同一行中生成 4 到 5 行。

示例代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <HEAD>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style>
            .line1
            { 
               background-color:#AAAAAA;
               height: 150px;
               width: 1px;
               display: block;
            } 
            .line2
            { 
               background-color:#CE5611;
               height: 150px;
               width: 1px;
               display: block;
               margin-left: 121px;
            } 
        </style>
    </HEAD>    
    <body>
        <div id="a1" style='padding-left: 14px;width: 100px;'>
            <span>h1</span>
            <span class="line1"></span>
            <span>h2</span>
            <span class="line2"></span>
            <span>h3</span>
            <span class="line1"></span>
        </div>
    </body>
</html>

I am trying to create one table using the <span> and <div> concept.

But the table is not coming together properly. I couldn't find where the issue is. Please tell me what the problem is. I have to produce 4 to 5 lines in a same row.

Sample code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <HEAD>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style>
            .line1
            { 
               background-color:#AAAAAA;
               height: 150px;
               width: 1px;
               display: block;
            } 
            .line2
            { 
               background-color:#CE5611;
               height: 150px;
               width: 1px;
               display: block;
               margin-left: 121px;
            } 
        </style>
    </HEAD>    
    <body>
        <div id="a1" style='padding-left: 14px;width: 100px;'>
            <span>h1</span>
            <span class="line1"></span>
            <span>h2</span>
            <span class="line2"></span>
            <span>h3</span>
            <span class="line1"></span>
        </div>
    </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

格子衫的從容 2024-10-08 00:13:21

相反,这样的方式:

<div id="a1" style='padding-left: 14px;width: 100px;'>
                <span>h1</span>
                <span class="line1"></span>
                <span>h2</span>
                <span class="line2"></span>
                <span>h3</span>
                <span class="line1"></span>
</div>

吗..

#wrapper .content{
  float:left
  width:100px;
  padding:.5em;
}

#wrapper .content span{
 font-weight:bold;
}


<div id="wrapper">
  <div class="content"><span>line 1</span></div>
  <div class="content"><span>line 2</span></div>
  <div class="content"><span>line 3</span></div>
</div>

你知道

Instead this way of going :

<div id="a1" style='padding-left: 14px;width: 100px;'>
                <span>h1</span>
                <span class="line1"></span>
                <span>h2</span>
                <span class="line2"></span>
                <span>h3</span>
                <span class="line1"></span>
</div>

do

#wrapper .content{
  float:left
  width:100px;
  padding:.5em;
}

#wrapper .content span{
 font-weight:bold;
}


<div id="wrapper">
  <div class="content"><span>line 1</span></div>
  <div class="content"><span>line 2</span></div>
  <div class="content"><span>line 3</span></div>
</div>

you got the idea ..

灯角 2024-10-08 00:13:21

您真的希望分类跨度具有 display: block 吗?这迫使每个人都走上一条单独的线。从功能上讲,

有点相同(和

有点相同)。

您可能正在寻找 display: inline-block。这使您能够像您一样阻止属性(高度、宽度),但仍使其在周围内容中移动。另一种选择是使用 display: table-cell此处有一个显示支持图表。

Do you really want the classed spans to have display: block? That forces each one onto a seperate line. Functionally, <span style="display: block"> is kinda the same thing as <div> (and <div style="display: inline"> is kinda the same thing as <span>).

You're probably looking for display: inline-block. That gives you the ability to block attributes (height, width) like you are, but still leave it moving around within the surrounding contents. Another alternative is to use display: table-cell. There's a chart of display support here.

本宫微胖 2024-10-08 00:13:21

您应该使用

You should use a <table>.

微暖i 2024-10-08 00:13:21

我更喜欢使用 lispan 标签,而不是 divspan。它使操作变得更加容易。使用 li 作为 block 和 span inline-block

I prefer using li and span tags instead of div and span. It makes manipulation much easier. With li as block and span inline-block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文