带有单元格背景文本的 HTML 表格

发布于 2024-08-17 01:11:37 字数 174 浏览 3 评论 0原文

在每个单元格的背景中显示带有文本的 html 表格的最佳方法是什么?我正在制作日历,我希望在实际文本的背景中显示灰色日期。

此时我唯一能想到的是将日期和单元格内容放在单独的 div 中,这些 div 彼此浮动,但即便如此,在表格中也不能很好地实现。

顺便说一下,使用图像来显示日期并不是一个真正的选择。

What is the best way to go about displaying an html table with text in the background of each cell? I am making a calendar and I would like to have grey dates in the background of actual text.

The only thing I can think of at this point is to have the date and the cell content in separate divs that float over one another but even that isn't implementing well within a table.

By the way using an image to display the date is not really an option IMHO.

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

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

发布评论

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

评论(3

谎言 2024-08-24 01:11:37

在内容跨度中使用相对定位:

<tr>
    <td>
        <span class="day">6</span>
        <span class="contents">Contents go here</span>
    </td>
</tr>

在 CSS 中:

span.day {
    line-height: 20px; /* just to give it a height */
    display: block;
    color: #aaa;
}

span.contents {
    position: relative;
    top: -20px;
}

现在跨度重叠,内容超过天数。您可能想调整位置,但这应该可行。

尽管这可行,但我建议您使用图像。您可以将所有必需的日期嵌入到一个图像文件中(CSS 精灵技术),它可以让您更好地控制,减少特定于浏览器的问题。

Use relative positioning in the content span:

<tr>
    <td>
        <span class="day">6</span>
        <span class="contents">Contents go here</span>
    </td>
</tr>

And in CSS:

span.day {
    line-height: 20px; /* just to give it a height */
    display: block;
    color: #aaa;
}

span.contents {
    position: relative;
    top: -20px;
}

Now the spans are overlapping, with contents over day number. You might want to adjust the position but this should work.

Even though this would work, I would advise you to use images. You can embed all the required dates in one image file (the CSS sprite technique), it gives you greater control with less browser specific issues.

指尖微凉心微凉 2024-08-24 01:11:37

嗯...如果我理解正确的话,我在每个单元格中的做法可能类似于以下内容:

<div class="cell_container" style="position:relative;">
    <div class="cell_bg" style="position:absolute; width:100%; 
        height:100%; z-index:0; color: gray;">29/12/2009</div>
    <div class="cell_fg" style="position:absolute; width:100%; 
        height:100%; z-index:1;">Jim's birthday</div>
</div>

当然,您可以将样式移动到单独的 css 文件中。您也许还可以取消容器 div 并仅应用“position:relative;”包含单元格的样式。这种方法的主要缺点是,如果没有一些棘手的解决方法,您将失去在 IE 中垂直对齐的能力。

Hmm... if I understood correctly, the way I would do it is probably something like the following in each cell:

<div class="cell_container" style="position:relative;">
    <div class="cell_bg" style="position:absolute; width:100%; 
        height:100%; z-index:0; color: gray;">29/12/2009</div>
    <div class="cell_fg" style="position:absolute; width:100%; 
        height:100%; z-index:1;">Jim's birthday</div>
</div>

Naturally, you can move the styles into a seperate css file. You might also be able to do away with the container div and just apply the "position:relative;" style to the containing cell. The major downside to this method is that you will lose the ability to vertically align in IE, without some trickily implemented workaround.

浊酒尽余欢 2024-08-24 01:11:37

我知道您说过使用图像“恕我直言,不是一个选项”,但我可以建议使用图像会给您在日期的外观方面带来更多灵活性。您可以使用图像编辑器可用的任何字体,而不是浏览器中可以依赖的有限字体集。并且可以应用各种图像调整技巧,而这在浏览器中是不可能的。

I realize you said that using an image is "not an option IMHO", but may I suggest that using images would give you a lot more flexibility in the appearance of the date. You could use any font available to your image editor, rather than the limited set of fonts you can count on in a browser. And all sorts of image tweaking tricks could be aplied that would be immpossible in the browser.

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