Solved

inline images in a DIV - how to stretch the border to their bottom?

Posted on 2004-08-25
13
701 Views
Last Modified: 2008-02-20
Hi,

I have a series of inline DIVs, inside each of which is an image (floated left or right) and text. The <img> tag is inside the <p>tag so as to be flush with the top of the first line of text. Each DIV has a CSS border. The problem is, the border (and indeed the DIV itself) only contains the text, so if the image is tall and the text short, the image 'breaks out' of the border and can even intrude onto the next DIV.

In short, the container is not containing the element contained therein. Frustrating!

Might the assembled luminaries have a fix for this?
0
Comment
Question by:Havin_it
  • 7
  • 4
  • 2
13 Comments
 
LVL 11

Expert Comment

by:neester
ID: 11891764
Please post the code because its hard to understand what you have.

Cheers :)
0
 
LVL 10

Author Comment

by:Havin_it
ID: 11891841
Ah. good point. Here ya go.

Example HTML:

<div class="boxBorder">
<p class="header">
<a href="http://www.witcherytours.com/witcherytours_Video1.html" target="_blank"><img class="imgLeft" src="images/royalmile.jpg" alt="Adam Lyal's Royal Mile video - Click to buy" border="0" /></a>
Adam Lyal's Royal Mile - Tales of Old Edinburgh</p>
<p class="smallBodyText">The distinctive character of Edinburgh's most historic
      thoroughfare is vivdly brought to life on this exciting and unusual video.
      Our guide through the closes and wynds of the mile is Adam Lyal (deceased),
      hanged
      in the Grassmarket in 1811. Adam is now the city's most famous and charismatic
ghost. <br />
He introduces us to the grandeur of the Royal Mile architecture,
      regales us with tales of execution, witchcraft, plague and torture. We meet
      intriguing
      characters from Edinburgh's colourful and eventful past - from John Knox
      to      the Foule Clenger. Adam also visits the famous tattoo at the castle and
      soaks      up the carnival atmosphere of the Edinburgh Festival.
      <br />
  This highly entertaining and informative video offers visitor and local alike
      a fascinating and unique view of one of the world's best-loved and most beautiful
      cities. Not to be missed!<br />
</p>
</div><br />

CSS classes:

.boxBorder {
      border-top-width: 1px;
      border-top-style: solid;
      border-top-color: #999999;
      border-right-color: #999999;
      border-bottom-color: #999999;
      border-left-color: #999999;
      border-bottom-width: 2px;
      border-bottom-style: groove;
      border-right-width: 2px;
      border-left-width: 1px;
      border-right-style: groove;
      border-left-style: solid;
      padding: 12px 8px;
      width: 95%;
}

.imgLeft {
      margin-right: 10px;
      float: left;

}

.header {
      font-family: Geneva, Arial, Helvetica, sans-serif;
      font-size: 14px;
      text-align: left;
      font-weight: bold;
      text-decoration: underline;
      margin-top: 0px;
      margin-left: 6px;
}
0
 
LVL 11

Expert Comment

by:neester
ID: 11892101
OK firstly a point about CSS.
You can use ShortHand to code the borders.

      
<deleted text from a mispost>
0
 
LVL 11

Expert Comment

by:neester
ID: 11892106
Sorry.
What the hell happened there?


It meant to read:

.boxBorder {
     border-top-width: 1px;
     border-top-style: solid;
     border-top-color: #999999;
     border-right-color: #999999;
     border-bottom-color: #999999;
     border-left-color: #999999;
     border-bottom-width: 2px;
     border-bottom-style: groove;
     border-right-width: 2px;
     border-left-width: 1px;
     border-right-style: groove;
     border-left-style: solid;
     padding: 12px 8px;
     width: 95%;
}

CAN BECOME:

.boxBorder {
     border-top: 1px solid #999;
     border-right: 2px groove #999;
     bordet-bottom: 2px groove #999;
     border-left: 1px solid #999;
     padding: 12px 8px;
     width: 95%;
}
0
 
LVL 11

Expert Comment

by:neester
ID: 11892149

.boxBorder {
     border-top: 1px solid #999;
     border-right: 2px groove #999;
     border-bottom: 2px groove #999; <<<< error on prev. post... now its fixed
     border-left: 1px solid #999;
     padding: 12px 8px;
     width: 95%;
}
0
 
