If I am trying to set the same attribute in FXML and in a class definition in CSS, I would expect that the attribute set in FXML is considered more specific than the one from CSS.
For example, if I have a control such as
<Label styleClass="myLabel" prefHeight="40.0">
and, at the same time, a CSS definition such as
Label.myLabel {
-fx-pref-height: 100px;
}
I would expect the label to have a height of 40 px. Instead, it has 100 px.
Is there a way to make the attribute in the FXML have precedence?
In the (so far) absence of a qualified answer, I can only guess:
While one could expect that the FXML attributes have about the same specificity as an inline style definition, they haven't any relation.
The reason for this is the evaluation order: the FXML attributes are evaluated at an earlier time than and completely independent of the CSS definitions. That's why the CSS definitions completely overwrite the attribute definitions, making them obsolete.
Now it is more than a guess: Here I just found that the order of precedence is
a style from a user agent stylesheet in Application.setUserAgentStylesheet(java.lang.String)
value set from code, for example calling Node.setOpacity(double)
a style from an author stylesheet in Scene.getStylesheets() or Parent.getStylesheets()
a style from Node.setStyle(java.lang.String)
assuming that pre-setting a value in the FXML is equivalent to a value set from code.
Related
When I define a code for a class within the custom CSS of a post this is working however if I define the same code globally under my theme options-> Custom CSS this is not working.
.learndash-wrapper .ld-table-list a.ld-table-list-item-preview {
color: #13fff8;
}.
Therefore I have to go post by post adding this code to get the proper font color... and I would like to have it globally working.
Any idea why this happened?
First, check whether you have a typo or not. After verifying that you have entered class name properly. You can try out as,
.your-class-name{
color : #ffffff !important;
}
!important has the superpower to override previous CSS class and it's properties.
There are guidelines and defined the precedence of different CSS stylings.
Checkout,
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
Ask in the comment if required a more specific answer.
Check with the order of the css files loaded. If you have declared multiple css for same element latest class css will be applied. Along with that check the specificity of the css selectors. The selector with higher specificity will be affect the style.
How do I define a style in a parent component and then pass it to a child component e.g.?
<style>
.teststyle {
background-color: red;
width: 100px;
}
</style>
I thought if I did not use scoped the .teststyle would be available to the child, but it didn't work for me.
I can pass the style to use in a v-bind:style command using props cannot find a way to pass (or make available) for use with v-bind:class.
The child component is for re-use by many parent components each parent component with different style/class attributes each with different properties.
In one example the child component is a generic table and it needs things like column widths, cell colors etc.
In another instance the child component is a grid css layout and that needs no, columns, column layout etc.
What I normally do is I try to design the component as simply and cleanly as possible:
Give the root element a sensible class name (e.g. flyout).
Give child elements class names that use the root element's class name as a prefix (e.g. flyout-title, flyout-content, etc). Sometimes I'll abbreviate the root element's class name if it is long (as fly- or whatever).
<div class="flyout">
<div class="flyout-title">{{ title }}</div>
<div class="flyout-content"><slot/></div>
</div>
This is just my own class naming convention, but you can use whatever as long as it's consistent and unlikely to clash with other class names app-wide.
Now, when you use <flyout> as a child component and you want to style it with CSS, you give it a class name specific to the parent component. For example, if your parent component is app-menu then give the flyout the class name app-menu-flyout. Notice that this convention is the same as the aforementioned; always try to be consistent.
<flyout class="app-menu-flyout"/>
In your <style> section of the parent component, you can declare styles for the child component as follows:
.flyout.app-menu-flyout {
/* Root element */
}
.flyout.app-menu-flyout .flyout-content {
/* Child element */
}
I'm using selectors like this so that they are more specific and will override any styles defined on the child component itself. It'll also work regardless of the order in which the CSS ends up being (order may not be guaranteed by Webpack).
Note that this makes the parent and child components tightly coupled regarding the structure of the child component's template and the class names used. If you change the child component's template and/or class names, then you need to change the corresponding CSS in every other component that declares overriding styles for that component.
If you are using scoped CSS, then pay attention to how child components should be styled.
I want to set a class active on a div (part of a component) if a variable is true (workspace.active here) AND an ancestor element has class .home.
Something like:
<div [ngClass]="{'active': workspace.active && ':host-context(.home)', }">
Can I use somehow this pseudo selector :host-context in such an conditional expression for ngClass ?
Details:
I want to use same component in two use cases. Only some css properties should be different on the two cases. So I want to customize a css class set on a div on my component based on decision: "there is an ancestor home in the dom tree or not" - this should differentiate the two use cases.
I could do things like this in css:
:host-context(.home) .active {
background-color: #405976;
}
but then all selector combinations containing .active class should be combined also with :host-context and I I don't want to grow the complexity in css as it is already complex.
I would prefer to just set the class .active based on the condition. In css file !, not in code. (This is why :host-context exists in the end.)
In angular you should not make any logical decisions in the code based on the html content properties such as classes or attributes, but vice versa - you should render classes and attributes in html based on data bindings. That's the main idea of angular - rendering view based on data bindings. Component's code should not really care too much about view structure.
So, in this case if your class should be based on some external information you need to #Import() that data through data bindings into your component and then use component properties in the ngClass directive. Yes, it moves logic into the component instead of html/css, but that's where it's supposed to be anyway: in the model/controller code, not in the view markup. Also, this way it will be much more convenient to test such a component.
I Konw I can use setStyleSheet() to set style in Qt.But I encountered a problem,when I used setStyleSheet() twice first styles lost,which are set by first use of setStyleSheet().
For exmaple,
setStyleSheet("QLabel{color:red;}");
…………
setStyleSheet("QLabel{border-image:url(……)}")
When I set border-image,the red color property lost.
I tried to solve it by using
setStyleSheet(styleSheet()+QString("QLabel{border-image:url(……)}"));
but it was the same that only the border-image property existed.
Must I add every style property when I use setStyleSheet(),although that I set it before.
Thanks for bearing my poor written English.Any tips will be appreciated.
You can set stylesheets without QLabel tag:
setStyleSheet("color:red;");
After setting one stylesheet property, you can add another property like:
setStyleSheet( styleSheet().append(QString("border-image:url(……);")) );
This is in response to your comment on the accepted answer.
You can prevent overwriting stylesheets properties by setting the constant values to the parent (permitting that the parent's style isn't being changed dynamically as well). Only set the values that you change with C++ to the child item.
parentWidget->setStyleSheet( "QLabel#yourLabel { color:red; }" );
yourLabel->setStyleSheet( "QLabel { border-image:url(...) };" );
This will retain all of the parents properties that have been set on the widget when you change the widget's stylesheet.
Furthermore, this removes the case of a very large string, which is possible in the accepted answer. Frequent changes will inefficiently append the string with previously defined styles that will not be used.
By using double column for the second entry.
ui->pushButton_2->setStyleSheet(
"QPushButton{background-color:red;color:white}\
QPushButton::hover{color:black}");
I'm trying to figure out how to make svgs without giving every element a style attribute.
Two problems:
When referencing an external css file, the style appears correctly in a browser, but not in an image viewer. Is this normal/avoidable?
Most of my elements have class and id attributes, and the following css doesnt provide the desired effect, i.e., county 21015 doesnt have its fill overridden
.county
{
font-size:12px;
fill:#d0d0d0;
fill-rule:nonzero;
stroke:#000000;
stroke-opacity:1;
stroke-width:0.1;
stroke-miterlimit:4;
stroke-dasharray:none;
stroke-linecap:butt;
marker-start:none;
stroke-linejoin:bevel;
}
path#21015
{
fill:red;
}
If the fill isn't the one you want then there probably is something with higher specificity overriding the stylerule you want, such as an inline style attribute on that element, or some other rule affecting that element. You can also admit defeat by writing "fill: red !important" - that will work in the majority of cases.
Anyway, this is more of a css question than an svg question.
This is an alternative syntax...
Within the definition tags..
.fil0 {fill:#96989A}
Within the path tag(s) class="fil0"
Direct class references from the path to the definitions will override all others in my experience.