Overriding HTML img with CSS

13,422

You can use the !important override:

.productTable img {
  border: 0 none;
  width:192px !important;
  height:250px!important;
}

See http://jsfiddle.net/GDVXw/ for an example.

Just to illustrate, I've stretched the image a bunch here so you can see more clearly that the overrides works: http://jsfiddle.net/GDVXw/1/.

Share:
13,422
Admin
Author by

Admin

Updated on June 08, 2022

Comments

  • Admin
    Admin almost 2 years

    My jpeg is a pixelated obese shell of its former self... Is it possible to actually override html img height/width code with a css stylesheet instead of just streching an already adjusted image? The reason I ask is that a client has me working with godaddy's quick shopping cart (evil). The code it generates changes the size of the image in the html. Godaddy only allows css alterations, which is how I've managed to at least stretch the image back to original size. Unfortunately, it seems the html is applied to the image first despite the img css I've written, and then the css expands the image to nasty pixels. It's possible that, in addition to the height and width specifications in the html, godaddy has actually already converted the image to the smaller size on their server, though their techs deny this and the code would then be redundant. The CSS I'm using is pasted below, as is the unchangeable code that GoDaddy generates.

    //FROM CSS
    
    td.imageRow {
      padding: 10px 0 5px;
      vertical-align: middle;
      width:192px;
      height:250px;
    }
    
    .productTable img {
      border: 0 none;
      width:192px;
      height:250px;
    }
    
    .productTable a {
      width:192px;
      height:250px;
    }
    
    
    //FROM HTML
    <tbody>
    <tr><td class="imageRow"><a href="/Logo.htm">
        <img width="122" height="160" alt="Logo" src="/images/13129490572471789450105.jpeg">
        </a></td><td class="noBorder"></td><td class="noBorder"></td></tr>
        <tr><td class="titleRow"><a href="/Logo.htm">Logo</a></td><td></td><td></td></tr>
        <tr><td class="priceRow"></td><td></td><td></td></tr>
        <tr><td class="spacer">&nbsp;</td></tr>