Table of Contents
The latest research example code of ultra-practical css3 simulation border for H5 mobile terminal
Preface
Previous article review
html code
CSS code
Summary
Home Web Front-end H5 Tutorial H5 mobile terminal super practical css3 simulated border latest research sample code

H5 mobile terminal super practical css3 simulated border latest research sample code

Mar 10, 2017 pm 04:54 PM

The latest research example code of ultra-practical css3 simulation border for H5 mobile terminal

Preface

In a previous blog post "Mobile In "Summary of some basic knowledge points of terminal H5 in Section 5: Border Processing", I mentioned that you can use box-shadow:0 0 0 1px #ddd; to simulate borders. Of course, The content in the blog post is not wrong, but it has certain limitations. Therefore, today I am here to correct and improve the flaws in my previous blog post.

Why should I simulate the border instead of directly Write border?
Because the border needs to calculate the box model. And we may use adaptive layout on the mobile terminal. It is very laborious to calculate the border.
Therefore, by using the method of simulating borders, you do not need to consider the width of the border, which is more convenient.
Of course, using attributes like box-sizing:border-box can also exclude the border from being calculated in the box model.
And this method is used in many modern CSS frameworks.
But I personally do not recommend this approach. Because this way padding is not included in the box model.
Anyway, I don’t like this approach. So I simulated the border!

Previous article review

If you don’t want to open the link above, read what is said in the previous blog post What. Here I will summarize the two key simulation methods. If you don’t understand, you can read it. If you understand, just read the following content.

Method 1outline Simulate the border

Use outline: 1px solid #ddd; This stroke method simulates the border

Advantages:
1. You can use various line shapes like border
2. You can adjust the distance from the border to the boxoutline-offset Parameters

Disadvantages:
1. It cannot be made to fit rounded elements (this is considered a BUG by W3C and may be fixed in the near future)
2. It can only be added to the four sides at once, not just Add a side.

Method 2box-shadow Simulate border

Usebox-shadow:0 0 0 1px #ddd; Outer glow simulation border

Advantages:
1. Can fit rounded corner elements to generate perfect borders
2. Can repeat parameters to generate multiple borders

Disadvantages:
1. Only solid lines are linear, not dashed lines

For more information, please see my previous blog post, or Baidu related information.

box-shadow Can simulate a border on any side

I originally thought it was impossible. It can be seen that my CSS skills are not strong enough, and I have to study hard.

Last time I had nothing to do, I wrote a set of alphanumeric tables using a p to view the DEMO. Although I used relevant knowledge points, I still did not rely on the idea of ​​​​simulating borders.

Thinking about it carefully today, it turns out that box-shadow can simulate any of the four sides. Therefore, I wrote this blog post.

There are too many languages, it is better to be direct Look at the code:

html code

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Document</title></head><body>
    <p class="box sibian"></p>
    <p class="box shangbian"></p>
    <p class="box xibian"></p>
    <p class="box zuobian"></p>
    <p class="box youbian"></p>
    <p class="box zuoshangbian"></p>
    <p class="box youshangbian"></p>
    <p class="box zuoxiabian"></p>
    <p class="box youxiabian"></p>
    <p class="box wushangbian"></p>
    <p class="box wuyoubian"></p>
    <p class="box wuxiabian"></p>
    <p class="box wuzuobian"></p></body></html>
Copy after login

CSS code

.box {width: 100px;
height: 100px;background: #f00; 
margin: 50px;float: left;}
.sibian {box-shadow: 0 0 0 5px #000;}
.shangbian {box-shadow: 0 -5px #000;}
.xibian {box-shadow: 0 5px #000;}
.zuobian {box-shadow: -5px 0 #000;}
.youbian {box-shadow: 5px 0 #000;}
.zuoshangbian {box-shadow: -5px -5px #000,-5px 0 #000,0 -5px #000;}
.youshangbian {box-shadow: 5px -5px #000,5px 0 #000,0 -5px #000;}
.zuoxiabian {box-shadow: -5px 5px #000,-5px 0 #000,0 5px #000;}
.youxiabian {box-shadow: 5px 5px #000,5px 0 #000,0 5px #000;}
.wushangbian {box-shadow: 5px 5px #000,5px 0 #000,0 5px #000,-5px 5px #000,-5px 0 #000;}
.wuyoubian {box-shadow: -5px -5px #000,-5px 0 #000,0 -5px #000,-5px 5px #000,0 5px #000;}
.wuxiabian {box-shadow: -5px -5px #000,-5px 0 #000,0 -5px #000,5px -5px #000,5px 0 #000;}
.wuzuobian {box-shadow: 5px -5px #000,5px 0 #000,0 -5px #000,5px 5px #000,0 5px #000;}
Copy after login

View box-shadow simulated border DEMO

Summary

  1. Using the box-shadow attribute, it can be repeated indefinitely and can be continuously filled to meet our needs.

  2. Also, box-shadow You can set only two values, so there is no expansion, no blur, and one-to-one movement.

  3. box The disadvantage of -shadow still exists, that is, it can only simulate solid lines, but not dotted lines.

  4. In the use of rounded corners, better calculations are needed. Anyway, multiple coverage is used Features

  5. It is the easiest to create a 1px border.

The above is the detailed content of H5 mobile terminal super practical css3 simulated border latest research sample code. 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)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

See all articles