带有 DataList 和 DIV 的水平表?

发布于 2024-11-02 16:23:44 字数 2163 浏览 4 评论 0 原文

我正在尝试创建一个表格布局,标题位于左侧,字段水平对齐。 (请参见下面的模型。)我尝试使用 DataList 来完成此操作(使用 .NET 2.0),并将其包装在 x 轴上带有滚动条的 div 中,以便如果有足够的组可见,则滚动将会出现栏。

               Group One      Group Two      Group Three
Header One      Value          Value          Value
Header Two      Value          Value          Value
Header Three    Value          Value          Value

我正在努力解决两点,都在下面的代码和 jsFiddle 中看到。

  • 如何将 #itm 块保持在一行中而不在 #wrapper 上显式定义宽度?
    • 空白:#wrapper 上的 nowrap 在这里起作用。
  • 即使数据应垂直扩展其父 DIV,如何保持行高度一致?
    • 给定大致的字段长度,设置明确的高度对我来说是有用的。

原始 jsFiddle:http://jsfiddle.net/D6yXV/1/

更新修复:http://jsfiddle.net/D6yXV/7/

HTML:

<div id="hdr">
    <label>Header One</label>
    <label>Header Two</label>
    <label class="highlight">Header Three</label>
    <label>Header Four</label>
</div>

<div id="itm">
    <span>Some Data</span>
    <span>More Data</span>
    <span class="highlight">Even More Data</span>
    <span>No More Data</span>
</div>

<div id="itm">
    <span>Some Data</span>
    <span>More Data</span>
    <span class="highlight">Actually, this is a large field and could stretch the row out some.</span>
    <span>Even More Data</span>
</div>

<div id="itm">
    <span>Some Data</span>
    <span>More Data</span>
    <span class="highlight">Even More Data</span>
    <span>No More Data</span>
</div>

</div>

CSS:

#wrapper { overflow-x: auto; }
#hdr, #itm { display: inline-block; padding: 3px; width: 150px; }
#itm { border-left: solid 1px #000; }
#hdr label { font-weight: 700; display: block; }
#itm span { display: block; }
.highlight { background-color: #EEE; }

I'm trying to create a table layout with headers on the left and horizontally aligned fields. (See mock-up below.) I'm trying to accomplish this using a DataList -- stuck with .NET 2.0 -- and wrapped in a div with a scrollbar on the x-axis so that if enough groups are visible, a scroll bar will appear.

               Group One      Group Two      Group Three
Header One      Value          Value          Value
Header Two      Value          Value          Value
Header Three    Value          Value          Value

I'm struggling with two points, both seen in the below code and jsFiddle.

  • How do I keep the #itm blocks in a single line without explicitly defining a width on the #wrapper?
    • white-space: nowrap on #wrapper works here.
  • How do I keep a consistent height on rows, even if data should vertically expand its parent DIV?
    • Setting an explicit height will work for me, given an approximate field length.

Original jsFiddle: http://jsfiddle.net/D6yXV/1/

Updated with fixes: http://jsfiddle.net/D6yXV/7/

HTML:

<div id="hdr">
    <label>Header One</label>
    <label>Header Two</label>
    <label class="highlight">Header Three</label>
    <label>Header Four</label>
</div>

<div id="itm">
    <span>Some Data</span>
    <span>More Data</span>
    <span class="highlight">Even More Data</span>
    <span>No More Data</span>
</div>

<div id="itm">
    <span>Some Data</span>
    <span>More Data</span>
    <span class="highlight">Actually, this is a large field and could stretch the row out some.</span>
    <span>Even More Data</span>
</div>

<div id="itm">
    <span>Some Data</span>
    <span>More Data</span>
    <span class="highlight">Even More Data</span>
    <span>No More Data</span>
</div>

</div>

CSS:

#wrapper { overflow-x: auto; }
#hdr, #itm { display: inline-block; padding: 3px; width: 150px; }
#itm { border-left: solid 1px #000; }
#hdr label { font-weight: 700; display: block; }
#itm span { display: block; }
.highlight { background-color: #EEE; }

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

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

发布评论

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

评论(2

韶华倾负 2024-11-09 16:23:44

放置一个“float:left;”在物品上?并从 hdr 规则中删除 itm :)

更好的是,对表格数据使用表格(或中继器):)

Put a "float:left;" on the items? And remove itm from the hdr rule :)

Better yet, use a table (or Repeater) for tabular data :)

梦晓ヶ微光ヅ倾城 2024-11-09 16:23:44

说真的,你为什么不使用's?

Seriously why aren't you using <table>'s?

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