Solved

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

Posted on 2004-08-25
13
700 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
Comment Utility
Please post the code because its hard to understand what you have.

Cheers :)
0
 
LVL 10

Author Comment

by:Havin_it
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

.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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:neester
Comment Utility
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
Comment Utility
Thanks, that's a valid observation but doesn't seem likely to solve my problem.
0
 
LVL 11

Expert Comment

by:neester
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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... …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

771 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

9 Experts available now in Live!

Get 1:1 Help Now