Summary of basic css styles for web front-end development

WBOY
Release: 2016-08-04 08:53:21
Original
1203 people have browsed it

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

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

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
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!