search
HomeWeb Front-endHTML TutorialSummary of basic css styles for web front-end development

Use of colors and units

  1. Color
    • Use the name of the color to indicate the color, such as: red
    • Use hexadecimal to represent the demonstration, for example: #FF0000
    • Use rgb numerical values ​​to represent colors, rgb (red, green, blue), each value is between 0-255
      Generally, hexadecimal is used to represent colors
  2. Unit
    • px: Pixel, related to resolution setting.
    • % is relative to the percentage of the browser. You can set the width, but you cannot set the height.

Text style(text)

  1. color: Set text color
  2. text-align: Set text alignment
    • center
    • left
    • right
  3. letter-spacing: word spacing/letter spacing
  4. word-spacing: word spacing, set it if there are spaces, see spaces for Chinese.
  5. line-height: line height (line height of the second line = bottom of the first line to top of the third line)
  6. text-indent: usually 2 pieces at 30px
  7. text-decoration: text decoration
    • underline:underline
    • overline: overline
    • line-through: strikethrough
    • blink flash (can’t use it)
  8. text-transform: case conversion
    • uppercase: all capital letters
    • lowercase: all lowercase
    • capitalize: Each word starts with a capital
  9. text-shadow: Create text shadow (horizontal offset px, vertical offset px, blur level px, shadow color). The higher the blur level px value, the more blurry it is.
  10. Set font:
  • font-style: font style italic, oblique italic
  • font-size: Set the font size
  • font-weight: Set the thickness of the font, bolder is the thickest
  • font-family: Set text fonts, regular script, official script, etc.
  • Font abbreviation attribute: The order of style weight size family (space) must be in this format. Generally, after using the abbreviation attribute, put the letter-spacing after the font attribute, otherwise it will be overwritten.

Borders and Backgrounds

  1. Apply borders to elements
    • border-width: border width
    • border-style: border style
      none no border
      dashed dashed line
      solied solid line
      double double line
      groove groove line
      dotted dotted line border
      inset outset convex
      ridge ridge border
    • bolder-color: border color
    • Abbreviated form border:width style color in no order
  2. Set a certain border individually
    • border-top/bottom/left/right-width/style/color
    • Abbreviated form: border-top{width, style, color}
  3. Apply a rounded border (x radius, y radius, just write one when xy is the same)
    • border-top/bottom-left/right-radius
    • Abbreviation: border-radius
  4. Set element background
    • margin-right: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; list-style: disc;">background-image:{url("")} Background image address
    • background-repeat: Background image repetition method, generally no-repeat
    • background-size: background image size
    • background-position: background image position
    • Abbreviation: background:color image repeat position, if the size is not written, it will conflict
  5. Create box shadow
    • box-shadow: horizontal offset vertical offset blur value shadow extension radius shadow color 10px 10px 5px 0px red;
    • To add multiple shadows, just use a comma to write the second one after the first one. Set the first one to an integer and the second shadow to a negative number
  6. Set outline
    • The difference between borders and outlines: outlines do not belong to the page, and the layout of the page will not be adjusted due to the application of outlines
    • The border occupies the actual size, the outline does not
    • When hover is set, the outline-modified div will not be displaced, but the border-modified div will be displaced
    • outline-color: outline color
    • outline-style: outline style
    • outline-width: outline width
    • outline-offset: Offset of outline from element border
    • Abbreviation: outline

Other styles (table, list, transparency, cursor)

  1. Form
    • border-collapse adjacent cell border processing, merge table = collapse
    • border-spacing: spacing between adjacent cells
    • caption-side: title position
    • empty-cells: Whether empty cells are displayed
  2. List

    • list-style-style: The mark style at the front of the list, round dots, square dots, etc.
    • list-style-image: list image tag
    • Abbreviation: list-style:none cancels all attributes of the list, generally used for navigation
    • Horizontal navigation: li{display:inline}
  3. Transparency

    • opacity: Set transparency (value between 0-1)
  4. Cursor shape

    • cursor: Set the cursor shape. When the cursor is placed on a certain div, set the waiting state, hand shape, etc.

Box model

The box model is divided into elements, padding, borders, margins,

1. Set elements of a certain size

<span class="hljs-number">1). <span class="hljs-string">width:设置元素宽度
<span class="hljs-number">2). <span class="hljs-string">height:设置元素高度</span></span></span></span>

2.Set padding

  • padding-top/bottom/right/left
  • padding: abbreviation

3. Set the margin (the distance from the border to the edge of the browser or to the next box)

  • margin-top/bottom/left/right
  • margin: abbreviated form

4. Set the minimum and maximum sizes (when the width is set to a percentage, after expanding or shrinking the browser or changing to a large or small screen monitor, prevent elements from being misaligned or overflowing)

  • min-width: The minimum value is the sum of the widths of the two divs
  • max-width: maximum value

5. Handle element content overflow

  • overflow-x/y: x or y axis overflow
  • overflow: abbreviation: scroll sets the scroll bar (overflow processing method)

6.Change element type

1).Element types are divided into:

  • Inline elements: The width and height cannot be set on the page, nor will they occupy a row, b, span
  • inline-block Inline block-level element: It cannot occupy an exclusive line, but it can set the width and height of the .img element
  • block block-level element: occupies an exclusive line, and can set width, height, p, and div elements

2).Change element type display:

  • Element types can be converted to each other, and the properties of the elements will also change after conversion
  • divs are generally not converted into inline elements and will be lost, and cannot be set high

3). Hidden element: display:none

7. Floating and blocking elements from stacking

  • float:float:left/right
  • Eliminate elements stacked together: clear:both (eliminate both left and right)

8.Case:

Building Baidu page:

  • Tips: To center the div, directly use margin: 0 auto;
  • In order not to implement the browser default features initially: *{margin:0px; padding:0px}
  • In order to prevent the div block from overflowing, set the maximum and minimum values. The minimum value is the sum of the left and right divs
  • Center vertical text: line-height
  • For navigation, add the link a tag outside the li tag

Layout style

1. Positioning method position

  • static: By default, the elements are ordinary elements, and the document flow is positioned from top to bottom
  • relative: The position of the element is relative to the normal position. The position before the displacement cannot be used by other elements. Generally, no big changes are made. To fine-tune the position of an element, only top and left can be used. I feel like he moved relative to his previous position
  • fixed (fixed): positioned relative to the browser window, commonly used!!!, the position will not be occupied before displacement, and can be used up, down, left, and right, commonly used techniques for small advertisements, the scroll bar keeps moving, his The position will not change, it will break away from the document flow and float above the document flow. Its up, down, left and right positions are relative to the sides. For example: top50px does not move up 50px, but the distance between the element and the top border is 50px. You can also set button Use it, and the position will not change when you pull the scroll bar

  • Absolute (absolute): An ancestor element whose relative position value is not static. The stator element changes according to the ancestor element. The ancestor element cannot be static. Depending on who changes, who cannot be static (the default is static), occurs in parent-child or ancestor elements. Displacement positioning between descendant elements

    2. Positioning layout

    top/bottom/left/right

    3. z-index

    Used to set the display layer number of elements and elements, both positive and negative numbers are acceptable
    Must be used in conjunction with position

    Transition, transformation

    1. Transition

    Transition: an element gradually changes from one style to another
    Attribute:
  • transition-delay: Set the delay before transition
  • transition-duration: Set transition time
  • transition-property: Set the properties of transition participation
  • transition-timing-function: transition rate (linear uniform speed)
  • transition: short form (property duration timing-function delay)

    Reverse transition:

    Set in hover, paste it into the div, and it’s done

2. Transformation

      • transform: Specify how to transform
      • transform: scaleX/Y(1.5) scale 1.5 times
      • transform: rotate(360deg) rotates 360 degrees, deg represents the degree, and the effect is very good with the transition time
      • transform: skew(X-axis angle, Y-axis angle) tilt angle
      • transform: translate(X-axis distance, Y-axis distance) moving distance
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
What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

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.

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor