我正在寻找一个小问题的解决方案,完全是新手,我建立了第一个站点。我利用了“摘要-详细信息”功能,并添加了一个图像,这意味着库存下拉箭头已移动,我无法将其定位在想要的位置。我从材料图标中添加了一个图标,当单击整个图像/部分时,我希望它可以旋转。我不会包含任何JS,因为我可能应该在距离我应该去的地方很远的地方。任何帮助表示赞赏。
.card {
width: 18em;
justify-self: center;
margin: 0;
padding: 2em 1em 0;
}
.card img {
margin: 0 0 5px 0;
width: 18em;
height: auto;
}
summary {
width: 18em;
font-weight: bold;
font-family: monospace;
font-size: 1.2rem;
text-transform: uppercase;
text-align: center;
margin: 0;
padding: 0;
color: #202020;
background: #808080;
cursor: pointer;
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
}
summary::-webkit-details-marker {
display: none;
}
.card i {
margin: 0;
padding: 0;
font-variant-position: sub;
color: #101010;
}
.card i:active{
transform: rotate(180deg);
color: #fef;
}
summary:focus {
outline-style: none;
background: #404040;
color: #fef;
}
details {
width: 17.55em;
color: #fef;
background: #212529;
border-bottom: 1px solid rgba(250, 224, 66, .45);
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
padding: 0;
margin: -.25em 0 2em;
border-right: solid 1px #b5b5b5;
border-bottom: solid 1px #b5b5b5;
}
.contentul li {
padding: 1em;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<div class="card" id="card" >
<details>
<summary><img id="img1" src="https://images.unsplash.com/photo-1503708928676-1cb796a0891e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1334&q=80" alt="ex1">Excavators<br><i class="fas fa-chevron-down"></i></summary>
<ul class="contentul">
<li>180° Wheeled</li>
<li>360° Wheeled</li>
<li>360° Tracked</li>
</ul>
</details>
</div>
答案 0 :(得分:0)
您不需要JavaScript
即可完成此操作。 translateY
位用于防止图标旋转离开其起始位置。值0.5em
表示容纳人字形框的高度的一半。
.fas.fa-chevron-down {
transition: .15s transform ease-in-out;
}
details[open] .fas.fa-chevron-down {
transform: rotate(180deg) translateY(-0.5em);
}
演示
.card {
width: 18em;
justify-self: center;
margin: 0;
padding: 2em 1em 0;
}
.card img {
margin: 0 0 5px 0;
width: 18em;
height: auto;
}
summary {
width: 18em;
font-weight: bold;
font-family: monospace;
font-size: 1.2rem;
text-transform: uppercase;
text-align: center;
margin: 0;
padding: 0;
color: #202020;
background: #808080;
cursor: pointer;
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
}
summary::-webkit-details-marker {
display: none;
}
.card i {
margin: 0;
padding: 0;
font-variant-position: sub;
color: #101010;
}
.card i:active {
transform: rotate(180deg);
color: #fef;
}
summary:focus {
outline-style: none;
background: #404040;
color: #fef;
}
details {
width: 17.55em;
color: #fef;
background: #212529;
border-bottom: 1px solid rgba(250, 224, 66, .45);
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
padding: 0;
margin: -.25em 0 2em;
border-right: solid 1px #b5b5b5;
border-bottom: solid 1px #b5b5b5;
}
.contentul li {
padding: 1em;
}
.fas.fa-chevron-down {
transition: .15s transform ease-in-out;
}
details[open] .fas.fa-chevron-down {
transform: rotate(180deg) translateY(-0.5em);
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<div class="card" id="card">
<details>
<summary><img id="img1" src="https://images.unsplash.com/photo-1503708928676-1cb796a0891e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1334&q=80" alt="ex1">Excavators<br><i class="fas fa-chevron-down"></i></summary>
<ul class="contentul">
<li>180° Wheeled</li>
<li>360° Wheeled</li>
<li>360° Tracked</li>
</ul>
</details>
</div>