Results 1 to 2 of 2

Thread: CSS: div / image / text width

  1. #1
    jorgensen Guest

    CSS: div / image / text width

    Hi there.....

    First post :-)

    I have read that it is oldtime to use tables as the main layout construction, therefore I give CSS / divs a go.

    Things are going quite well, but I have this problem:

    My site loads some pictures, of various sizes. They are placed inside a <div> with a 10 px border. Inside the <div> under the image, I have some text describing the image.

    What I would like, is to get the width of the text to be the same as the image, but I can't figure out how ? I can set a fixed width for the text, but then it don't fits the image.

    Does anyone have a tip to achieve this ?

    Thanks

    example:

  2. #2
    Join Date
    May 2009
    Posts
    130
    Well, you could probably put your text in a div, and then give it a fixed width.

    Like so:

    Code:
    #main_contianer{
    position:relative;
    width:600px;
    border:10px solid #ffffff;
    }
    #pic1{
    position:relative;
    width:200px;
    height:200px;
    }
    .text{
    position:relative;
    width:200px;
    }
    Code:
    <div id="main_container">
      <img src="images/mypic.png" alt="A Lovely Picture" id="pic1" />
      <div class="text">
        Some text here.
      </div>
    </div>
    Then I guess you could just play around with the positioning and margins.

    Let me know if this works for you.

Similar Threads

  1. Image Swap on text link
    By bkirish in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 09 Apr 2010, 03:42 PM
  2. css background image alignment only works for IE
    By pokinski in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 06 Feb 2007, 08:24 AM
  3. CSS- relationship between image position and div elements?
    By web88js in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 23 Nov 2006, 01:41 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •