我有一个
HTML页面,为了这个问题看起来像这样:
<html> <head> <style> div { width: 100%; } .success { background-color: #ccffcc; } </style> </head> <body> <div class="success"> <nobr>This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line. This is a very long line.</nobr> </div> </body> </html>
注意“非常长的行”和该div的背景颜色.
我的问题(我认为这是一个基本的)是背景颜色在屏幕的边缘停止.当我向右滚动查看文本的其余部分时,其余的文本背景是白色的.
基本上我希望我的div行为如下:
>具有指定的背景颜色
>至少具有与屏幕相同的宽度,即使文本内部只是几个字
>按照文本的宽度,如果它大于屏幕的宽度
(可选)(我知道这真的是一个不同的后续问题),如果我有不止一个这样的div,首先,有没有办法让两个人自动跟随最宽的div的宽度?
有没有意义?
有没有办法做到这一点?
我已经在这里设置了一个测试页面,如果你在iPhone上查看,虽然是一个小字体,显示问题:http://www.vkarlsen.no/test/test.html
我看到以下问题列为SO的潜在重复/建议,以下是我在以下信息中注意到的内容:
> iPad background for div blocks not spanning entire width of screen
尝试建议的< Meta ... viewport ... />标签没有变化(现在在测试页面中).
> Background color stretches accross entire width of ul
< div> s已经是块元素
> WebKit doesn’t paint background-color for entire width of final inline list item
尝试设置div显示:inline-block;但这似乎并没有改变任何事情