Difference between table width and style width [duplicate] - html

This question already has answers here:
What's the difference between HTML's and CSS's width attribute?
(7 answers)
Closed 5 years ago.
Is there a difference between
<table width="100%">
and
<table style="width: 100%">
I know that the img need
<img width="20px">
to precalculate the space it will use. But how is it with tables?

The first option is the old HTML strategy of setting properties of a table.
It is deprecated because of concerns about adding "visualization" properties to your HTML code, which should focus on content markup.
The second option is the (new) CSS solution but, please, do not declare it "inline" but in a separate CSS file targeting the table element with a class or ID name, otherwise advantages are effectively null; CSS philosophy is based on separation between data and styles, so if you declare it "inline"... there is implicitly no separation.

1st example is HTML width tag, which nowadays is basically used on newsletters.
2nd example is CSS inline, not a good approach, unless you want to override some class style and you don't want to add more classes.
3rd example is like 1st example, and not necessary needs the unit measure , take a look: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img

Related

Defining image proportions in HTML vs CSS [duplicate]

This question already has answers here:
Image width/height as an attribute or in CSS? [duplicate]
(12 answers)
Closed 4 years ago.
Fairly new at this, but what’s the benefit to defining image height/width in a linked Css over defining it inline attribute of the img tag? Everything I’m seeing points to defining the img size in Html as better since the browser will load the page faster with the proportions in mind without having to track them down elsewhere, but the whole point of separating the two is to keep things like sizes and colors outside the main html and clean up everything.
Thanks!
Using inline style is hardly ever a good approach.
Using classes allows other developers to modify your code much easier. Also managing properties via classes is a standard everyone uses. Nobody will look for them coded inline.
There are really many reasons why you should define your styles somewhere else than inline.
You should take a read here and search stackoverflow/google as this question has been asked many times before.
I would suggest:
1) Define the original size value in HTML om the img tag.
2) Add an "id" to your img tag in HTML
3) With the "id" tag, add it as reference in CSS and adjust the size based on %.
The benefit of doing it like this is that you will control the size from CSS but anyhow have a standard size defined in HTML.

Determining whether or not Width/Height goes inside a Style Tag, or whether you leave it by itself as an HTML Attribute inside HTML? [duplicate]

This question already has answers here:
Should I specify height and width attributes for my IMGs in HTML?
(5 answers)
Closed 5 years ago.
I'm not just referring to image's so it's not a duplicate.
It could be Inline JavaScript, Div tags, the list goes on.
Just cause I mentioned width/height, doesn't automatically mean images.
And I was primarily asking about 'HTML,' Not CSS*
Maybe I should've been more specific in asking my question.
This Is My Question:
What's the rule of thumb when determining whether or not Width/Height goes inside a Style Tag, or whether you leave it by itself as an HTML Attribute inside HTML.
Input Variable
<element width="100px" height="100px" />
Style Tag
<element style="width:100px; height:100px;" />
Best practice is to use css for styling because
After dynamic deployment of html, its little hesitating to access
attribute of html.
Sometimes as an Frontend developer you just have
access to static code and in this way it is easy to manipulate the
css code as compare to update html code
They have the same effect.
<element width="100px" height="100px" /> has been used for a long time, same with the widht/height properties of say.. an HTML table.
There is no difference whether you specify it on the element itself or within the CSS, though I now prefer using CSS so I can keep the HTML clear and concise.
There is absolutely NO difference.

Inline style vs "inline style" . What is the difference? [duplicate]

This question already has answers here:
What's the difference between the HTML width / height attribute and the CSS width / height property on the img element?
(8 answers)
Differences between assigning attribute, style, and class in div
(3 answers)
Closed 7 years ago.
What is the difference between height="50" VS style="height:50px" ?
And height="50" VS style="height:50"?
I am always confused by this.
Presentation-related attributes such as height="50" where the original way to specify presentation details of HTML elements.
However, they have since been deprecated in favour of CSS, via the style, class and id attributes, which give a lot more flexibility that the original attributes (at the very least because CSS can be extended without touching the definition of HTML itself, but of course also because you get the "cascading" part, as well as multiple units, media-queries, and much more).
You should thus generally avoid such attributes in HTML.
The only exception is HTML in e-mail, as many clients support those attributes but not the CSS versions.
Note that you should generally avoid style attributes as well, in favour of separate CSS, and class and/or id attributes. This allows you to completely separate the HTML and CSS, and makes it easier to change the presentation of your page without touching the HTML (or the code that generates it).
Also, in CSS (and thus in style attributes), you must specify units (except for 0), so height: 50 is not valid, you should use height: 50px (or another unit).
Using style attribute you add rich CSS to the element. Some styling can not be added using HTML attributes. For example <div style="background-color: #ff00ff; float: right"> is impossible with plain HTML attributes.

Class styles not being applied to <img>s [duplicate]

This question already has answers here:
Is there a reason why CSS doesn't support ids and classes, starting from numbers?
(8 answers)
Closed 7 years ago.
Here's a strange one. This seems pretty simple but just isn't working.
Fiddle
I have images within a container. Images with class="1" should take up the full width of the container div. Images with class="2" should be able to fit 2 images side by side, taking up the full width of the container div. Images with class="3" should be able to fit 3... you get the idea.
However, even though the classes are being applied (inspect the elements!), the styles are not. The only thing that seems to work is a general style for #container img, which Iyou can test in the fiddle by removing the ".1" or ".2" from either style. As soon as you add .1, the images no longer take on the style, even if they are class="1"!
All I can think tis that maybe tags don't support the class attr? But I don't think that's true.
CSS class selectors cannot start with a number.
Use an attribute selector or (more sensibly) better class names.
The problem is that
In CSS, identifiers [...] cannot start with a digit.
That means that class selectors can start with a digit, but you must escape it properly.
To escape a digit d, you can use \00003d or \3d  (note the whitespace).
For example,
.\31 {
background: #0f0;
}
<div class="1">Foo bar</div>

When functionalities of html attributes and css styles overlap

1) If inside CSS file we specify the following style:
td
{ text-align:center; }
While in a Html file we have
<td align=”right” … >
then value set in CSS file will take precedence over an inline html attribute and thus elements contained inside <td> cell will be aligned to the center.
a) Is same true for all html attributes? Meaning if a CSS rule and an html attribute functionalities overlap , will the CSS rule always take precedence?
BTW – I know we should usually prefer using CSS rules vs html attributes
thanx
Which set of definitions, HTML attributes or CSS properties, take precedence?
The textbook answer:
CSS properties take precedence over HTML attributes. If both are specified, HTML attributes will be displayed in browsers without CSS support but won't have any effect in browsers with CSS support.
(Reference: http://www.hwg.org/resources/faqs/cssFAQ.html)
The real-world answer:
It depends, if you want to be certain for a specific attribute or set of attributes, you will have to create a unit test and apply those tests to the specific browser(s) that you want to verify for compliance with the "textbook" answer, or compliance to your specification for the specific project you are working on.
You already imply that you know certain HTML attributes are deprecated, so I will not belabor that point here.