The front end of basic HTML (1)

HTML Introduction

The nature of Web services 

Copy the code
import socket


sk = socket.socket()

sk.bind(("127.0.0.1", 8080))
sk.listen(5)


while True:
    conn, addr = sk.accept()
    data = conn.recv(8096)
    conn.send(b"HTTP/1.1 200 OK\r\n\r\n")
    conn.send(b"<h1>Hello world!</h1>")
    conn.close()
Copy the code

 

The requesting browser -> HTTP protocol -> server receives the request -> response returned from the server -> server the HTML file content to the browser -> browser rendering the page

What is HTML?

  • HTML (Hypertext Markup Language, HTML) is a markup language used to create web pages.
  • Rule browser is recognizable in nature, according to the rules we write the page, the browser rendering our website according to the rules. For different browsers may have different interpretations of the same label. (Compatibility issues)
  • Web page file name extension: .html or .htm

 

What HTML is not? 

HTML is a markup language (markup language), it is not a programming language.

HTML uses tags to describe web pages.

HTML document structure

The most basic HTML document:

Copy the code
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>css样式优先级</title>
</head>
<body>

</body>
</html>
Copy the code

 

  1. <! DOCTYPE html> declaration for the HTML5 document.
  2. <HTML> , </ HTML> is the start tag and end tag of the document. Is the root element HTML pages, among them the head of the document (head) and body (body).
  3. <head> , </ head> defines the beginning of the HTML document. Content between them does not appear in the document window browser. It contains documents yuan (meta) data.
  4. <title> , </ title> defines the page title is displayed in the browser title bar.
  5. <body> , </ body> text is visible between the body of the page content.

 

Note: For Chinese web pages need to use  <meta charset = "utf-8 ">  statement, otherwise it will be garbled. Some browsers set as the default encoding GBK, then you need to set  <meta charset = "gbk"> .

HTML formatting tags

  • HTML tags are keywords surrounded by angle brackets, such as <HTML> , <div> etc.
  • HTML tags are usually in pairs, such as: <div> and </ div> , a tag is first started, the second label end. Closing tag will slash.
  • There is a separate part of the label is also presented, for example: a , <HR /> , <IMG the src = "1.jpg" /> and the like.
  • Labels which can have a number of attributes, attributes may be without.

Tag syntax:

  • <Tag attribute name = 1 "attribute value 1" Attribute 2 = "attribute value 2" ......> content portion </ tag name>
  • <Tag attribute name = 1 "attribute value 1" Attribute 2 = "attribute value 2" ...... />

A few very important properties:

  • id: The unique ID defined tags, HTML document tree unique
  • class: defining one or more class name for the html element (classname) (CSS style class name)
  • style: the elements specified inline styles (CSS style)

HTML comments

<-! Footnotes ->

Note the code of the mother.

<! DOCTYPE> tag

<! DOCTYPE> declaration must be the first line of HTML documents located in <html> tag before.

<! DOCTYPE> declaration is not an HTML tag; it is an indication about which web browser HTML version of the page using the instructions written.

Common HTML tags

The head commonly used tags

label significance
<title></title> Define the page title
<style></style> Internal style sheet definitions
<script></script> Code or custom JS JS file import external
<link/> The introduction of an external style sheet file or a Web site icon
<meta/> The definition of the original web page information

 

Meta Tags

Meta tags Description:

  • <meta> element provides meta-information about the page (mata-information), for the search engines and the frequency of updating the description and keywords.
  • <meta> tag at the head of the document does not contain any content.
  • <meta> The information provided is invisible to the user.

Consisting of meta tags: meta tag has two attributes, they are http-equiv and name attributes, different attributes have different parameter values, these different parameter values ​​to achieve a different page functions. 

1.http-equiv attribute: http equivalent to the role of head of the file, it can be returned to the browser some useful information to help correctly display Web content, the corresponding attribute value content, the content is actually the content of each variable parameter.

<-! Encoding type specified document (need to know) -> 
< Meta HTTP-equiv = "Content-Type" charset = UTF8 " >   
<! - 2 seconds after the jump to the corresponding website, pay attention to the quotation marks (Learn ) -> 
< Meta HTTP-equiv = "Refresh" Content = "2; the URL of = HTTPS: //www.oldboyedu.com" > 
<-! tell IE to render the document in the most advanced mode (understand) -> 
< Meta HTTP-equiv = "X-UA-compatible" Content = "IEs = Edge" >

2.name properties: mainly used to describe a web page, the corresponding content attribute values, the contents of the main content is to facilitate the search engine robots to find information and the classification information.

< Meta name = "keywords" Content = "Meta summary, html meta, meta attributes, meta jump" > 
< Meta name = "the Description" Content = "Python Education College Old Boys" >

Within the body commonly used tags

Basic tag (block-level tags and labels inline)

Copy the code
<b> bold </ B> 
<I> italics </ I>
<U> underline </ U>
<S> Delete </ S>

<P> paragraph tag </ P>

<h1 of> Title 1 </ h1 >
<H2> title 2 </ H2>
<H3> title. 3 </ H3>
<H4> title. 4 </ H4>
<H5> title. 5 </ H5>
<H6> title. 6 </ H6>

<! - wrap ->
<br>

<-! horizontal line -> <hr>
Copy the code

Special characters

content Code corresponding
Blank &nbsp;
> &gt;
< &lt;
& &amp;
¥ &yen;
版权 &copy;
注册 &reg;

 

div标签和span标签

div标签用来定义一个块级元素,并无实际的意义。主要通过CSS样式为其赋予不同的表现。
span标签用来定义内联(行内)元素,并无实际的意义。主要通过CSS样式为其赋予不同的表现。

块级元素与行内元素的区别:
所谓块元素,是以另起一行开始渲染的元素,行内元素则不需另起一行。如果单独在网页中插入这两个元素,不会对页面产生任何的影响。
这两个元素是专门为定义CSS样式而生的。

注意:

关于标签嵌套:通常块级元素可以包含内联元素或某些块级元素,但内联元素不能包含块级元素,它只能包含其它内联元素。

p标签不能包含块级标签,p标签也不能包含p标签。

img标签

<img src="图片的路径" alt="图片未加载成功时的提示" title="鼠标悬浮时提示信息" width="宽" height="高(宽高两个属性只用一个会自动等比缩放)">

 

a标签

超链接标签

所谓的超链接是指从一个网页指向一个目标的连接关系,这个目标可以是另一个网页,也可以是相同网页上的不同位置,还可以是一个图片,一个电子邮件地址,一个文件,甚至是一个应用程序。

什么是URL?
URL是统一资源定位器(Uniform Resource Locator)的缩写,也被称为网页地址,是因特网上标准的资源的地址。
URL举例
http://www.sohu.com/stu/intro.html
http://222.172.123.33/stu/intro.html

URL地址由4部分组成
第1部分:为协议:http://、ftp://等 
第2部分:为站点地址:可以是域名或IP地址
第3部分:为页面在站点中的目录:stu
第4部分:为页面名称,例如 index.html
各部分之间用“/”符号隔开。
URL
<a href="http://www.oldboyedu.com" target="_blank" >点我</a>

href属性指定目标网页地址。该地址可以有几种类型:

  • 绝对URL - 指向另一个站点(比如 href="http://www.jd.com)
  • 相对URL - 指当前站点中确切的路径(href="index.htm")
  • 锚URL - 指向页面中的锚(href="#top")

 

target:

  • _blank表示在新标签页中打开目标网页
  • _self表示在当前标签页中打开目标网页

列表

1.无序列表

<ul type="disc">
  <li>第一项</li>
  <li>第二项</li>
</ul>

type属性:

  • disc(实心圆点,默认值)
  • circle(空心圆圈)
  • square(实心方块)
  • none(无样式)

2.有序列表

<ol type="1" start="2">
  <li>第一项</li>
  <li>第二项</li>
</ol>

type属性:

  • 1 数字列表,默认值
  • A 大写字母
  • a 小写字母
  • Ⅰ大写罗马
  • ⅰ小写罗马

3.标题列表

Copy the code
<dl>
  <dt>标题1</dt>
  <dd>内容1</dd>
  <dt>标题2</dt>
  <dd>内容1</dd>
  <dd>内容2</dd>
</dl>
Copy the code

表格

表格是一个二维数据空间,一个表格由若干行组成,一个行又有若干单元格组成,单元格里可以包含文字、列表、图案、表单、数字符号、预置文本和其它的表格等内容。
表格最重要的目的是显示表格类数据。表格类数据是指最适合组织为表格格式(即按行和列组织)的数据。
表格的基本结构:

Copy the code
<table>
  <thead>
  <tr>
    <th>序号</th>
    <th>姓名</th>
    <th>爱好</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>1</td>
    <td>Egon</td>
    <td>杠娘</td>
  </tr>
  <tr>
    <td>2</td>
    <td>Yuan</td>
    <td>日天</td>
  </tr>
  </tbody>
</table>
Copy the code

属性:

  • border: 表格边框.
  • cellpadding: 内边距
  • cellspacing: 外边距.
  • width: 像素 百分比.(最好通过css来设置长宽)
  • rowspan: 单元格竖跨多少行
  • colspan: 单元格横跨多少列(即合并单元格)

form

功能:

表单用于向服务器传输数据,从而实现用户与Web服务器的交互

表单能够包含input系列标签,比如文本字段、复选框、单选框、提交按钮等等。

表单还可以包含textarea、select、fieldset和 label标签。

表单属性

 

属性 描述
accept-charset 规定在被提交表单中使用的字符集(默认:页面字符集)。
action 规定向何处提交表单的地址(URL)(提交页面)。
autocomplete 规定浏览器应该自动完成表单(默认:开启)。
enctype 规定被提交数据的编码(默认:url-encoded)。
method 规定在提交表单时所用的 HTTP 方法(默认:GET)。
name 规定识别表单的名称(对于 DOM 使用:document.forms.name)。
novalidate 规定浏览器不验证表单。
target 规定 action 属性中地址的目标(默认:_self)。

 

表单元素

基本概念:
HTML表单是HTML元素中较为复杂的部分,表单往往和脚本、动态页面、数据处理等功能相结合,因此它是制作动态网站很重要的内容。
表单一般用来收集用户的输入信息
表单工作原理:
访问者在浏览有表单的网页时,可填写必需的信息,然后按某个按钮提交。这些信息通过Internet传送到服务器上。
服务器上专门的程序对这些数据进行处理,如果有错误会返回错误信息,并要求纠正错误。当数据完整无误后,服务器反馈一个输入完成的信息。

from django.conf.urls import url
from django.shortcuts import HttpResponse


def upload(request):
    print("request.GET:", request.GET)
    print("request.POST:", request.POST)

    if request.FILES:
        filename = request.FILES["file"].name
        with open(filename, 'wb') as f:
            for chunk in request.FILES['file'].chunks():
                f.write(chunk)
            return HttpResponse('上传成功')
    return HttpResponse("收到了!")

urlpatterns = [
    url(r'^upload/', upload),
]
Django接收上传文件代码

 

input

<input> 元素会根据不同的 type 属性,变化为多种形态。

type属性值 表现形式 对应代码
text 单行输入文本 <input type=text" />
password 密码输入框 <input type="password"  />
date 日期输入框 <input type="date" />
checkbox 复选框 <input type="checkbox" checked="checked"  />
radio 单选框 <input type="radio"  />
submit 提交按钮 <input type="submit" value="提交" />
reset 重置按钮 <input type="reset" value="重置"  />
button 普通按钮 <input type="button" value="普通按钮"  />
hidden 隐藏输入框 <input type="hidden"  />
file 文本选择框 <input type="file"  />

 属性说明:

  • name:表单提交时的“键”,注意和id的区别
  • value:表单提交时对应项的值
    • type="button", "reset", "submit"时,为按钮上显示的文本年内容
    • type="text","password","hidden"时,为输入框的初始值
    • type="checkbox", "radio", "file",为输入相关联的值
  • checked:radio和checkbox默认被选中的项
  • readonly:text和password设置只读
  • disabled:所有input均适用

select标签

Copy the code
<form action="" method="post">
  <select name="city" id="city">
    <option value="1">北京</option>
    <option selected="selected" value="2">上海</option>
    <option value="3">广州</option>
    <option value="4">深圳</option>
  </select>
</form>
Copy the code

属性说明:

  • multiple:布尔属性,设置后为多选,否则默认单选
  • disabled:禁用
  • selected:默认选中该项
  • value:定义提交时的选项值

label标签

定义:<label> 标签为 input 元素定义标注(标记)。
说明:

  1. label 元素不会向用户呈现任何特殊效果。
  2. <label> 标签的 for 属性值应当与相关元素的 id 属性值相同。
<form action="">
  <label for="username">用户名</label>
  <input type="text" id="username" name="username">
</form>

textarea多行文本

<textarea name="memo" id="memo" cols="30" rows="10">
  默认内容
</textarea>

Property Description:

  • name: Name
  • rows: the number of lines
  • cols: number of columns
  • disabled: Disable

 

Guess you like

Origin www.cnblogs.com/mofujin/p/10977342.html