0

I'm trying to apply styling depending on the element's parameters. I've tried to search for "conditional css react", "conditional react style in css" and other similar queries.
My code below:
e.g.

<div class="ChatComponent_chatText__n2g6S">
    <span class="ChatComponent_message__e9Kqh" data-author="me">test me</span>
    <span class="ChatComponent_message__e9Kqh" data-author="other">test others</span>
</div>

and the css code

.message {
    background-color: #eef5f8;
    padding: 0.5em;
    border-radius: 10px;
    flex-grow: 0;
    border-bottom-left-radius: 0;
}

.message [data-author="me"] {
    background: linear-gradient(to right, #363795, #005C97);
    color: white;
    -webkit-align-self: flex-end;
    -ms-flex-item-align: end;
    align-self: flex-end;
    border-bottom-right-radius: 0 !important;
    border-bottom-left-radius: 10px !important;
}

And the rendered image below:
rendered image

1 Answer 1

1

Turns out I needed to remove the space between the css selector and the parameter such as:

.message {
    background-color: #eef5f8;
    padding: 0.5em;
    border-radius: 10px;
    flex-grow: 0;
    border-bottom-left-radius: 0;
}

.message[data-author="me"] {
    background: linear-gradient(to right, #363795, #005C97);
    color: white;
    -webkit-align-self: flex-end;
    -ms-flex-item-align: end;
    align-self: flex-end;
    border-bottom-right-radius: 0 !important;
    border-bottom-left-radius: 10px !important;
}

and the rendered image is below:
rendered image

Sign up to request clarification or add additional context in comments.

1 Comment

please reduce the question and answer to a minimum

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.