Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Set div and child elements width by childs heading length

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #41046
    seanjacob
    Participant

    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 :(

    #115796
    Paulie_D
    Member

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

    #115800
    seanjacob
    Participant

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

    #115801
    Paulie_D
    Member

    >there must be a CSS way of doing this

    That’s what they all say.

    #115816
    Chris Coyier
    Keymaster

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

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

    #115822
    Paulie_D
    Member

    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)
  • The forum ‘CSS’ is closed to new topics and replies.