Skip to content

The CSS attributes are not taking effect, but the "CSS_PATH" attribute is working. #6003

Answered by willmcgugan
Gu-f asked this question in Q&A
Discussion options

You must be logged in to vote

When you put CSS in a screen it is "scoped". i.e. it prefixes every ruleset with the container type. It is breaking your CSS because your Screen rule becomes MyScreen Screen, which doesn't make sense.

The solution is to always be specific with your rules. Don't style Screen because that would apply to all screens. If you want to style MyScreen then begin your rule with MyScreen. Textual knows not to prefix specific rules like that.

So a fix would be this:

from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Label


class MyScreen(Screen):
    def compose(self) -> ComposeResult:
        yield Label("Center Label")

    CSS = """
    MyScr…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Gu-f
Comment options

Answer selected by Gu-f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #6002 on July 30, 2025 06:07.