


When we develop web front-end, in order to make the website more visually beautiful and richer in effect, the powerful properties of css naturally play an indispensable role. Then here is a crucial attribute to mention, the css display attribute. So some novices may ask, what does display in css mean? How to use css display?
This article will give you a detailed introduction to the specific usage of the css display attribute, hoping to solve your questions. (In order to make it easier for everyone to understand this article, it is recommended to read my article [How are html elements distinguished?] which has a detailed introduction to block-level elements and inline elements)
First, let me list several commonly used values of css display: none, block, inline, inline-block
Next, we will explain the usage of css display attributes in detail through specific code examples.
1. Introduction to specific examples of css display block attributes
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>css display:block属性实例</title> <style> *{padding: 0;margin:0;list-style: none;} ul li{float: left;} a{ display:block; width: 30px;height: 30px; color:#fff; background: green;margin: 5px; text-decoration: none; text-align: center; line-height: 30px; } </style> </head> <body> <div class="demo"> <ul> <li><a href="">1</a></li> <li><a href="">2</a></li> <li><a href="">3</a></li> <li><a href="">4</a></li> <li><a href="">5</a></li> </ul> </div> </body> </html>
The above code is accessed through the browser, and the effect is as shown in Figure 1:
We comment out the display:block; attribute in the a tag, and the effect is as shown in Figure 2:
Then through Figure 1 and Figure Comparing 2, we can find that in Figure 1, because the display:block attribute is set, the element block in a can display the width, height, and inner and outer margin settings. In Figure 2, just the display block attribute is removed, which results in the width and height not being set for all element blocks.
That is to say, the display block attribute can set the inline element to a block-level element, and then set its width, height, top, bottom, left, and right margins, padding, and margin. We can use this attribute to achieve the effect we want.
2. Specific examples of css display none attribute
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>css display:none属性实例</title> <style> *{padding: 0;margin:0;list-style: none;} ul li{float: left;} a{ display: none; width: 30px;height: 30px;color:#fff; background: green;margin: 5px; text-decoration: none;text-align: center;line-height: 30px;} </style> </head> <body> <div class="demo"> <p>a元素不会显示出来</p> <ul> <li><a href="">1</a></li> <li><a href="">2</a></li> <li><a href="">3</a></li> <li><a href="">4</a></li> <li><a href="">5</a></li> </ul> </div> </body> </html>
The effect is as shown in Figure 3:
As can be seen from Figure 3, after we set the display:none; attribute to a, all its elements are hidden and will not be displayed. So it is obviously decided that the display attribute value is the none attribute. display none is usually used in the design of the first and second columns of the navigation bar.
3. Introduction to css display inline attribute
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>css display:inline属性实例</title> <style> p {display: inline} </style> </head> <body> <p>p标签是块级元素。</p> <p>此时显示为内联元素,不换行。</p> </body> </div> </body> </html>
The effect is as shown in Figure 4:
You can see from Figure 4 You know, the css display inline attribute can turn an element into an inline element, that is, an inline element, and there are no line breaks before and after the element.
4. Introduction to css display inline-block attribute
As the name suggests, the inline-block attribute definitely combines the characteristics of the inline and block attributes, which means that this attribute can Turn the element into an inline block element. You can not only display the specified elements in the same line, but also set the width and height of their elements.
Then this article is an introduction to the specific usage of the css display attribute, including specific usage examples of none, block, inline, and inline-block. It has certain reference value and I hope it will be helpful to friends in need.
The above is the detailed content of What does the display attribute in css mean? how to use? [Example summary]. For more information, please follow other related articles on the PHP Chinese website!

I got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?

Yes, you can, and it doesn't really matter in what order. A CSS preprocessor is not required. It works in regular CSS.

You should for sure be setting far-out cache headers on your assets like CSS and JavaScript (and images and fonts and whatever else). That tells the browser

Many developers write about how to maintain a CSS codebase, yet not a lot of them write about how they measure the quality of that codebase. Sure, we have

Have you ever had a form that needed to accept a short, arbitrary bit of text? Like a name or whatever. That's exactly what is for. There are lots of

I'm so excited to be heading to Zürich, Switzerland for Front Conference (Love that name and URL!). I've never been to Switzerland before, so I'm excited

One of my favorite developments in software development has been the advent of serverless. As a developer who has a tendency to get bogged down in the details

In this post, we’ll be using an ecommerce store demo I built and deployed to Netlify to show how we can make dynamic routes for incoming data. It’s a fairly


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools