-1

I have a css style for html element, such as:

html {
  position: relative;
  height: 100%;
  min-height: 300px;
}

If it is style for body or any element within body, I can apply styling directly using style="..." parameter of such element.

But how can I apply style to html element directly (inline)?

Ωmega
  • 42,614
  • 34
  • 134
  • 203

2 Answers2

2

Simply do it the same as you described in the body example:

<html style="position: relative; height: 100%; min-height: 300px;">

But beware that inline styles are bad practice. Don't use them unless you have a really serious reason. Refer to this answer mentioned in the comments of this very question.

Community
  • 1
  • 1
matewka
  • 9,912
  • 2
  • 32
  • 43
  • Also, wouldn't the "position:relative" be irrelevant? The `` block is at the top level of the document; everything contained inside it /by default/ is relative to that space. – Jason M. Batchelor Dec 11 '13 at 15:01
  • @mori57 - To my surprise, it is not irrelevant - see http://stackoverflow.com/questions/20521309/resize-issue-with-table-centered-horizontally-and-vertically – Ωmega Dec 11 '13 at 15:04
  • 2
    I feel saying "inline styles are bad" is rather misleading. Although they are harder to maintain, they don't affect performance or cause other `bad` things to happen. It is more a matter of "practice" and "personal preference". Maybe a better way to phrase it is to say "inline styles are considered bad practice". Just a thought. – Dom Dec 11 '13 at 15:04
  • 1
    @ΩmegaΔ ... Interesting, I would have thought that the base element was indeed the relative container for all others in an HTML doc. Ah well, learn something new every day, right? Thx! – Jason M. Batchelor Dec 11 '13 at 15:13
0

That's not proper but you can do it with

<html style="background-color:red;">
JayD
  • 6,173
  • 4
  • 20
  • 24