How to create a responsive product display layout using HTML and CSS
Overview:
In modern society, more and more people shop through the Internet. In order to attract more consumers, website developers need to create beautiful and responsive product display pages. This article will introduce you to how to use HTML and CSS to implement a simple and effective product display layout.
Step 1: Set HTML structure
First, we need to set up a basic HTML structure. In this structure, we will use a div element to create a container for the product and insert the product's image, title, and price into it. The following is a basic HTML structure example:
<!DOCTYPE html> <html> <head> <title>商品展示</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="container"> <div class="product"> <img src="/static/imghwm/default1.png" data-src="product1.jpg" class="lazy" alt="How to create a responsive product display layout using HTML and CSS" > <h3 id="商品标题">商品标题</h3> <p>商品价格</p> </div> <div class="product"> <img src="/static/imghwm/default1.png" data-src="product2.jpg" class="lazy" alt="How to create a responsive product display layout using HTML and CSS" > <h3 id="商品标题">商品标题</h3> <p>商品价格</p> </div> <!-- 添加更多的商品 --> </div> </body> </html>
In the above example, we have set up a container div that will contain all the products. Each product is defined as a div with the class name "product". The product image, title and price are inserted into the product div respectively.
Step 2: Set CSS style
Next, we need to use CSS to set the style of the product display layout. We will use CSS media queries to implement responsive layout. Here is an example of setting CSS styles:
.container { display: flex; flex-wrap: wrap; justify-content: center; } .product { width: 300px; margin: 20px; padding: 10px; text-align: center; background-color: lightgray; } .product img { width: 100%; height: auto; } @media (max-width: 768px) { .product { width: 400px; } } @media (max-width: 480px) { .container { flex-direction: column; } .product { width: 100%; } }
In the above example, we first set the container to flex layout and use the flex-wrap property to make the items wrap when the container exceeds the width. We then set the product width, margins, and padding, and center-aligned the text. Finally, we set the background color for the product container.
In the @media query, we set different styles for different screen sizes. When the maximum width is 768px, we set the width of the product to 400px. When the maximum width is 480px, we use the flex-direction attribute to arrange the products vertically and set the width of the products to 100%.
Step 3: Add more products
If you want to display more products, just add more products div in the HTML. You can copy existing product divs to quickly create new products. The product's image, title, and price can be customized as needed.
Summary:
It is not difficult to create a responsive product display layout using HTML and CSS. By setting the HTML structure and CSS styles, we can easily implement a beautiful product display page. Remember to use media queries to adapt to different screen sizes to ensure your products look best on a variety of devices. I hope this article helped you create an impressive responsive product display layout.
Appendix: Sample file
style.css:
.container { display: flex; flex-wrap: wrap; justify-content: center; } .product { width: 300px; margin: 20px; padding: 10px; text-align: center; background-color: lightgray; } .product img { width: 100%; height: auto; } @media (max-width: 768px) { .product { width: 400px; } } @media (max-width: 480px) { .container { flex-direction: column; } .product { width: 100%; } }
index.html:
<!DOCTYPE html> <html> <head> <title>商品展示</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="container"> <div class="product"> <img src="/static/imghwm/default1.png" data-src="product1.jpg" class="lazy" alt="How to create a responsive product display layout using HTML and CSS" > <h3 id="商品标题">商品标题</h3> <p>商品价格</p> </div> <div class="product"> <img src="/static/imghwm/default1.png" data-src="product2.jpg" class="lazy" alt="How to create a responsive product display layout using HTML and CSS" > <h3 id="商品标题">商品标题</h3> <p>商品价格</p> </div> <!-- 添加更多的商品 --> </div> </body> </html>
The above sample file uses two schematic product images. You You can replace it with your own product image. Remember to change the file name and path to the corresponding ones in index.html.
The above is the detailed content of How to create a responsive product display layout using HTML and CSS. For more information, please follow other related articles on the PHP Chinese website!

在css中,可用list-style-type属性来去掉ul的圆点标记,语法为“ul{list-style-type:none}”;list-style-type属性可设置列表项标记的类型,当值为“none”可不定义标记,也可去除已有标记。

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

在css中,可以利用cursor属性实现鼠标隐藏效果,该属性用于定义鼠标指针放在一个元素边界范围内时所用的光标形状,当属性值设置为none时,就可以实现鼠标隐藏效果,语法为“元素{cursor:none}”。

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

转换方法:1、给英文元素添加“text-transform: uppercase;”样式,可将所有的英文字母都变成大写;2、给英文元素添加“text-transform:capitalize;”样式,可将英文文本中每个单词的首字母变为大写。

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools