The content of this article is to introduce how to make an invitation letter in HTML5? How to create an invitation (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Purpose: Making this simple invitation letter is just to let novices get started with web development.
Before making the page, let’s take a look at the overall appearance of the entire invitation.
1. First write the HTML code
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>邀请函</title> </head> <body> <div id="container"> <h1>hello world</h1> <p>欢迎来到虚拟世界,在这里发挥你的想象力,探索无限的可能。</p> <a href="#" id="button">点击进入</a> </div> </body> </html>
Instructions:
< !doctype html>: This is shaped like a declaration of a document.
tag: represents the beginning of html, represents the end of html.
Tag: It contains a description of various attributes and configuration information of the html5 page. Therefore, it can be regarded as an "identity card" to a certain extent.Tag: This represents a paragraph.
2. Beautify the page: CSS
1. Add a background image to the page:
html,body{ height: 100%; }body { background: url(images/1.jpg) center center; background-size: cover; }
We are adding a background image to the page When adding a background image, the background image we select may have relatively large pixels and may not fit in our browser window; so we center the background attribute of the body in both horizontal and vertical directions, because the browser does not have it by default. The height attribute is given to the body, so the height: 100% attribute must be set to the body and the body's parent (html). Set the attribute background-size: cover on the body to realize the background image adaptively filling the full screen.
2. Add font style to the web page
html,body{ height: 100%; font-family: sans-serif; color: #801449; }
font-family: The attribute can change the font.
color: You can change the color of the font. Since CSS has an inheritance mechanism, subsequent elements have this attribute.
3. Adjust the position of the invitation content area.
body { background: url(images/1.jpg) center center; background-size: cover; margin: 0; padding: 0; position: relative; }#container { width: 100%; text-align: center; position: absolute; top: 50%; transform: translateY(-50%); }
First of all, we use margin: 0;padding: 0; This is a very common practice, which can clarify some of the default margin values preset by the browser for page elements, making CSS independent control more precise.
Here we use the id selector (# id name), and we set its width to 100%; use text-ailgn:center to center its text horizontally.
So how to achieve vertical play? Positioning is used here: we need to control the top attribute of the container, which must be based on absolute positioning. To make the container absolutely positioned, its parent (body) must be set to relative positioning. Then we use the attribute to make the top 50% away from the top.
It’s not over yet, we can use the transform attribute of html5 to set translateY(-50%); that is, move it upward by half its height.
In this way, the entire container will be displayed in the center of the page.
4. Set some text fonts and sizes for its content labels.
h1 { font-size: 54px; text-transform: uppercase; margin-bottom: 20px; }p { font-size: 21px; margin-bottom: 40px; }a { font-size: 18px; color: #8f3c3c; }
Description:
font-size: Set the font size.
text-transform:uppercase: Convert text to uppercase letters.
margin-bottom:20px : This involves the box model, which means that the bottom border has a width of 20px.
5. Make an invitation button.
a { font-size: 18px; color: #8f3c3c; border: 1px solid #c66c6c; border-radius: 3px; padding: 10px 100px; text-decoration: none; }
border: Set the border for it. The three parameters of this attribute represent the border width of 1px, solid line, and color respectively.
border-radius: Sets a 3px rounded corner for its border.
padding: the top and bottom padding is 10px; the left and right padding is 100px.
text-decoration:none : This will remove the underline of the link.
Overall css file:
html,body{ height: 100%; font-family: sans-serif; color: #801449; } body { background: url(images/1.jpg) center center; background-size: cover; margin: 0; padding: 0; position: relative; } #container { width: 100%; text-align: center; position: absolute; top: 50%; transform: translateY(-50%); } h1 { font-size: 54px; text-transform: uppercase; margin-bottom: 20px; } p { font-size: 21px; margin-bottom: 40px; } a { font-size: 18px; color: #8f3c3c; border: 1px solid #c66c6c; border-radius: 3px; padding: 10px 100px; text-decoration: none; }
3. Create interaction for the page
var btn = document.getElementById('button'); btn.onclick = function(e) { //preventDefault() 可以阻止单机链接后浏览器默认的URL跳转。 e.preventDefault(); btn.innerHTML = "正在进入..." btn.style.border = "0"; }
First, we add the id as button to the link.
Use document.getElementById(id name) to get a link and assign it to the variable btn.
Then add the stand-alone attribute to btn and call the execution function.
e.preventDefault(); //将阻止其默认的链接跳转。 btn.innerHTML = "正在进入..." //改变文本内容。 btn.style.border = "0";
The above is the detailed content of How to create an invitation letter in html5? How to make an invitation letter (code example). For more information, please follow other related articles on the PHP Chinese website!