Grow your CSS skills. Land your dream job.

Set div and child elements width by childs heading length

  • # November 28, 2012 at 10:50 am

    So I want to set a div’s width by the length of the heading, w/o specifying any widths or using jQuery.

    Title here

    Long paragraph that needs to fit in the titles width. 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.

    I thought I had it! – [http://codepen.io/seanjacob/pen/xKfan](http://codepen.io/seanjacob/pen/xKfan “codepen”) but only works in FF :(

    # November 28, 2012 at 11:05 am

    Without JS I’m pretty sure it isn’t going to happen.

    # November 28, 2012 at 11:10 am

    Ouch, sad since I got so close, there must be a CSS way of doing this.

    # November 28, 2012 at 11:11 am

    >there must be a CSS way of doing this

    That’s what they all say.

    # November 28, 2012 at 12:10 pm

    If the h1 is floated it becomes only as wide as the text…

    http://codepen.io/chriscoyier/pen/6744cc65c7a38aa97b3f12a19c5e8442

    # November 28, 2012 at 12:29 pm

    True but that won’t set the width of the parent div or sibling paragraph will it?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".