Support Forum » CSS

crop image and display inline

(3 posts)

  1. gt2304b
    Member

    Hi all,

    so I need to crop an image that is 14x28 and display it inline (in the middle of a paragraph). So here's the dilemma: to 'crop' an image, you have to constrain the container around the image (either as an img tag or as a background image) which means that the container must be a block element. (only way to specify width and height). But again, I would like to display this image in the middle of the paragraph.. something like this:

    Doesn't this picture [14x14 cropped picture] look great?

    In the interest of accessibility and just good html/css practices, I need the picture to remain cropped at 14x14 in the event the font-size is increased or decreased by the user.

    The ONLY way I have been able to get the functionality that I want is to create a single cell table with display:inline that contains a div which crops my image. But this results in ugly, non-semantic markup: <table><tr><td><div></div></td></tr></table>

    I was able to get close to what I want by doing this:
    (html:)
    <span class=\\\"crop-icon\\\"></span>

    (css:)

    span.crop-icon {
      padding:0 14px 0 0;
      font-size:14px;
      background: transparent url(croppicture.gif) no-repeat top left scroll;
    }

    While this works in firefox, it doesn't work in IE7 -- not sure why... (In IE7, the background image is not displayed.. there is just an empty space where it should be. The really weird thing is that when I X-RAY the blank space, the whole (uncropped) image pops onto the screen and stays there until I do a refresh of the page.)

    can anyone help?!?

    Posted: 2 years #
  2. Cary
    Member

    I couldn't come up with any way of making this work in IE short of using a transparent gif with a background image. Also, this will still allow you to use alt text if you need it.

    <img class=\"cropicon\" src=\"blank.gif\" width=\"14\" height=\"14\" alt=\"\">

    img.cropicon {
    	background: url(croppicture.gif) no-repeat 0 0;
    }
    Posted: 2 years #
  3. gt2304b
    Member

    I guess the ONLY html element that can be displayed inline AND you can set the width and height is the img element... =(

    That is a nifty workaround with the transparent gif, but I guess this is one example of how CSS is still lacking in allowing you to separate content and presentation.

    Thanks for the reply.

    Posted: 2 years #

RSS feed for this topic

Reply

You must log in to post.

0.054 - 9 queries