Antworten auf deine Fragen:
Neues Thema erstellen

CSS - Float-Höhenproblem?

keul3

3dsMax | 3D-Contest

Hi,

sry erstmal für den etwas schwammigen Titel. Ich brauch etwas Nachhilfe in CSS, wahrscheinlich fehlt mir nur eine Property, leider weiß ich nicht welche. Und zwar folgendes: Ich haben einen Div-Container mit u.a. einem gefloateten Text mit prozentualer Breitenangabe. Das Problem ist, wenn der Text über die Höhe des anderen Contents im gleichen Container hinausgeht, so dass es zu Überschneidungen mit nachfolgenden Elementen kommt.

Beispiel: http://keul3.de/css_test.html (ggf. Browserfenster verkleinern, um zu sehn was ich meine)
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>TEST</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
* {
    margin: 0;
    padding: 0;
}


#image {
    width: 40%;
    position: relative;
    background-color:#990066;
}


.text {
    width: 40%;
    position: relative;
    text-align:justify;
    right: 10%;
    background-color:#999966;
    float: right;
}

.container {
    width: 40%;
    margin:auto;
    background-color:#CCCCCC;
    height:auto;
}

.standard {
    width: 40%;
    margin: auto;
    background-color:#FFFFCC;
}

</style>


</head>
<body>

<div class="container">
    <canvas id="image" width="400" height="400"></canvas>
    <p class="text">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her.Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One

</p>
</div>
           
<p class="standard">A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley ...</p>

   
<script>
    document.getElementById("image").getContext("2d").fillRect(0, 0, 400, 400);
</script> 
</body>
</html>

Wie erreiche ich es, dass die Div-Height dem Text entspricht?

mfg keule
 

Sargas

Mod | Forum

Teammitglied
PSD Beta Team
Floating nervt echt... Wenn du den Browsersupport nicht unbedingt brauchst arbeite dich lieber in display:flex ein. Ansonsten löst das hier dein Problem?

HTML:
<!DOCTYPE html>
<html lang="en">

<head>
    <title>TEST</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
        * {
            margin: 0;
            padding: 0;
        }
       
        #image {
            width: 40%;
            position: relative;
            background-color: #990066;
        }
       
        .clearfix::before,
        .clearfix::after {
            content: " ";
            display: table;
        }
       
        .clearfix::after {
            clear: both;
        }
       
        .clearfix {
            *zoom: 1;
            /* Für den IE6 und IE7 */
        }
       
        .text {
            width: 40%;
            position: relative;
            text-align: justify;
            right: 10%;
            background-color: #999966;
            float: right;
        }
       
        .container {
            width: 40%;
            margin: auto;
            background-color: #CCCCCC;
            height: auto;
        }
       
        .standard {
            width: 40%;
            margin: auto;
            background-color: #FFFFCC;
        }
    </style>


</head>

<body>

    <div class="container clearfix">
        <canvas id="image" width="400" height="400"></canvas>
        <p class="text">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then she continued her way. On her way she met a copy. The copy warned the Little Blind Text, that where it came from it would have been rewritten a thousand times and everything that was left from its origin would be the word "and" and the Little Blind Text should turn around and return to its own, safe country. But nothing the copy said could convince her and so it didn’t take long until a few insidious Copy Writers ambushed her, made her drunk with Longe and Parole and dragged her into their agency, where they abused her for their projects again and again. And if she hasn’t been rewritten, then they are still using her.Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One

        </p>
    </div>

    <p class="standard">A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley ...</p>


    <script>
        document.getElementById("image").getContext("2d").fillRect(0, 0, 400, 400);
    </script>
</body>

</html>
 

Myhar

Hat es drauf

Zusätzlich zu der schon vorgezeigten Lösung gibt es hier eine schnellere, welche in 99% der float-Probleme auch ausreicht.
Du brauchst bei deinem Beispiel dem .container nur overflow:auto zusätzlich geben (der Rest bleibt gleich), dann passt die Darstellung.
Wie gesagt, in jedem Fall kann man das nicht anwenden, manchmal entstehen hier ungewünschte Scrollbalken (aber die sind bei mir in den letzten Jahren auch nur 1-2 Mal wo aufgetreten und konnten beseitigt werden)
Aber ja, wer floatet muss auch clearen.
 
Bilder bitte hier hochladen und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Antworten auf deine Fragen:
Neues Thema erstellen

Willkommen auf PSD-Tutorials.de

In unseren Foren vernetzt du dich mit anderen Personen, um dich rund um die Themen Fotografie, Grafik, Gestaltung, Bildbearbeitung und 3D auszutauschen. Außerdem schalten wir für dich regelmäßig kostenlose Inhalte frei. Liebe Grüße senden dir die PSD-Gründer Stefan und Matthias Petri aus Waren an der Müritz. Hier erfährst du mehr über uns.

Stefan und Matthias Petri von PSD-Tutorials.de

Nächster neuer Gratisinhalt

03
Stunden
:
:
25
Minuten
:
:
19
Sekunden

Neueste Themen & Antworten

Flatrate für Tutorials, Assets, Vorlagen

Zurzeit aktive Besucher

Keine Mitglieder online.

Statistik des Forums

Themen
118.634
Beiträge
1.538.447
Mitglieder
67.555
Neuestes Mitglied
scheflo
Oben