简体   繁体   English

需要div扩展以包含甚至大于页面宽度的内容

[英]Require div to expand to contain content even larger than page width

I need to have a div stretch to contain the content when the content is larger than the div, even when the content stretches beyond the width of the html page. 当内容大于div时,即使内容超出html页面的宽度,我也需要进行div拉伸以包含内容。

Example HTML: HTML示例:

<body>
    <div id="outerDiv">
        <div id="innerDiv">asdfasdfkjasdflkjasldkfalsdkfjalsdkflaskdjfaslkdjfkalsjdhfkasjdhkljsdfashdjsdkjasfkjakfjhskdjfhakjdhkasjdhfsjdkashasjhkajsdkashkashfkajsdlfkjaskdjfhaksdjlaskjdkjdfhkasjdkajndckasjdbcjhsadcjkhasbdfhasbfjkasbdkjfnasdkcsdjfnaksjdfbaksdhfiweuhfjskdbfasjdfnasdfasdfasf
        </div>
    </div>
</body>

Example CSS: CSS示例:

#outerDiv
{
    background-color: red;
}

#innerDiv
{
    background-color: blue;
}

I have an example here: http://jsfiddle.net/978ew1jz/4/ 我在这里有一个例子: http : //jsfiddle.net/978ew1jz/4/

I want the blue div to stretch as long as the text does. 我希望蓝色div能够与文本一样长。

Edit: I also need the red div to still surround the blue div when the blue div stretches. 编辑:当蓝色div伸展时,我还需要红色div仍然围绕蓝色div。

Change your #outerDiv CSS to 将您的#outerDiv CSS更改为

#outerDiv
{
  background-color: red;
  display:inline-block;
  width: auto;
}

and it will stretch as per the content. 它将根据内容进行拉伸。

EDIT: 编辑:

Here is the Fiddle . 这是小提琴 Your red div will stretch with the blue div . 您的red div将与blue div一起延伸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM