Home Web Front-end CSS Tutorial Some tips on creating border effects with CSS

Some tips on creating border effects with CSS

Jun 26, 2018 am 11:30 AM
background frame

边框在Web页面的内容块中非常常用,这里为大家整理了CSS制作边框效果的技巧总结,尤其是第三种方案的background-origin利用十分讨巧,需要的朋友可以参考下

比如这里最终需求如下:

2016526115057189.png (330×250)

html代码:

<ul class="demo">  
    <li>Lady gaga</li>  
    <li>Mariah Carey</li>  
    <li>Adele</li>  
    <li>Avril Lavigne</li>  
    <li>Sarah Brightman</li>  
    <li>Celine Dion</li>  
</ul>
Copy after login

方案一:

使用伪元素制作一个变宽,并定位在底部。

CSS代码:

.demo li {   
    padding-left: 15px;   
    line-height: 40px;   
}   
.demo li::after {   
    position: absolute;   
    rightright: 0;   
    bottombottom: 0;   
    left: 0;   
    border-bottom: 1px solid #ccc;   
    content: "\0020";   
}   
.demo li:not(:last-child)::after {   
    left: 15px;   
}   
.demo li:hover {   
    background-color: #f3f3f3;   
}
Copy after login

方案二:

so cool,使用背景图像(注意是图像)渐变,代码瞬间少了许多。(原文用background,我这里改回background-image方便理解)

.demo li {   
    padding-left: 15px;   
    line-height: 40px;   
    background-image: linear-gradient(transparent 39px, #ccc 39px, #ccc) no-repeat;   
}   
.demo li:not(:last-child) {   
    background-position: 15px;   
}   
.demo li:hover {   
    background-color: #f3f3f3;   
}
Copy after login

方案三:

在第三种的基础上使用了background-origin

background-origin: border-box | padding-box | content-box

padding-box:从padding区域(含padding)开始显示背景图像。

border-box:从border区域(含border)开始显示背景图像。

content-box:从content区域开始显示背景图像。

所以我们可以利用padding-box和content-box解析不同的背景图像(注意是图像)开始区域。来实现,代码如下:

.demo li {   
    padding-left: 15px;   
    line-height: 40px;   
    background-image: linear-gradient(transparent 39px, #ccc 39px, #ccc) no-repeat;   
    background-origin:padding-box;/*background-origin默认值,可不写,我只是为了跟下面对比而已*/  
}   
.demo li:not(:last-child) {   
    background-origin:content-box;   
}   
.demo li:hover {   
    background-color: #f3f3f3;   
}
Copy after login

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

利用SVG和CSS3实现炫酷的边框动画

关于CSS banner图响应式居中显示的方法

兼容ie的内阴影和外阴影的实现效果及测试代码

The above is the detailed content of Some tips on creating border effects with 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)

Hot Topics

Java Tutorial
1653
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

How to use CSS to achieve the rotating background animation effect of elements How to use CSS to achieve the rotating background animation effect of elements Nov 21, 2023 am 09:05 AM

How to use CSS to implement rotating background image animation effects of elements. Background image animation effects can increase the visual appeal and user experience of web pages. This article will introduce how to use CSS to achieve the rotating background animation effect of elements, and provide specific code examples. First, we need to prepare a background image, which can be any picture you like, such as a picture of the sun or an electric fan. Save the image and name it "bg.png". Next, create an HTML file and add a div element in the file, setting it to

How to make custom borders in Microsoft Word How to make custom borders in Microsoft Word Nov 18, 2023 pm 11:17 PM

Want to make the front page of your school project look exciting? Nothing makes it stand out from other submissions like a nice, elegant border on the homepage of your workbook. However, the standard single-line borders in Microsoft Word have become very obvious and boring. Therefore, we show you the steps to create and use custom borders in Microsoft Word documents. How to Make Custom Borders in Microsoft Word Creating custom borders is very easy. However, you will need a boundary. Step 1 – Download Custom Borders There are tons of free borders on the internet. We have downloaded a border like this. Step 1 – Search the Internet for custom borders. Alternatively, you can go to clipping

Popular science on how to set excel borders Popular science on how to set excel borders Mar 20, 2024 am 10:30 AM

It is not uncommon for Excel to appear in our daily work and life. Whether it is the production of employee information, salary tables, or student enrollment information and transcripts, Excel is a relatively easy-to-use tool. When printing Excel, you need to set borders to meet printing requirements. In this article, the editor will introduce you to several ways to set Excel borders. Method 1. Use the function tab button. This should be a method often used by everyone. It is convenient and fast. The specific operation: select the cell area B2:H10 where you need to add a border, click the [Start] tab - [Border] drop-down on the right Button-[All Frames] to complete adding frames. Method 2. Select the cell area B2:H10 where you want to add a border.

How to use CSS to animate the border of an element How to use CSS to animate the border of an element Nov 21, 2023 pm 02:26 PM

How to use CSS to achieve element border animation effects Introduction: In web design, in order to increase the user's visual experience and the attractiveness of the page, some animation effects are often used to make page elements more vivid and interesting. Among them, border animation is a very common effect, which can make the element border change, flicker or flow dynamically. This article will introduce how to use CSS to animate the border of elements and provide specific code examples. 1. Realize the border color change animation To realize the border color change animation effect, you can

How to add borders to images using PHP How to add borders to images using PHP Aug 26, 2023 am 10:12 AM

How to use PHP to add borders to pictures In web development and image processing, it is often necessary to add borders to pictures to improve the beauty and visibility of the pictures. This article will introduce how to add borders to images using PHP, with code examples. First, we need to make sure that PHP's GD library is installed on the server. The GD library is an open source library for image processing that can be used to create, manipulate and output images. Most servers have the GD library installed by default, but if it is not installed, you can manage the work through the PHP extension.

Tips for achieving gradient border effect using CSS properties Tips for achieving gradient border effect using CSS properties Nov 18, 2023 pm 02:53 PM

The technique of realizing the gradient border effect using CSS properties requires specific code examples. In web design, the border is an important element that can bring richer visual effects to the page. And if you can achieve a gradient effect on the border, it will further increase the appeal of the page. This article will introduce some techniques for using CSS properties to achieve gradient border effects, and provide specific code examples. Use the "border-image" attribute to implement gradient borders&lt;style&gt;.gradient-

Tips for implementing border animation effects using CSS properties Tips for implementing border animation effects using CSS properties Nov 18, 2023 pm 01:26 PM

Techniques for implementing border animation effects using CSS properties require specific code examples. With the continuous development of Web technology, the requirements for page design are becoming higher and higher. In page design, animation effects are one of the important means to attract users' attention. Among them, border animation effects can add vitality and vitality to the page. This article will introduce some techniques for using CSS properties to help you achieve various border animation effects. 1. Use the transition attribute to achieve transition effects. The transition attribute can define the elements in different states.

See all articles