Styling compound widgets confuses me #4388
-
|
Trying to style a Compound Widget I went in some trouble. Styling a normal But when I use an Here my small code which should demonstrate this: #!/usr/bin/env python3
from textual.app import App
from textual.widget import Widget
from textual.widgets import Input, Label
class LabelInput(Widget):
DEFAULT_CSS = """
LabelInput {
layout: horizontal;
}
.labelinput {
border: none;
height: 1;
background: magenta;
}
"""
def compose(self):
yield Label('Label für MyInput: ')
yield Input(classes='labelinput', placeholder='LabelInput')
class Test(App):
CSS = """
.input {
border: none;
height: 1;
background: blue;
}
"""
def compose(self):
yield Label('Label für Input')
yield Input(classes='input', placeholder='Input')
yield LabelInput()
if __name__ == '__main__':
app = Test()
app.run()The The As you can see in the code the May be the With the May be that could be helpful because of the As soon as I define the CSS rule for I would be glad to get some hint. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
I'm not seeing any styling of the :focus pseudo class in your code. Something like Input has separate styling for the focus state. See https://textual.textualize.io/guide/CSS/#pseudo-classes for more background. |
Beta Was this translation helpful? Give feedback.
-
|
Wow, all these three variants work fine. In each case the Vaiant 1: DEFAULT_CSS = """
LabelInput {
layout: horizontal;
&> Input {
border: none;
height: 1;
background: magenta;
&:focus {
border: none;
}
}
}Variant 2: DEFAULT_CSS = """
LabelInput {
layout: horizontal;
}
LabelInput .labelinput {
border: none;
height: 1;
background: magenta;
}Variant 3: DEFAULT_CSS = """
LabelInput {
layout: horizontal;
.labelinput {
border: none;
height: 1;
background: magenta;
}
}For now I would prefer variant 2 or 3. There I easily can overwrite the The only thing is that I had to repeat the So it could be a good idea to separate more essential rules from less importend ones like this: DEFAULT_CSS = """
LabelInput {
layout: horizontal;
.oneline {
border: none;
height: 1;
}
.labelinput {
background: magenta;
}
}Of course, in this case both of the classes must be passed to the Input(classes='labelinput oneline')Now I can configure colors or other things overwriting That looks good for me. Again: Thank you very much for patient assistance. |
Beta Was this translation helpful? Give feedback.
I think perhaps what is confusing here is that the
.inputclass in the App CSS doesn't handle the:focuspseudo class either, yet that works as Ulrich expects without any border when it is focused.It looks like the
DEFAULT_CSSabove was missing the parent selector, after adding this here:Or using nested CSS like this: