Recently, I've been exploring the use of <style jsx>
in my Next.js project and encountered a scenario where I needed to style an element based on a conditional statement. Additionally, my project relies on tailwindCSS for styling:
<div
className="mt-20 description_content text-center flex flex-col justify-center items-center text-gray-500 mx-5"
dangerouslySetInnerHTML={{
__html: productDetail?.description,}}>
</div>
.description_content p:first-child {
position: relative !important;
overflow: hidden !important;
width: 100% !important;
padding-top: 56.25% !important; /* if there is no iframe tag as a child, it should be padding-top: 0px; */
}
.description_content p iframe {
position: absolute !important;
top: 0 !important;
left: 0 !important;
bottom: 0 !important;
right: 0 !important;
width: 100% !important;
height: 100% !important;
margin: 0 auto !important;
}
My goal is to dynamically set the padding-top property to 56.25% under certain conditions - specifically when an iframe tag is present under the first p tag. However, if there's no iframe tag under the first p tag, I want to adjust the padding-top to 0px.
I'm curious if there's a method to implement a conditional statement within CSS to achieve this functionality.