what if I need to modify bower contents? - bower

Please bear with me, I'm having a little trouble wrapping my head around this one...
On face value I know this questions seems foolish. The answer us you DON'T modify your bower contents because anything you do is going to be overwritten each time the bower updates and you would have to reimplement the changes over and over.
But if the situation effectively requires that I modify the CSS stylesheet that styles one of my bower components how do I handle this?
The only solution that I can come up with would be to have my custom stylesheet style the same components, make sure it is called after the original bower stylesheet, and let my alterations cascade over the initial styling.
This will work fine for certain attributes (color, etc) but what about more "incremental" attributes? For example lets say the bower gives an item a left margin of 5px, but I set it to 2px.
Would my style cascading on top get negate the initial one or would they combine to give me a margin of 7px?
If they are added together does that mean I should reset these bower item attributes in the CSS reset at the top of my custom style sheet?
Sorry if this question is dumb or way off base, I just don't understand how I should handle this.

CSS properties are not cumulative. They don't add together. If a property is set in multiple places, the property with the most specific selector wins and the rest are ignored. You can override properties set before by re-specifying them with a higher or equal specificity.
The correct way in this case is probably to override the few styles you need in your own stylesheet that is included after the component's stylesheet, as you said.

Related

Load Angular Material before own styles

We have an Angular project, with Material and we're having some issues with overriding styles.
For example, if we want to change the border-radius globally on <mat-card>, we currently need to add important to the styles:
.mat-card { border-radius: $some-var !important; }
This seems to me to be caused by the material styles loading after our own custom styles. At least according to "traditional" CSS standards. So usually you could just change the load order around, and the last loaded styles would overwrite the previous.
Is there a way to achieve this? Or how are we supposed to style these kinds of elements, without adding !important all over?
You are not really supposed to "style these kinds of elements" - that's not what Angular Material is about. But some customization can be done - and a guide is available: https://v6.material.angular.io/guide/customizing-component-styles.
You especially need to understand how style is encapsulated and dynamically applied. You can control when the global Angular Material style sheet is loaded in the "traditional" way, but you cannot control when all component style is applied because some of it is dynamic. If you hope to completely restyle everything - you should probably consider a different library as it is not always merely a matter of redefining class properties.

Custom scrollbars for <vaadin-combo-box> , impossible?

I'm using vaadin-combo-box and I have a problem. I have no clue how to customize look and feel of scrollbars for the dropdown. I read about styling parts and I know how to do it but this seems to be impossible. Cant figure out the way to select #scroller element because it has been design not to be a "part" to style. However that is the only way I can think of to apply custom style to dropdown scrollbars. How can that be accomplished?
Thanks in advance for help.
#Update
Turns out that as of today there is no way of having customized styling on scrollbars for vaadin-combo-box component. Element responsible for scrolling resides inside contents shadow DOM and is inaccessible from outside nor its going to inherit style implemented on the parent part [part="content"]
The dropdown part is called vaadin-combo-box-overlay, see: https://vaadin.com/components/vaadin-combo-box/html-api/elements/Vaadin.ComboBoxOverlayElement And it is available for styling.
This allows to style the dropdown to some extent, but there is additional shadow root, that prevents to apply e.g. ::-webkit-scrollbar styles on #scroller element.
So the last option would be to make a copy of the vaadin-combo-box html file in right place in frontend directory. It happens so that that file will be used instead of the one coming from webjar. Then you can edit that html file directly. Of course this means that if there are changes in future versions of vaadin-combo-box, you need to copy again, re-apply changes

Actionscript: Position elements one after another automatically

Is it possible to make Sprites position themselves one after another automatically.
Similar to display:display-block in CSS.
For example i'm adding Sprites to some parent in a row, the way they are in xml skin file and they are automatically position themselves next to each other.
Is there an event, which tells that a child were added to the parent?
I could implement some extended Sprite, to position pushed elements automatically, by calculating where the last element is located?
Why the hell Actionscipt doesn't have something like CSS in it? It's a pain in the ass to build UI inside it, compared to HTML...
Madness...
In case of "raw" ActionScript you should either search for an appropriate library or do it your self. ActionScript doesn't define any CSS like logic.
On the other hand Flex does, but you will not find any CSS that let you define layout. CSS is used to modify visual appearance of containers and components in Flex. Layout is usually done with the layout property of the container classes provided by Flex. For example yo can use a Group and set its layout property to an instance of HorizontalLayout or VerticalLayout. This will automatically position all child components of the group either in x or in y direction. In case of using Flex you cannot use sprites directly, but there are many components you can use. Maybe there is one for your purposes.
See the Flex API documentation. The spark.components package will be a good starting point.

jQueryUI draggable sets "position: relative" on my draggable divs

I'm having an odd problem with jQuery draggable this morning, I wonder if anyone else has come across this.
I have many small divs inside a large div. They are absolutely positioned: "position:absolute" in CSS for their class, with the actual position itself calculated and set in JS on demand.
Now I'm adding functionality to allow these divs to be draggable.
But, as soon as I make one draggable, it is given "position:relative" directly on the element, which as you might imagine, seriously messes up the on screen position.
Does anyone know why it changes the "position" like this or how to tell it not to?
EDIT:
Just realised there is a rather obvious answer staring me in the face - !important on my position:absolute! This seems to fix it. BUT I'm still interested if anyone knows why it sets "position: relative" like this (and doesn't either make it configurable or check first if it needs position)...I'm wondering what problems I've just stored up for myself ;-)
"I came across the same problem today. The reason was I was applying draggable() on a dynamically created element. I was 'later' appending it to dom. The element should be in dom when you apply draggable() (if style is being applied by a class). In short, when it finds no position attached with the element , it adds relative." - Jashwant
Firs do: .append(jElement) Then: jElement.draggable()
For some reason Jashwant put his answer in the comment to the question. So I thought it will be convenient to other to repost it here.
It also happened to me, but only on Chrome. Reason?
It was like this:
$("#div-popup").draggable({ handle: ".top", containment: 'document'});
Then I removed the containment parameter, like this:
$("#div-popup").draggable({ handle: ".top"});
So it's about the Browser (Chrome in this case), which sets position to Relative when you specify which containment the element will be draggable.
in my case it seems to be a race condition between the stylesheets and javascript loading...
i realized i'd made the mistake of including the stylesheets AFTER the javascript in the document head. they should be included BEFORE the javascript because $(document).ready() does not account for the CSS being loaded by the browser: https://stackoverflow.com/a/1324720/3633109

How to set a border on a Vaadin component?

I would like to programmatically set a border around a Form component in Java. How can I do this without having to edit the css style sheet?
You could wrap the form with a Panel component, which has a border defined already. Otherwise, not much alternatives than just using CSS.
One option, if you wish to stay inside the server environment, is to use the CSSInject add-on and add the border using that (you still need to write CSS, but you can do it on the server in a Java file and not inside a regular CSS file).
Vaadin Flow — Style::set to specify CSS
In Vaadin Flow (Vaadin versions 10 and later), you can conveniently set CSS for a widget or layout programmatically. No need to edit separate CSS files, even though styling with CSS files is the recommended way.
On your widget/layout, call getStyle to retrieve the Style object.
On that Style object, call set to pass the name and value of your CSS property.
For example, I find setting a bright colored border on my nested layouts quite helpful for debugging.
myVerticalLayout.getStyle().set( "border" , "6px dotted DarkOrange" ) ;
You can see this in action with this screenshot on my Answer to another Vaadin question here:

Resources