gpt4 book ai didi

html - 图片下方的居中链接

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:38 24 4
gpt4 key购买 nike

如何在我的图片下方居中链接,我尝试了一切。当我使用 clear:both 时,这对我有帮助,但是我的图像在一列中,我不希望这样。所以基本上我想在每个以图片为中心的链接/文本下面。我知道此 HTML/CSS 不包含我想放在图片下方的链接,我删除了所有可能造成混淆的内容。

谢谢。

* {
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
}
html {
height: 100%;
background-color: #F0FFF0;
}
body {
height: 100%;
width: 100%;
font-size: 100%;
margin: 0;
}
.container {
display: box;
width: 100%;
height: 100%;
margin: 5%;
padding: 0%;
clear: both;
}
.products img {
width: 31%;
height: 31%;
position: relative;
float: left;
display: inline;
margin: 0 2% 3% 0%;
}
<!DOCTYPE>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Products</title>
<link rel="stylesheet" type="text/css" href="css/products.css" />
</head>

<body>
<div class="container">
<div class="products">
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>

<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>


</div>
</div>

</body>

</html>

最佳答案

给你:

不要 float 图片, float 链接。

将图片设为display:block 并在链接中添加text-align:center

* {
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
}
html {
height: 100%;
background-color: #F0FFF0;
}
body {
height: 100%;
width: 100%;
font-size: 100%;
margin: 0;
}
.container {
display: box;
width: 100%;
height: 100%;
margin: 5%;
padding: 0%;
clear: both;
}
.products a {
width: 31%;
height: 31%;
position: relative;
float: left;
margin: 0 2% 3% 0%;
text-align: center
}
.products a img {
display: block;
margin: auto;
}
<!DOCTYPE>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Products</title>
<link rel="stylesheet" type="text/css" href="css/products.css" />
</head>

<body>
<div class="container">
<div class="products">
<a href="#">
<img src="http://www.fillmurray.com/g/140/100" alt="Product name">Link Text
</a>

<a href="#">
<img src="http://www.fillmurray.com/g/140/100" alt="Product name">Link Text
</a>

<a href="#">
<img src="http://www.fillmurray.com/g/140/100" alt="Product name">Link Text
</a>


</div>
</div>

</body>

</html>

关于html - 图片下方的居中链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36894787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com