


What's the Difference Between Width/Height in CSS and Width/Height HTML attributes?
Some HTML elements accept width and height as attributes. Some do not. For example:
<!-- valid, works, is a good idea --> <img style="max-width:90%" style="max-width:90%" src="What's%20the%20Difference%20Between%20Width/Height%20in%20CSS%20and%20Width/Height%20HTML%20attributes?" alt="What's the Difference Between Width/Height in CSS and Width/Height HTML attributes?"> <iframe width="600" height="400" src="What's%20the%20Difference%20Between%20Width/Height%20in%20CSS%20and%20Width/Height%20HTML%20attributes?"></iframe> <svg width="20" height="20"></svg> <!-- not valid, doesn't work, not a good idea --> <div width="40" height="40"></div> <span width="100" height="10"></span>
Those attributes are sometimes referred to as presentational attributes. The thing to know about them is that they are overridden by any other styling information whatsoever. That makes them ideal as a fallback.
So, if CSS loads and has a declaration like:
img { width: 400px; }
…that is going to override the width="500" on the tag above. Presentational attributes are the weakest kind of styling, so they are overridden by any CSS, even selectors with very low specificity.
What might be a smidge confusing is that presentational attributes seem like they would have high specificity. These inline styles, for instance, are very strong:
<img style="max-width:90%" src="What's%20the%20Difference%20Between%20Width/Height%20in%20CSS%20and%20Width/Height%20HTML%20attributes?" alt="What's the Difference Between Width/Height in CSS and Width/Height HTML attributes?">
Using an inline style (which works on any element, not a select few), we’ve moved from the weakest way to apply width and height to one of the strongest. Regular CSS will not override this, with a selector of any specificity strength. If we need to override them from CSS, we’ll need !important rules.
img { width: 400px !important; }
To reiterate, presentational attributes on elements that accept them (e.g. ,
But presentational attributes are also weak and are usually overridden in the CSS.
The above is the detailed content of What's the Difference Between Width/Height in CSS and Width/Height HTML attributes?. For more information, please follow other related articles on the PHP Chinese website!

Here's a container with some child elements:

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)