CSS巧用content内容生成

(1)防止子元素的margin越界

.parent:before {
content: '  ';
display: table;
}

(2)清除子元素的浮动对父元素及后续元素造成的影响

.parent:after {
content: '  ';
display: table;
clear: both;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的移动端购物车界面的CSS代码示例: HTML代码: ``` <html> <head> <title>移动端购物车界面</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="cart-container"> <div class="cart-header"> <h1>购物车</h1> </div> <div class="cart-items"> <div class="cart-item"> <img src="product1.jpg" alt="产品1"> <div class="cart-item-info"> <h2>产品1</h2> <p>价格:$100</p> <button>删除</button> </div> </div> <div class="cart-item"> <img src="product2.jpg" alt="产品2"> <div class="cart-item-info"> <h2>产品2</h2> <p>价格:$200</p> <button>删除</button> </div> </div> </div> <div class="cart-total"> <p>总价:$300</p> </div> <button class="checkout-button">结算</button> </div> </body> </html> ``` CSS代码: ``` body { font-family: Arial, sans-serif; } .cart-container { padding: 20px; } .cart-header { text-align: center; } .cart-header h1 { font-size: 24px; margin: 0; } .cart-item { display: flex; flex-direction: row; align-items: center; margin-bottom: 20px; } .cart-item img { width: 80px; height: 80px; margin-right: 20px; } .cart-item-info h2 { font-size: 18px; margin: 0; } .cart-item-info p { font-size: 14px; margin: 0; } .cart-item-info button { background-color: #f44336; color: #fff; border: none; border-radius: 4px; padding: 8px 16px; font-size: 14px; margin-top: 10px; cursor: pointer; } .cart-total { text-align: right; } .cart-total p { font-size: 16px; margin: 0; } .checkout-button { background-color: #008CBA; color: #fff; border: none; border-radius: 4px; padding: 16px; font-size: 18px; width: 100%; margin-top: 20px; cursor: pointer; } ``` 说明: 上面的CSS代码实现了一个简单的移动端购物车界面,包括购物车标题、购物车商品列表、商品图片、商品信息、删除按钮、总价、结算按钮等元素。其中,使用了flex布局,使得界面在移动设备上显示更加合理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值