带有单元格背景文本的 HTML 表格
在每个单元格的背景中显示带有文本的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在内容跨度中使用相对定位:
在 CSS 中:
现在跨度重叠,内容超过天数。您可能想调整位置,但这应该可行。
尽管这可行,但我建议您使用图像。您可以将所有必需的日期嵌入到一个图像文件中(CSS 精灵技术),它可以让您更好地控制,减少特定于浏览器的问题。
Use relative positioning in the content span:
And in CSS:
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.
嗯...如果我理解正确的话,我在每个单元格中的做法可能类似于以下内容:
当然,您可以将样式移动到单独的 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:
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.
我知道您说过使用图像“恕我直言,不是一个选项”,但我可以建议使用图像会给您在日期的外观方面带来更多灵活性。您可以使用图像编辑器可用的任何字体,而不是浏览器中可以依赖的有限字体集。并且可以应用各种图像调整技巧,而这在浏览器中是不可能的。
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.