Methods to Override width and top HTML attributes with CSS


One of many HTML components that incessantly comes into collision with CSS is the img factor. As we discovered in Request Metrics’ Fixing Cumulative Structure Shift Issues on DavidWalshBlog article, offering picture dimensions inside the picture tag will assist to enhance your web site’s rating. However in a world the place responsive design is king, we’d like CSS and HTML to work collectively.

Most responsive design fashion changes are finished through max-width values, however whenever you present a top worth to your picture, you may get a distorted picture. The objective ought to at all times be a show photographs in relative dimensions. So how can we make sure the top attribute does not battle with max-width values?

The reply is as straightforward as top: auto!

/* assuming any media question */
img {
  /* Make sure the picture does not go offscreen */
  max-width: 500px;
  /* Make sure the picture top is responsive no matter HTML attribute */
  top: auto;
}

The dance to please customers and search engines like google and yahoo is at all times a enjoyable steadiness. CSS and HTML have been by no means meant to battle however in some circumstances they do. Use this code to optimize for each customers and search engines like google and yahoo!

  • CSS @supports

    Characteristic detection through JavaScript is a shopper aspect finest observe and for all the fitting causes, however sadly that very same performance hasn’t been obtainable inside CSS.  What we find yourself doing is repeating the identical properties a number of occasions with every browser prefix.  Yuck.  One other factor we…

  • Being a Dev Dad

    I get requested a great deal of questions day-after-day however I am at all times shocked that they are not often questions on code and even tech — lots of the questions I get are extra about non-dev stuff like what my workplace is like, what software program I exploit, and oftentimes…


Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox