search
HomeWeb Front-endHTML TutorialSummary of CSS DIV usage_html/css_WEB-ITnose

(original link:)


CCS = Cascading Style Sheets


Inline style sheet (not recommended):


Internal style sheet (not recommended):

p{color:#F00;}

……


External style sheet (usually under the title of the head):


CSS Writing structure:

{

; : ;

… …

}

For example:

p {

color: #F00;

font-size: 12px;

}


Basic type selector:

  • Tag selector: written inside tag, such as: p{}. Select all contents of this label. Support custom labels.
  • Class selector: starting with ".", such as: .30font{}, means selecting all elements with class "30font".
  • id selector: starts with "#".

  • Composite type selector:

  • Pseudo-class selector: separated by ":", For example, "a:link", "a:hover", "a:active" (mouse pressed), "a:visited" for ; or ".myClass:hover"
  • Group selector: separated by ",", select several elements at the same time, such as: "a, p, h3"
  • tag specifies the selector: such as p.aa means p with class="aa" Tag, p#aa represents the p tag with id="aa"
  • contains selectors: separated by spaces, indicating B inside A, such as "#top a" indicating < inside id="top" ;a> tag
  • sibling adjacent selectors: separated by " ", such as "h1 p" means

    tag

  • attribute selector adjacent to

    : Separated by "[]", such as "p[align]" means

    tags with align attribute

  • Wildcard selector: "*", means selecting all elements

  • Font and text properties:

  • font-family: font name
  • font-size: font Size needs to be in unit px
  • font-weight: bold. bold, bolder, lighter, 100, 200, ... 900 (meaning 100, 200...)
  • font-style: font style. normal, italic, oblique (also italic, only valid for some special fonts)
  • font-variant: Convert English letters to uppercase. normal: normal font, small-caps: small uppercase font
  • line-hight: line height
  • text-transform: capitalize: capitalize the first letter, uppercase: all capitals, lowercase: All lowercase, none: unchanged
  • text-decoration: text decoration. underline, overline, line-through, blink, none, there can be multiple, separated by spaces
  • color: color
  • text-indet: first line indent (requires unit)
  • text-align: text alignment, left, right, center, justify (justify both ends)
  • letter-spacing: word spacing (requires unit px)

  • Background attributes:

  • background-color: background color
  • background-image: background image (takes precedence over background color) )
  • background-repeat: Whether to tile the background image. repeat (default), no-repeat, repeat-x, repeat-y (horizontal and vertical tiles)
  • background-attachment: whether to follow the scroll bar movement. fixed: do not move, scroll: move (default)
  • background-position: background positioning, the relative displacement of the origin coordinates (x, y) of the upper left corner of the background image, or right, left, top, bottom, center
  • Background attributes can be written together. List the attribute values ​​and separate them with spaces, such as:

    body{

    background: #F00 url(images/bg.jpg) no- repeat fixed 50px 100px;

    }

    背景平铺:repeat-x 或 repeat-y,把图片按x轴或y轴(横向或竖向)平铺


    优先级排序:默认


    框模型(或盒模型):

  • 内联对象,按行显示:display:inline,由line-hight决定行高。如

    ,

  • 块对象,按块显示:display:block,由width和height决定宽和高,默认占一行。如

  • 内联对象转换为块对象后,就可以使用width和height属性了:a{display:block; width=10px; height:20px;}


  • padding:内填充(分top, bottom, left, right)
  • margin:外边距(分top, bottom, left, right)
  • border:边框(分top, bottom, left, right)
  • width:内容的宽度
  • height:内容的高度
  • 注:当两个元素上下排列时,他们间的margin会自动合并(都不是float或绝对定位的情况下)


    border的属性(分top, bottom, left, right):

  • style:线条样式(dotted, solid, double, 等)
  • width:粗细(单位px)
  • color:颜色
  • 可以缩写:border: solid 1px #FFF;

    单独设置一条边:

  • border-bottom: solid 2px #00F;
  • border-bottom-width: 2px;
  • (注:后面会覆盖前面的)


    margin和padding的设置:

  • margin: 1px (上下左右)
  • margin: 1px 2px 3px 4px; (上 右 下 左)
  • margin: 1px 2px; (上下 左右)
  • margin: 1px 2px 3px; (上 左右 下)
  • (注:padding的设置方法跟margin一样)


    浮动(float):

  • 浮动到普通流的上一层
  • float: left,浮动后向左,直到左边碰到边界或碰到同一层元素的右边界
  • float: right,浮动后向右,直到右边碰到边界或碰到同一层元素的左边界

  • 清理(clear):

  • 使浮动层继续在普通流保留占位
  • clear: both, left, right,应用于普通流,使普通流根据上一层的占位情况来决定自己的位置
  • 一般可以在浮动层和普通流直接加一个clear div来分隔排版,如:

    .clear{clear:both;}


    Center the block horizontally:

    1. margin left and right: auto (eg: margin:0px auto;)
    2. The block must have a specific width value (width)

    Note: The body has a margin of 8px by default. Cancel method: body{margin:0px;}

    Center the block vertically (less commonly used):

    1. width:500px; height:200px; position: absolute; top:50%; left:50%; margin-top:-100px; margin-left:-250px;

    Center text within the block:

    1. Center horizontally: text- align: center
    2. Vertically centered: line height = box height, such as: height:200px; line-height:200px (one line fills the entire div)


    ul list:

  • There is padding and margin by default. Cancel method: ul{padding:0px; margin:0px;}
  • list-style: List style (none, )
  • list-style-image:url(images/a.jpg);
  • Horizontal: li{float:left}
  • Set the dividing line: li{ background:url(images/1.png) no-repeat bottom center;}

  • Positioning (via position attribute):

  • static: Default positioning method, displayed by row or block.
  • relative: relative positioning, the element is offset by a certain distance (use top, right, bottom, left to position relative to the original position, the original space occupied will not be released)
  • absolute: element Removed completely from the document flow (similar to float) and positioned relative to its parent box (using top, right, bottom, left positioning). For example: #aaa{position:absolute; top:100px; left:50px;}
  • fixed: similar to absolute, except that the positioning is at a distance from the browser window. (Can be used to make floating ads)
  • Note: If they overlap, you can use the z-index attribute to determine who is on top, and the one with the larger value is on top.


    Size:

  • Fixed value: such as width: 100px;
  • missing Default value: leave it blank
  • Percent: the percentage of the parent box, such as width: 80%;
  • min-height, min-width: the minimum height and width of the element
  • max-height, max-width: the maximum height and width of the element

  • Handling when content exceeds the parent box:

  • overflow:hidden: The exceeded content is cut
  • overflow:scroll: The scroll bar is always displayed
  • overflow:auto: When the content is cut, Show scroll bars (the default value for body and textarea is auto)
  • overflow-x:hidden: Disable horizontal scroll bars
  • overflow-y:scroll: Always display vertical scroll bars
  • Note: If the parent box does not set height, the parent box will be raised until it reaches max-height.


    Browser scroll bar settings:

    For example: html{

    scrollbar-base-color:# F00;

    }

    Note: It seems to be only valid for IE.




    Photoshop cutting process:

    1. Use guides
    2. Use the slice tool
    3. Cancel the background and make the image transparent
    4. Save as web format...
    5. Save: slice : All user slices
    6. Save
    7. Rename

    Original article, please indicate the reprint from Clement-Xu’s csdn blog. )

    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

    The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

    The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

    The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

    HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

    The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

    The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

    The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

    HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

    The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

    HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

    HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

    HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

    HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

    From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

    HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    mPDF

    mPDF

    mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    DVWA

    DVWA

    Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    Powerful PHP integrated development environment