信任徽章 html css 和脚本
我正在尝试在我的商店上进行定制徽章。我想拥有4个具有“快速运输”之类的信息。单击其中一个时,一个小的描述性文本将在下面显示。
现在,我的问题是,我找不到将< p>
设置为宽度100%的方法当不按下时不好)
有人可以给我有关如何执行此操作的提示吗? < 3我没有想法,
这是我的代码,谢谢!
var acc = document.getElementsByClassName("accordion-2");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
.accordion-2 {
background-color: rgb(255, 255, 255);
color: #444;
cursor: pointer;
padding: 18px;
width: 49%;
float: left;
border: none;
border-bottom: 1px solid rgba(0, 0, 0, 0.164);
text-align: left;
outline: none;
font-size: 15px;
font-style: italic;
transition: 0.2s;
}
.active,
.accordion-2:hover {
background-color: rgb(212, 245, 255);
}
.accordion-2-guld:hover {
background-color: rgb(236, 185, 45);
}
.accordion-2:after {
content: '\002B';
color: #777;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2212";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
.panel:after {
float: left;
}
<button class="accordion-2">Gratis frakt</button>
<div class="panel">
<p>Gratis | Postnord Hemleverans 3-5 dagar.<br><br>49kr | Skickas samma dag eller dagen efter. 1-2 arbetsdagar.<br><br>57kr | Utlämningsställe</p>
</div>
<button class="accordion-2">Enkel retur</button>
<div class="panel">
<p>Byta storlek eller färg? Inga problem! <br><br> Du står för frakten till oss och vi skickar gratis tillbaka nya produkter!</p>
</div>
<button class="accordion-2">Fin paketbox</button>
<div class="panel">
<p>Varje smycke kommer fint paketerad i våra fina askar och läderpåsar. De kommer i vit eller svart och olika storlekar. Vi ser till att paketet passar just din beställning
I am trying to do custom badges on my store. I want to have 4 objects with info like "fast shipping". When clicking on one of them, a small descriptive text will show just underneath.
Now, my problem is that I can't find a way to set the <p>
to width 100% only when active, without putting it 100% all the time (which will make it all look bad when not pressed)
Can someone give me tips on how to do this? <3 I am out of ideas hahah
Here is my code, thanks!
var acc = document.getElementsByClassName("accordion-2");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
.accordion-2 {
background-color: rgb(255, 255, 255);
color: #444;
cursor: pointer;
padding: 18px;
width: 49%;
float: left;
border: none;
border-bottom: 1px solid rgba(0, 0, 0, 0.164);
text-align: left;
outline: none;
font-size: 15px;
font-style: italic;
transition: 0.2s;
}
.active,
.accordion-2:hover {
background-color: rgb(212, 245, 255);
}
.accordion-2-guld:hover {
background-color: rgb(236, 185, 45);
}
.accordion-2:after {
content: '\002B';
color: #777;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2212";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
.panel:after {
float: left;
}
<button class="accordion-2">Gratis frakt</button>
<div class="panel">
<p>Gratis | Postnord Hemleverans 3-5 dagar.<br><br>49kr | Skickas samma dag eller dagen efter. 1-2 arbetsdagar.<br><br>57kr | Utlämningsställe</p>
</div>
<button class="accordion-2">Enkel retur</button>
<div class="panel">
<p>Byta storlek eller färg? Inga problem! <br><br> Du står för frakten till oss och vi skickar gratis tillbaka nya produkter!</p>
</div>
<button class="accordion-2">Fin paketbox</button>
<div class="panel">
<p>Varje smycke kommer fint paketerad i våra fina askar och läderpåsar. De kommer i vit eller svart och olika storlekar. Vi ser till att paketet passar just din beställning ???? Har du ett speciellt önskemål är det bara att lägga en liten kommentar vi utcheckning,
så löser vi det!</p>
</div>
<button class="accordion-2">Betala efter 30 dagar med Klarna</button>
<div class="panel">
<p>Vi erbjuder Klarna betalning, Swish & Kortbetlaning.</p>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
2列和描述在每列内部的按钮下。
使用CSS网格。
将您的
按钮
和.panel
包装到.column
中。使用CSS网格在40%
中显示2列。删除
float:从您的
,并设置按钮
中左width:100%
到您的按钮。2 columns and description is under the button inside each column.
Use CSS grid.
Wrap your
button
and.panel
into a.column
. Use CSS grid to display 2 columns at40%
each.Remove
float: left
from yourbutton
and setwidth: 100%
to your button.Now you will have 2 columns with description under the button inside each column.
See it on jsfiddle.
To have 2 columns but when active, display
.panel
in full width.Use the same CSS grid as above but add
.active
class to.column
in JS. Modify.accordion-columns .column.active
CSS to start and column 1 and end at the end.Modify your CSS to display
+
and-
correctly.See it on jsfiddle.