Is it possible to use image inside bootstrap-min.css
We are using a theme (modern) and some icons are controlled by bootstrap.
I would like to change the following line to use image.
.glyphicon-home:before{content:"\e021"}
Try this:
.glyphicon-home{
display:inline-block;
background-image:url('../images/YOUR_IMAGE.png');
width:20px;
height:20px;
}
Just clear the content parameter and add your own image using background. The rest of the styles (display:inline-block) should still inherit.
.glyphicon-home:before{
content: "";
background: url(IMAGEPATH) 50% 50% no-repeat;
}
Oh - and I wouldn't put it into bootstrap.min.css - add it to a stylesheet that is called later, or your theme's style.css
Related
I want to define all VaadinGrids in my Application with the component variant GridVariant.LUMO_ROW_STRIPES. I don't want repeat the definition on all grid instances as shown below.
grid.addThemeVariants(GridVariant.LUMO_ROW_STRIPES);
Is there any way to do this with a global configuration or something else?
I have tried so far to use the #Theme Annoation to define a theme variant. But this doesn't work.
As already mentioned in the comment, one approach is to create a subclass of Grid, apply the variant to it, and use it instead of the Grid class in your app.
Another option is to apply the CSS with which the variant is implemented to the Grid in your own theme. It's only 4 lines of CSS: https://github.com/vaadin/web-components/blob/master/packages/grid/theme/lumo/vaadin-grid-styles.js#L312-L316
Just remove the [theme~='row-stripes'] parts from the selector, and load that css into the Grid's shadow DOM e.g. by placing it in themes/your-app-theme/components/vaadin-grid.css
One option is to subclass Grid and add the variant in the constructor:
public class MyGrid extends Grid {
public MyGrid() {
addThemeVariant(GridVariant.LUMO_ROW_STRIPES);
}
}
Another option is to copy-paste the variant CSS to your own custom theme, and remove the host selector, so that that styles are not scoped to any variant:
frontend/themes/myapp/components/vaadin-grid.css:
[part~='row']:not([odd]) [part~='body-cell'],
[part~='row']:not([odd]) [part~='details-cell'] {
background-image: linear-gradient(var(--lumo-contrast-5pct), var(--lumo-contrast-5pct));
background-repeat: repeat-x;
}
If you're using Vaadin 24 (prerelease at the time of writing), you can use the new recommended way of styling (avoid injecting styles into the shadow root of the component):
frontend/themes/myapp/styles.css:
vaadin-grid::part(even-row-cell),
vaadin-grid::part(even-row-cell details-cell) {
background-image: linear-gradient(var(--lumo-contrast-5pct), var(--lumo-contrast-5pct));
background-repeat: repeat-x;
}
I have created a simple grid with one column:
public MyGrid() {
addComponentColumn(this::getIcon).setClassNameGenerator(i -> "icon-img");
setItems(/** some items */);
setClassName("sidebar-grid");
}
And I have a css theme called mangaTheme. I use it like this #Theme("mangaTheme"). In the mangaTheme folder I have styles.css file with the following content:
.icon-img {
padding: 0;
}
.sidebar-grid {
width: 102px;
margin: auto;
margin-left: -30%;
}
The sidebar-grid css properties are applied properly as the grid is moved, but the icon-img properties are not applied whatsoever:
The classnames are applied:
What am I doing wrong or missing? I have also read this guide: https://cookbook.vaadin.com/dynamic-grid-cell-styling
EDIT: After configuring my workspace as was mentioned in the answer this is the resulting structure, but it still does not seem to function properly.
What you're missing is that the cell <td> element is inside the shadow DOM of the vaadin-grid component, and thus cannot be styled with global CSS. To style parts of components that are inside the component's shadow DOM, you need to inject the CSS into the component.
In the Cookbook example, this is done through the themeFor parameter in the annotation that loads the stylesheet:
#CssImport(themeFor = "vaadin-grid", value = "./recipe/dynamicgridcellstyling/dynamic-grid-cell-styling.css")
In your theme folder, however, you can do the same thing by putting that CSS in a stylesheet called vaadin-grid.css in the components subfolder, i.e.:
themes/mangaTheme/components/vaadin-grid.css
Another thing you're missing is that the classname is applied to the <td> cell, but the padding is on the vaadin-grid-cell-content element slotted into the cell, not the cell itself, so you need to rewrite your selector:
.icon-img ::slotted(vaadin-grid-cell-content) {
padding: 0;
}
(The sidebar-grid CSS class works fine as-is because it's applied to the vaadin-grid root element, which is in the page's regular DOM.)
I'm new in vaadin development and i hope someone can help me. I just created a grid table with a model and everything works fine. But now, i want to change the background color of the selected row. I figure out, that i have to create a theme. I found this in the Vaadin Forum: https://vaadin.com/forum/thread/17867059/how-to-set-selected-row-opacity-in-vaadin-grid
This is what i have already done:
I created a html class with the code from the link. I called this class grid-selection-theme.html
I put this class into src/main/webapp/frontend/styles/grid-selection-theme.html
In the java file with the Grid, i added the import: #HtmlImport("frontend://styles/grid-selection-theme.html);
I added the theme to the grid: mygrid.addThemeName("grid-selection-theme");
Here is the code from the other thread in the forum:
<dom-module id="grid-header" theme-for="vaadin-grid">
<template>
<style>
:host(:not([reordering])) [part~="row"][selected] [part~="body-cell"]:not([part~="details-cell"]) {
background-color: rgba(255, 0, 0, .50);
}
</style>
</template>
</dom-module>
But it does not work.
This seems to work fine for me, what is your version of framework?
In case you are using Vaadin 14, you would need to place styles into .css file instead and import the file using #CSSImport
My style file gridStyles.css contains:
:host([theme~="grid-selection-theme"]) [part~="row"][selected] [part~="body-cell"]:not([part~="details-cell"]) {
background-color: red;
}
Class where grid is used has this import defined:
#CssImport(value = "./styles/gridStyles.css", themeFor = "vaadin-grid")
Grid has theme name added
I've change a host selector to reflect a theme attribute: in case you have multiple grids on the same page, then style will be applied only to the one having mygrid.addThemeName("grid-selection-theme");
Output looks like this:
Some coworkers and I are writing help documentation in HTML to be used with a JavaFX WebView panel. We want it to look consistent with the rest of the UI. Normally I would specify the default font in a CSS file, but the rest of the JavaFX application appears to use the default system UI font.
Is there any way to set this programmatically? I can pick Segoe UI by name in .css, but we want it to look correct regardless of platform.
Use
Font.getDefault().getName()
to get the defaults font name and just add it to the HTML file / String which is about to be added into the WebView.
example:
cssString = cssString + "html { font-family: '" + Font.getDefault().getName() + "';}";
Ofcause you should do it cleaner than this.
If I understood you completely you want a default font for the whole javafx part of your application. I suggest you do this:
Download a font of your own as .ttf and add it to the resources in your application.
Load the font with the static function Font.loadFont:
Font.loadFont(this.class.getClassLoader().getResource("fonts/YOURFONT.ttf").toExternalForm(), 10);
Now set the font to the root of the application. I suggest doing that with css as it is suggested here -> another stackoverflow answer: In your application.css add:
.root{ -fx-font-family: "YOURFONT"; }
After that you need to load the application.css file and set it on your scene:
scene.getStylesheets().add(this.class.getClassLoader().getResource("css/application.css").toExternalForm());
I believe that it is better if you are not dependent of the system on which your app is running, so pack the font in your application.
For the html you can do completely the same thing with normal css by providing a #font-face.
How can I draw a horizontal line in java gwt, something similar to the '< hr >' tag in HTML? I tried it by using
com.google.gwt.user.client.Element bottomLine = DOM.createDiv();
but that somehow doesn't work in IE...
You can use the HTML widget to add whatever html you want inside your page
HTML html = new HTML("<hr style=\"width:100%;\" />")
rootPanel.add(html); // or add it inside another widget
Or you can use css on Panel and define the border-bottom property (if you have a panel that spans the entire page).
Document.get().createHRElement()?