简体   繁体   English

无法设置手风琴样式(PrimeReact)

[英]Unable to style Accordion (PrimeReact)

I have some accordions from PrimeReact which I use in my code.我在我的代码中使用了一些来自 PrimeReact 的手风琴。 But there are pictures inside and I want to make them smaller.但是里面有图片,我想把它们变小。 This is the current problem:这是当前的问题:

在此处输入图像描述

As you can see, the picture is way too big.如您所见,图片太大了。 I want to set the width to 100% .我想将width设置为100%

Now I did this already before when I used Angular with PrimeNG (same library, just for Angular) and I managed to this in the css file like:现在,当我将 Angular 与 PrimeNG(相同的库,仅用于 Angular)一起使用时,我已经这样做了,并且我在 css 文件中做到了这一点,例如:

:host ::ng-deep .p-accordion-content img {
  width: 100%;
}

This code did exactly what I wanted.这段代码完全符合我的要求。

Now I need the same for React.现在我需要同样的 React。 But it is not working when I use:但是当我使用时它不起作用:

:host .p-accordion-content img {
  width: 100%;
}

This is the code I used to create the accordions.这是我用来创建手风琴的代码。 Maybe it will help:也许它会有所帮助:

createAccordions = () => {
    const allFAQs = this.state.allFAQs;
    let accordions = [];

    for (const faq of allFAQs) {
        const accordion = <AccordionTab key={faq.uuid} header={faq.question}><div dangerouslySetInnerHTML={{ __html: faq.answer }}></div></AccordionTab>;
        accordions.push(accordion);
    }

    return accordions;
}

render() {
    return (
        <div>
            <div className="p-grid">
                
                <div className="p-col-3">

                </div>

                <div className="p-col-6">
                    <Accordion>
                        {this.createAccordions()}
                    </Accordion>
                </div>


                <div className="p-col-3">
                    
                </div>
            </div>
        </div>
    )
}

Does anyone know what I did wrong?有谁知道我做错了什么? How can I style the picture inside the accordionTab?如何设置 accordionTab 内图片的样式?

Thanks for every help!感谢您的帮助!

this is easy you just need to do some experiments with your image dimensions for example... add height along with width(this is used in CSS with pure html similar can be used in your code also)这很容易,你只需要对你的图像尺寸做一些实验,例如......添加高度和宽度(这在 CSS 中使用,纯 html 类似也可以在你的代码中使用)

:host .p-accordion-content img {
  width: 100%;
  height: auto;
}

thankyou谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM