Home Backend Development PHP Tutorial Several details that need to be paid attention to when using div+css

Several details that need to be paid attention to when using div+css

Jul 18, 2017 pm 05:36 PM
css

  第一个注意点:选择器的使用(标签、class、id)

三种选择器中id(#)的优先级最高,根据id名筛选出唯一元素;

如下输入:#menu{ width:1200px; height:45px; background:#90F}

     

其次是class(.)的优先级较高,根据id名筛选出唯一元素;

如下输入:.text{ width:200px; height:45px; text-align:center; line-height:45px; vertical-align:middle}

     

标签优先级最差,根据标签名选中元素;

如下输入:div{text-align:center; vertical-align:middle; line-height:100px}

     

微软雅黑

  第二个注意点:外边距margin、内边距padding和流float的使用

外边距margin和内边距padding的使用是相对于边框的调整,四边框按上右下左顺时针调整;

特殊使用:外边距margin一般配合流float来使用,流float给操作的对象规定一个方向(left向左流、right向右流),被操作对象按此按此方向进行布局

如下(导航栏的制作):

    .text{ width:200px; height:45px; float:left; text-align:center; line-height:45px; vertical-align:middle}
    .text:hover{ background-color:#000; color:#F00; cursor:pointer}

  

另外,内边距padding:如果加了内边距,该元素会相应的变大,则需要在相应的高度属性中进行调整;

如下输入:

    

height:80px; background-color:#90C; float:left; padding:20px 0px 0px 0px">
(这里height由100px调整为80px,加padding效果)

  第三个注意点:分层z-index的使用条件

使用分层z-index时,要配合位置属性来调整;如果缺少属性位置的设置,则没有显示效果。

如下输入:

  


  



#1. Do not use images that are too small for background tiles.

This is why many people don’t use 1px, only then did I know. Tiling an image with a width and height of 1px to an area of ​​200px requires 200*200=40,000 times and takes up resources.

2. No borders.

The recommended writing method is border:none;, haha, I use this all the time. border:0; only defines the border width as zero, but the border style and color will still be parsed by the browser and occupy resources.

3. Use the * wildcard with caution.

The so-called wildcard is to initialize all tags in CSS, regardless of whether they are used or not, outdated or advanced, and treated equally. This consumes a lot of resources. There are optional initialization tags.

4. CSS hexadecimal color code abbreviation.

As I got used to abbreviations and lowercase letters, I realized that it was not the recommended way of writing, in order to reduce the resources occupied by parsing. But it will also increase the file size. Which one is better or worse needs to be carefully verified.

5. Put the style on the head and the script on the foot. Not embedded, only external links.

6. Never use CSS expressions.

7. Use to reference the style sheet instead of importing it through @import.

8. Generally speaking, PNG is smaller than GIF, much smaller. Then again, how much color is wasted in GIFs is well worth optimizing.

9. Never scale images in HTML. One does not look good, and the other takes up resources.

10. It is best to use even numbers for text fonts, 12px, 14px, 16px, the effect is very good. Special case, 15px.


The above is the detailed content of Several details that need to be paid attention to when using div+css. For more information, please follow other related articles on the PHP Chinese website!

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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

See all articles