Streaming live at 10am (PST)

Parent width (as the child width)


#1

Hi everyone,

Is it possible to set the parent width to be the child width?
For example - set automatically the div’s width to the width of the image within the div.
Thanks!


#2

Hi. First. Div is block-level element:

A block-level element always starts on a new line and takes up the full width available (stretches out to the left and right as far as it can). w3schools

So in deafult the width of the parent is 100%. If you change this toinline-block or inline you get the effect you want.

An inline element does not start on a new line and only takes up as much width as necessary. w3schools

Or set width to the div and than give to the child 100% (same visual result):

This is in general. For images you find another tricks. See this Q:

Related Q:

For more specific Answer add link or code example.


#3

Thank you so much, you really helped me!


#4

This topic was automatically closed 125 days after the last reply. New replies are no longer allowed.