如何使 href 中的完整图像可点击
How to make a full image inside href be clickable
简单的问题,我做错了什么,但没有得到这里的问题。我想让图像像 link 一样可点击,但这不能正常工作,link 只停留在中间,而不是我想要的完整图像。有人可以帮忙吗?
<div>
<ul class="principaisCategorias">
<li class="itemCategoria">
<div class="imagesItemCategoria">
<a data-bind="ccLink:{route: '/category/ar-condicionado-portatil'}">
<img src="/file/general/imageItemCategoria.jpg" />
</a>
</div>
</li>
</ul>
</div>
这是我的 css:
div{
display: inline;
font-weight: bold;
text-align: center;
ul{
padding: 0;
margin: 0;
&.principaisCategorias{
width: 102%;
height: 450px;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
.itemCategoria{
list-style-type: none;
margin-top: 2px;
margin-left: 2%;
margin-bottom: 2px;
margin-right: 2%;
height: 140px;
width: 45%;
background-color: mediumturquoise;
.imagesItemCategoria {
width: 100%;
height: 100%;
position: relative;
display: inline-block;
img, a{
display: block;
width: 100%;
height: 100%;
max-height:100%;
max-width:100%;
}
a{
display: inline-block;
}
}
}
}
}
}
当我尝试 运行 时,代码最初 none 正在应用内部样式。这是因为您的 CSS 像 SASS 或 SCSS 一样嵌套。当我重构为普通 CSS 语法时,它开始工作得更好。
就 a
link 行为问题而言,您在该元素上没有 href
属性,因此它的行为或多或少类似于 <span>
标记.那里还有其他一些不必要的样式。这就是我需要让它按预期运行的全部内容:
.imagesItemCategoria a {
display: block;
cursor: pointer;
}
完整代码和工作演示:
.wrapper {
display: inline;
font-weight: bold;
text-align: center;
}
ul.principaisCategorias{
width: 102%;
height: 450px;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
padding: 0;
margin: 0;
}
.itemCategoria{
list-style-type: none;
margin-top: 2px;
margin-left: 2%;
margin-bottom: 2px;
margin-right: 2%;
height: 140px;
width: 45%;
background-color: mediumturquoise;
}
.imagesItemCategoria {
width: 100%;
height: 100%;
position: relative;
display: inline-block;
}
.imagesItemCategoria a {
display: block;
cursor: pointer;
}
.imagesItemCategoria img {
width: 100%;
height: auto;
display: block;
}
<div class="wrapper">
<ul class="principaisCategorias">
<li class="itemCategoria">
<div class="imagesItemCategoria">
<a data-bind="ccLink:{route: '/category/ar-condicionado-portatil'}">
<img src="https://picsum.photos/300" />
</a>
</div>
</li>
</ul>
</div>
简单的问题,我做错了什么,但没有得到这里的问题。我想让图像像 link 一样可点击,但这不能正常工作,link 只停留在中间,而不是我想要的完整图像。有人可以帮忙吗?
<div>
<ul class="principaisCategorias">
<li class="itemCategoria">
<div class="imagesItemCategoria">
<a data-bind="ccLink:{route: '/category/ar-condicionado-portatil'}">
<img src="/file/general/imageItemCategoria.jpg" />
</a>
</div>
</li>
</ul>
</div>
这是我的 css:
div{
display: inline;
font-weight: bold;
text-align: center;
ul{
padding: 0;
margin: 0;
&.principaisCategorias{
width: 102%;
height: 450px;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
.itemCategoria{
list-style-type: none;
margin-top: 2px;
margin-left: 2%;
margin-bottom: 2px;
margin-right: 2%;
height: 140px;
width: 45%;
background-color: mediumturquoise;
.imagesItemCategoria {
width: 100%;
height: 100%;
position: relative;
display: inline-block;
img, a{
display: block;
width: 100%;
height: 100%;
max-height:100%;
max-width:100%;
}
a{
display: inline-block;
}
}
}
}
}
}
当我尝试 运行 时,代码最初 none 正在应用内部样式。这是因为您的 CSS 像 SASS 或 SCSS 一样嵌套。当我重构为普通 CSS 语法时,它开始工作得更好。
就 a
link 行为问题而言,您在该元素上没有 href
属性,因此它的行为或多或少类似于 <span>
标记.那里还有其他一些不必要的样式。这就是我需要让它按预期运行的全部内容:
.imagesItemCategoria a {
display: block;
cursor: pointer;
}
完整代码和工作演示:
.wrapper {
display: inline;
font-weight: bold;
text-align: center;
}
ul.principaisCategorias{
width: 102%;
height: 450px;
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
padding: 0;
margin: 0;
}
.itemCategoria{
list-style-type: none;
margin-top: 2px;
margin-left: 2%;
margin-bottom: 2px;
margin-right: 2%;
height: 140px;
width: 45%;
background-color: mediumturquoise;
}
.imagesItemCategoria {
width: 100%;
height: 100%;
position: relative;
display: inline-block;
}
.imagesItemCategoria a {
display: block;
cursor: pointer;
}
.imagesItemCategoria img {
width: 100%;
height: auto;
display: block;
}
<div class="wrapper">
<ul class="principaisCategorias">
<li class="itemCategoria">
<div class="imagesItemCategoria">
<a data-bind="ccLink:{route: '/category/ar-condicionado-portatil'}">
<img src="https://picsum.photos/300" />
</a>
</div>
</li>
</ul>
</div>