带有背景图像的 CSS Div - 如何允许页面上的 div 扩展?
我不确定如何表达这个主题的问题......抱歉。
我刚刚开始学习CSS。
我有一个带有背景图像的
,并且
中有文本。我读到,选择 em 字体大小是一个不错的选择,因为有些人可能需要在浏览器中使用更大的文本大小。因此使用 em 设置 font-size 可以更好地适应这些类型的用户。但允许调整文本大小的问题是,在许多情况下,我的
中的文本将超出背景图像的大小,并使页面看起来很糟糕并且设计不好。有没有办法使用CSS并允许背景图像'匹配'或'扩展'以适应更大的文本大小?
I wasn't sure how to word the question for this topic...sorry.
I'm just starting to learn CSS.
I have a <div>
with a background image and there is text within the <div>
. I read that choosing font sizes in em is a good choice because some people might require larger text sizes in their browsers. So setting the font-size with em would accommodate these types of users better.
But the problem with allowing the text to be resized, is that in many cases, the text within my <div>
is going to go beyond the size of the background image and make the page look terrible and poorly designed.
Is there a way to use CSS and allow the background image to 'match' or 'expand' to accommodate to larger text size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
div
的width
设置为img
width
,这样它就不会扩展得更宽(超出图像) )。当然,放大的文本会迫使
div
沿高度增长。您还可以将
background-img
设置为重复(如果图像允许),以便当文本展开时,图像会重复。You could set the
width
of thediv
to theimg
width
so that it never expands wider (beyond the image).Of course, the enlarged text would force the
div
to grow height-wise.You could also set the
background-img
to repeat (if the image allows for it), so that when the text expands, the image is repeated.由于您刚开始,您可能需要阅读 http://na.isobar.com/standards/# _pixels_vs_ems 其中他们说:
正确:
不正确:
Since you are starting out, you might want to read http://na.isobar.com/standards/#_pixels_vs_ems wherein they say:
Correct:
Incorrect: