SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Scott Blanchard's Avatar
    Join Date
    Sep 2010
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to force this figcaption element to respect its parent's width boundaries.

    On this page > http://stones.clickbump.com/trent-re...-nails-lineup/

    The figcaption element (just below the Trent Reznor image within the main content block) breaks out of the figure container (due to its length). When the figcaption text is shorter, the figcaption element stays centered below the figure element as in this example (the Rhianna pic) > http://stones.clickbump.com/rihannas...e-cover-shoot/

    Any ideas how to get the figcaption to line up properly, regardless of how long it is?

    Ideally, I want it to begin text wrap when its length exceeds the width of its parent (the figure element). However, the figure element cannot have a defined width because the size of the featured image it contains is variable.

  2. #2
    SitePoint Addict Scott Blanchard's Avatar
    Join Date
    Sep 2010
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update: I was able to resolve the issue with:

    Code:
    figure{display:table}
    figcaption{display:table-caption;caption-side:bottom}
    The key rule here is "caption-side", which apparently defaults to top, counterintuitive as that may seem

  3. #3
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,338
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Hi Scott,

    Glad you found a solution but I thought it worth to also mention a very old table trick you can apply using css that will have the same effect.

    Code:
    .entry figure {
        display: table;
        width: 1px;
    }
    You set the display:table element to be 1px wide and as tables always stretch to hold their content the width of the table becomes the width of the largest non wrapping element in that section (your image). This means that all captions will also wrap within the bounds of the image.

    It's a technique used in tables of bygone days

  4. #4
    SitePoint Addict Scott Blanchard's Avatar
    Join Date
    Sep 2010
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Paul, I'm testing that out due to the fact that my solution is borked in IE8. However, its forcing the image to a smaller width than it should be (in Chrome and IE8 oddly enough).

    Unless you have some suggestions to tweak it, I'm going to revert to my code and handle the IE8 issue in isolation.

  5. #5
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,338
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Hi Scott,

    It seems to work in Chrome ok and this cut down version seems to be working.

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style type="text/css">
    .figureFeatured {
    	display:table;
    	width:1px;
    	text-align:center;
    }
    .figureFeatured img {
    	display:block;
    	float:none;
    }
    .figcaption {
    	display:table;
    	clear:both
    }
    </style>
    <!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    </head>
    
    <body>
    <div itemprop="articleBody" class="entry">
    		<figure  style="float:left" class="figureFeatured"><img width="200" height="300" style="margin:5px 15px 10px 0;" itemprop="image" alt="Trent Reznor attends the 83rd Annual Academy Awards in Hollywood" class="alignleft wp-post-image" src="http://stones.clickbump.com/wp-content/uploads/reznor-large-200x300.jpg"> <figcaption class="figcaption">Trent Reznor attends the 83rd Annual Academy Awards in Hollywood</span> </figcaption>
    		<p>Trent Reznor has stayed busy in the four years since Nine Inch Nails’ farewell tour. In November, Trent Reznor broke the news to Rolling Stone that the band is working on new material. “All signs point to yes,” he said. “There are some things in the works.”</p>
    		<p>Today on his website, Reznor confirmed he is rebuilding Nine Inch Nails with an almost entirely new lineup, including bassist Eric Avery (formerly of Jane’s Addiction), guitarist Adrian Belew (King Crimson), keyboardist Alessandro Cortini (NIN), keyboardist Josh Eustis (Puscifer, Telefon Tel Aviv) and drummer Ilan Rubin (NIN, Lostprophets).” “Nine Inch Nails are touring this year,” Reznor writes. “The first shows will begin this summer, followed by a full-on arena tour of the U.S. this fall and lots of other dates worldwide to follow through 2014.”</p>
    		<p>&nbsp;</p>
    		<p><strong>Video</strong>: <a href="http://www.rollingstone.com/music/news/video-trent-reznor-shares-footage-from-nine-inch-nails-final-tour-20110103">Trent Reznor Shares Footage From Nine Inch Nails’ Final Tour</a></p>
    		<p>Reznor revived the project while working with the King Crimson guitarist. “I was working with Adrian Belew on some musical ideas, which led to some discussion on performing, which led to some beard-scratching, which (many steps later) led to the decision to re-think the idea of what Nine Inch Nails could be, and the idea of playing a show. Calls were made to some friends, lots of new ideas were discussed, and a show was booked &ndash; which led to another, which somehow led to a lot of shows.”</p>
    		<p>Reznor has a full plate: his other band, How to Destroy Angels &ndash; his project with wife Mariqueen Maandig, Rob Sheridan and Atticus Ross &ndash; releases its new album March 5th and will tour in April.</p>
    		<p>Despite NIN’s “Wave Goodbye” tour, Reznor maintains the band never ended. “I never said that that wasn’t going to happen, just that it couldn’t go on as it was,” he told Rolling Stone. “Having a few years doing other things, I’ve enjoyed [them] and I’m enjoying doing How to Destroy Angels, and there will be a place for stuff that falls in the Nine Inch Nails column of things. It’s a different kind of work.”</p>
    </div>
    </body>
    </html>
    IE8 doesn't seem to like the figure element and if you change it to a div then it magically works. I'm still not sure about these html5 elements on older browsers as they always seem to throw something strange up.

    You could wrap the figure in a div and then it works in Ie8 (or change the figure to a div as mentioned above).

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <style type="text/css">
    .figwrap {
    	display:table;
    	width:1px;
    	text-align:center;
    	float:left;
    }
    .figureFeatured img {
    	display:block;
    	float:none;
    }
    </style>
    <!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    </head>
    
    <body>
    <div itemprop="articleBody" class="entry">
    		<div class="figwrap">
    				<figure  style="float:left" class="figureFeatured"><img width="200" height="300" style="margin:5px 15px 10px 0;" itemprop="image" alt="Trent Reznor attends the 83rd Annual Academy Awards in Hollywood" class="alignleft wp-post-image" src="http://stones.clickbump.com/wp-content/uploads/reznor-large-200x300.jpg"> <figcaption class="figcaption">Trent Reznor attends the 83rd Annual Academy Awards in Hollywood</figcaption> </figure>
    		</div>
    		<p>Trent Reznor has stayed busy in the four years since Nine Inch Nails’ farewell tour. In November, Trent Reznor broke the news to Rolling Stone that the band is working on new material. “All signs point to yes,” he said. “There are some things in the works.”</p>
    		<p>Today on his website, Reznor confirmed he is rebuilding Nine Inch Nails with an almost entirely new lineup, including bassist Eric Avery (formerly of Jane’s Addiction), guitarist Adrian Belew (King Crimson), keyboardist Alessandro Cortini (NIN), keyboardist Josh Eustis (Puscifer, Telefon Tel Aviv) and drummer Ilan Rubin (NIN, Lostprophets).” “Nine Inch Nails are touring this year,” Reznor writes. “The first shows will begin this summer, followed by a full-on arena tour of the U.S. this fall and lots of other dates worldwide to follow through 2014.”</p>
    		<p>&nbsp;</p>
    		<p><strong>Video</strong>: <a href="http://www.rollingstone.com/music/news/video-trent-reznor-shares-footage-from-nine-inch-nails-final-tour-20110103">Trent Reznor Shares Footage From Nine Inch Nails’ Final Tour</a></p>
    		<p>Reznor revived the project while working with the King Crimson guitarist. “I was working with Adrian Belew on some musical ideas, which led to some discussion on performing, which led to some beard-scratching, which (many steps later) led to the decision to re-think the idea of what Nine Inch Nails could be, and the idea of playing a show. Calls were made to some friends, lots of new ideas were discussed, and a show was booked &ndash; which led to another, which somehow led to a lot of shows.”</p>
    		<p>Reznor has a full plate: his other band, How to Destroy Angels &ndash; his project with wife Mariqueen Maandig, Rob Sheridan and Atticus Ross &ndash; releases its new album March 5th and will tour in April.</p>
    		<p>Despite NIN’s “Wave Goodbye” tour, Reznor maintains the band never ended. “I never said that that wasn’t going to happen, just that it couldn’t go on as it was,” he told Rolling Stone. “Having a few years doing other things, I’ve enjoyed [them] and I’m enjoying doing How to Destroy Angels, and there will be a place for stuff that falls in the Nine Inch Nails column of things. It’s a different kind of work.”</p>
    </div>
    </body>
    </html>

  6. #6
    SitePoint Addict Scott Blanchard's Avatar
    Join Date
    Sep 2010
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THanks Paul, I may just use jQuery to wrap it in a div on IE8 and below.


Bookmarks

Posting Permissions

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