LVL 11

Assisted Solution

by:neester
neester earned 75 total points
ID: 11892164
Here Simple fix:

this is the page i used to test with: ( I ADDED <div style="clear:both; height: 0px;"></div> to the code, after hte 1st <p>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
      <title>Nyt dokument</title>
<META NAME="generator" CONTENT="TSW WebPad">
<style>
.boxBorder {
     border-top: 1px solid #999;
     border-right: 2px groove #999;
     border-bottom: 2px groove #999;
     border-left: 1px solid #999;
     padding: 12px 8px;
     width: 95%;
}

.imgLeft {
     margin-right: 10px;
     float: left;

}

.header {
     font-family: Geneva, Arial, Helvetica, sans-serif;
     font-size: 14px;
     text-align: left;
     font-weight: bold;
     text-decoration: underline;
     margin-top: 0px;
     margin-left: 6px;
}
</style>
</head>

<body>

<div class="boxBorder">
<p class="header">
<a href="http://www.witcherytours.com/witcherytours_Video1.html" target="_blank"><img style="height: 200px;" class="imgLeft" src="http://www.witcherytours.com/images/royalmile.jpg" alt="Adam Lyal's Royal Mile video - Click to buy" border="0" /></a>
Adam Lyal's Royal Mile - Tales of Old Edinburgh</p>
<div style="clear:both; height: 0px;"></div>
<p class="smallBodyText">The distinctive character of Edinburgh's most historic
     thoroughfare is vivdly brought to life on this exciting and unusual video.
     Our guide through the closes and wynds of the mile is Adam Lyal (deceased),
     hanged
     in the Grassmarket in 1811. Adam is now the city's most famous and charismatic
ghost. <br />
He introduces us to the grandeur of the Royal Mile architecture,
     regales us with tales of execution, witchcraft, plague and torture. We meet
     intriguing
     characters from Edinburgh's colourful and eventful past - from John Knox
     to     the Foule Clenger. Adam also visits the famous tattoo at the castle and
     soaks     up the carnival atmosphere of the Edinburgh Festival.
     <br />
  This highly entertaining and informative video offers visitor and local alike
     a fascinating and unique view of one of the world's best-loved and most beautiful
     cities. Not to be missed!<br />
</p>
</div>


</body>
</html>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:neester
ID: 11892196
SORRY...
:)


REPLACE:
<div style="clear:both; height: 0px;"></div>
WITH
<br style="clear:both; height: 0px; display: inline; margin: 0; padding: 0;" />


I changed it to a DIV without testing :)
Didnt work the way i thought :)
enjoy that fix...
if it suits what you wanted.
I hope :)
0
 
LVL 10

Author Comment

by:Havin_it
ID: 11892211
Thanks, that's a valid observation but doesn't seem likely to solve my problem.
0
 
LVL 11

Expert Comment

by:neester
ID: 11892226
Adding <br style="clear:both; height: 0px; display: inline; margin: 0; padding: 0;" />
After the end of your first <p> didnt fix it?
0
 
LVL 10

Author Comment

by:Havin_it
ID: 11892289
Sorry, that was before your last posts. However inserting the <br> doesn't do it either - the next paragraph now aligns to the bottom of the image.
0
 
LVL 31

Accepted Solution

by:
seanpowell earned 50 total points
ID: 11892577
Hi Havin_it,

Have a read through this:
http://www.complexspiral.com/publications/containing-floats/

I don't want to post any more code yet becuase the thread is already becoming long...
0
 
LVL 10

Author Comment

by:Havin_it
ID: 11896033
Ah Mr Powell. A typically graceful response. In fairness it is the same one proposed by neester, but the background info allowed me to understand what was amiss.

@neester: your answer was correct for my needs, the problem was I didn't understand its functionality and placed it incorrectly (albeit via your guidelines). Placing the 'clearer' DIV below the remaining paras within the bordered DIV did the trick. You also rang my bell about my Dreamweaver bloat-code, so you get a slightly higher cut of the cake for sheer cheekiness ;)

Thanks all
0
 
LVL 31

Expert Comment

by:seanpowell
ID: 11896722
Thanks Havin_it :-)

(It's the old bit about the horse and drinking, just wanted to mkae sure you knew what was going on...)


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now