HTML CSS 代码:图片居中显示,PC 端 60% 宽度,移动端 80% 宽度,下方居中按钮
以下是一段 HTML 和 CSS 代码,可以实现图片居中显示,PC 端图片宽度为 60%,移动端图片宽度为 80%,并在下方居中显示两个按钮:
<!DOCTYPE html>
<html>
<head>
<style>
.container {
text-align: center;
}
img {
width: 60%;
}
@media screen and (max-width: 600px) {
img {
width: 80%;
}
}
.buttons {
display: flex;
justify-content: center;
margin-top: 20px;
}
.button {
margin: 0 10px;
}
</style>
</head>
<body>
<div class='container'>
<img src='your_image.jpg' alt='Image'>
<div class='buttons'>
<button class='button'>Button 1</button>
<button class='button'>Button 2</button>
</div>
</div>
</body>
</html>
你需要将'your_image.jpg'替换为你自己的图片路径。这段代码将图片居中显示,PC 端图片宽度为 60%,移动端图片宽度为 80%。在图片下方,两个按钮会居中显示。
原文地址: https://www.cveoy.top/t/topic/npBH 著作权归作者所有。请勿转载和采集!