Home > Web Front-end > CSS Tutorial > How to remove the last element style in css

How to remove the last element style in css

醉折花枝作酒筹
Release: 2023-01-05 16:07:53
Original
10901 people have browsed it

How to remove the last element style in css: 1. Use the id or class selector to set the last element as the default style; 2. Use the pseudo-class ":last-child" to automatically match the last element For an element, just set it as the default style, the syntax is "element name: last-child {attribute: default value}".

How to remove the last element style in css

The operating environment of this tutorial: Windows7 system, CSS3&&HTML5 version, Dell G3 computer.

Many people may have encountered such a situation:

<style>    
.test li{    
   float:left;    
   border-right:1px solid #ccc;      
   width:100px;      
   height:100px;    
   }
</stly>
   <ul class="test">    
       <li></li>    
       <li></li>    
       <li></li>
   </ul>
Copy after login

In this way, three right borders will appear. In actual application, the last border needs to be removed.

Here are two methods:

1. Add a style to the last li

.b-none{border:none}
Copy after login

2. Use css pseudo Class: last-child, to automatically match the last element and execute the corresponding style.

.test li:last-child{border:none}
Copy after login

The second pseudo-class method has compatibility issues under IE. If compatibility issues are not considered, go to is a good choice.

Recommended learning: css video tutorial

The above is the detailed content of How to remove the last element style in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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