如何在ReactJ中旋转伪元素及其内容为SVG
[我的项目的图像]
[1] : https://i.sstatic 。
/I.sstatic.net/lmhnu.png
当我单击橙色箭头时,我想旋转它(180 deg)
是可以使用CSS来完成的,或者我应该使用JS
以及如何声明可变并给予它是伪元素作为Reactjs
<div className="container">
<div className="imgBox">
<img src={img_1} alt="img_1" className="img_1" />
<img src={img_2} alt="img_2" className="img_2" />
</div>
<div className="textBox">
<h1>FAQ</h1>
<div className="questions">
<div>
<button
onClick={() => {
hideText(p1);
}}
>
How many team members can I invite?
</button>
<p ref={p1} className="p1 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p2);
}}
>
How many team members can I invite?
</button>
<p ref={p2} className="p2 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p3);
}}
>
How many team members can I invite?
</button>
<p ref={p3} className="p3 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p4);
}}
>
How many team members can I invite?
</button>
<p ref={p4} className="p4 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p5);
}}
>
How many team members can I invite?
</button>
<p ref={p5} className="p5 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
</div>
</div>
</div>
样式的值
.container>.textBox>.questions>div>button {
width: 100%;
height: 30px;
background: transparent;
color: var(--Very-dark-grayish-blue);
font-size: 15px;
text-align: left;
border: 0;
cursor: pointer;
outline: none;
}
.container>.textBox>.questions>div>button:hover {
color: var(--Soft-red);
}
.container>.textBox>.questions>div>button:focus {
font-weight: bold;
}
.container>.textBox>.questions>div>button::after {
content: url(./images/icon-arrow.svg);
float: right;
}
.container>.textBox>.questions>div>button::after:focus {
transform: rotate(180deg);
}
[images for my project]
[1]: https://i.sstatic.net/a6EFH.png
[2]: https://i.sstatic.net/lMhNu.png
when I click on the orange arrow I want to rotate it (180deg)
Is this can be done with CSS or I should use JS
And how I can declare a variable and give it a pseudo-element as a value in ReactJS
<div className="container">
<div className="imgBox">
<img src={img_1} alt="img_1" className="img_1" />
<img src={img_2} alt="img_2" className="img_2" />
</div>
<div className="textBox">
<h1>FAQ</h1>
<div className="questions">
<div>
<button
onClick={() => {
hideText(p1);
}}
>
How many team members can I invite?
</button>
<p ref={p1} className="p1 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p2);
}}
>
How many team members can I invite?
</button>
<p ref={p2} className="p2 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p3);
}}
>
How many team members can I invite?
</button>
<p ref={p3} className="p3 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p4);
}}
>
How many team members can I invite?
</button>
<p ref={p4} className="p4 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
<div>
<button
onClick={() => {
hideText(p5);
}}
>
How many team members can I invite?
</button>
<p ref={p5} className="p5 not-active">
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
Temporibus obcaecati, quae, corporis.
</p>
</div>
<hr />
</div>
</div>
</div>
Styling
.container>.textBox>.questions>div>button {
width: 100%;
height: 30px;
background: transparent;
color: var(--Very-dark-grayish-blue);
font-size: 15px;
text-align: left;
border: 0;
cursor: pointer;
outline: none;
}
.container>.textBox>.questions>div>button:hover {
color: var(--Soft-red);
}
.container>.textBox>.questions>div>button:focus {
font-weight: bold;
}
.container>.textBox>.questions>div>button::after {
content: url(./images/icon-arrow.svg);
float: right;
}
.container>.textBox>.questions>div>button::after:focus {
transform: rotate(180deg);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尚未发布您的标记,但是只需使用
&lt;详细信息&gt;
披露元素就可以使用html/css进行大量清洁。在此处阅读MDN文档: https> https:https:https://开发人员。 mozilla.org/en-us/docs/web/html/element/details您可以完全控制其样式,包括隐藏标记psuedo元素。在此线程中有一个具体答案,您会发现它有用: html/summary详细信息标记造型
这是可以开始的片段。我也从CSS中拿出了箭头,因为我没有您的SVG。您需要用您的背景图像等替换
的内容:
选择器之后,然后再替换[open]
selector。You haven't posted your markup, but you can do this a lot cleaner with just html/css using the
<details>
disclosure element. Read the MDN docs for that here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/detailsYou have full control over the style of it including hiding the marker psuedo element. There's a specific answer for that in this thread which you will find useful: HTML Details/Summary Element Marker Styling
Here's a snippet to get started. I've made the arrow out of css too because I don't have your svg. You'll need to replace the contents of the
:after
selector with your background-image etc, and again for the[open]
selector.