Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

css - HTML - What is the <page> tag doing?

I've been playing with getting a HTML document to display in A4 size and using the code in this codepen works perfectly:

https://codepen.io/rafaelcastrocouto/pen/LFAes

CSS

body {
  background: rgb(204,204,204); 
}

page {
  background: white;
  display: block;
  margin: 0 auto;
  margin-bottom: 0.5cm;
  box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
  }

page[size="A4"] {  
  width: 21cm;
  height: 29.7cm;
} 

HTML

<page size="A4"></page>

However, I'm not sure how or why declaring page and page [size information] in CSS allows you to use the tag in HTML. In fact, I can find any reference to a HTML page tag anywhere.

Can someone please explain how the code is working in the codepen? Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I do not believe that <page> is an actual HTML element.

When the browser sees this, it probably thinks it is getting old and missing out on new inventions that didn't exist when the browser was released.

In that case it is treated like a <div>, and CSS rules still apply.

But really it's best to stick to elements that really exist, instead of pretending they will some day, because in the future the implementations of newly created tags could be different than you expect.

It would have been better to be written as <div class="page" data-size="A4"> with the CSS looking for div.page and div.page[data-size="A4"].


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...