<div class="previewdiv">Test
<p style="clear:all"><img src="_webb/ragnhild/public_html/gallerypics/030610124034_01.jpg" width="296" height="200" align="left">Lorem
ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi
enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
dignissim qui blandit praesent luptatum zzril delenit augue duis dolore
te feugait nulla facilisi.</p>
</div>
där står det "Since a float is not in the flow, non-positioned block boxes created before and after the float box flow vertically as if the float didn't exist."
.clear {
clear: both;
font-size: 0px;
margin: 0px;
padding: 0px;
}
.content {
position: relative; /* Position is declared "relative" to gain control of stacking order (z-index). */
width: auto;
min-width: 220px;
margin: 0px 230px 20px 185px;
border-top:2px solid #C0C0C0;
border-left:0px solid #C0C0C0;
border-bottom:2px solid #C0C0C0;
border-right:0px solid #C0C0C0;
background-color: #FFFFC0;
color: #000000;
padding: 10px;
z-index: 3;} /* This allows the content to overlap the right menu in narrow windows in good browsers. */
/* I've heard this called the "be nice to Opera 5" rule. */
html>body #navAlfa {width: 128px;}
.content img {
position: relative;
border: 0;
float: left;
padding-right: 5px;
padding-bottom: 5px;
z-index:3;
}
Kan någon vara snäll och förklara för mig varför detta löses genom att man lägger till en tom div med clear:both efter.
Är detta ett hack? Finns det andra lösningar på detta problem?
What is the div class="spacer" in there for? When you float an element with CSS, it no longer takes up any "space" and any background and/or border will show up above the images instead of surrounding them. We need to add some content other than the floated DIVs into the container DIV to force the background or border to contain the floated elements as well. Add this to your style sheet to take care of that:
div.spacer {
clear: both;
}
.spacer i citatet motsvarar .clear i lösningen ovan ;)
Jag hade samma problem precis och letade därför upp den här tråden igen. Dock har den här lösningen (en tom div med clear:both) en jobbig sidoeffekt i Internet Explorer. Hack-diven skapar nämligen extra utrymme längst ner i den omgivande diven (se bild). Hur kommer man ifrån detta?
Nu har jag använt koden i mitt inlägg ovan, och det har fungerat alldeles utmärkt. Tills i dag när SBBK ringer och påpekar att texten på deras nyhetspuff inte syns förrän man markerar den (i Internet Explorer).
Web-Tor hjälpte mig fundera ut att boven var "clear:both" så nu undrar jag förstås hur man kommer runt detta. Tar jag bort "clear:both" tar bilden inte upp något utrymme och man är tillbaka till ursprungsproblemet.
Det står i artikeln att det inte riktigt funkar i Firefox, men detta fungerar alldeles utmärkt i de senaste buildsen. Sen själv punkten som han använder kan man köra utan, testade i Opera och NN7 och Firefox 0.8+