Skip to main content
Inspiring
December 19, 2016
Answered

style vs. tag

  • December 19, 2016
  • 1 reply
  • 294 views

Why is it that on an img tag the float property only works if applied to the inline style tag of img... why does it not apply when added to the CSS rule in the external stylesheet?

Thank you.

    This topic has been closed for replies.
    Correct answer osgood_

    r_tist wrote:

    Why is it that on an img tag the float property only works if applied to the inline style tag of img... why does it not apply when added to the CSS rule in the external stylesheet?

    Thank you.

    Sometimes you might need to dig a bit deeper like:

    <div class="container"><img src="my_image.jpg" class="img_float_left"></div>

    Rather than:

    .img_float_left {

    float: left;

    }

    You may have to use

    .container .img_float_left {

    float: left;

    }

    or if youre completely stuck but I don't advice it give the img tag a unique id (if that doesnt kill it then you have something else going on in your code)

    <img src="my_image.jpg" id="img_float_left">

    #img_float_left {

    float: left;

    }

    1 reply

    osgood_Correct answer
    Legend
    December 19, 2016

    r_tist wrote:

    Why is it that on an img tag the float property only works if applied to the inline style tag of img... why does it not apply when added to the CSS rule in the external stylesheet?

    Thank you.

    Sometimes you might need to dig a bit deeper like:

    <div class="container"><img src="my_image.jpg" class="img_float_left"></div>

    Rather than:

    .img_float_left {

    float: left;

    }

    You may have to use

    .container .img_float_left {

    float: left;

    }

    or if youre completely stuck but I don't advice it give the img tag a unique id (if that doesnt kill it then you have something else going on in your code)

    <img src="my_image.jpg" id="img_float_left">

    #img_float_left {

    float: left;

    }