DIV nicht anpassen Breite Inhalt in ein anderes DIV mit overflow: auto

Habe ich folgenden HTML-code:

<div class="main">
    <div class="container">
        <div class="contents">
            Some funny stuff in here
        </div>
    </div>
</div>

Mit den folgenden CSS:

.main {
    overflow: auto;
    width: 200px;
}
.container {
    border: 1px solid black;
}
.contents {
    width: 300px;
}

Dies ist, was diese Seite hat (siehe es an http://jsfiddle.net/C7RDh/7/):

  • main div ist 200px Breite mit overflow: auto (d.h. Schriftrollen Inhalt, wenn breiter als 200px).
  • So, als contents div-Element 300px breit, es scrollt horizontal.
  • So, würde ich erwarten, dass container div werden 300px (wie Elemente drin sind 300px breit), aber es ist nicht! Es ist 200px breit.

Wie kommt das? Ich möchte es so breit ist wie sein Inhalt (300px), wie kann ich das erreichen?

InformationsquelleAutor German Latorre | 2013-01-25

Schreibe einen Kommentar