I have a 'masonry' like grid on my website, which I display using *ngFor.
The grid blocks looks like the follow:
T T T
S A S
T S T
where T - stands for Tall blocks, S - short blocks, A - special section with a tall blocks height.
I'm trying to create a a grid which will be automatically populated using ngFor but using the grid schema.
For example:
T T T
S T S
T S T
and continue following the format ->
T T T
S T S
T S T
T T T
S T S
T S T
T T T
S T S
T S T
and so on, using the first three rows as an example, tall or short blocks specified by class only. So my questions is, which is the best way to check all this conditions in order to display them in the following format?
To get the effect you want, you will need to leverage css to create a masonry layout.
The best way is to use css column-count, but you will need to transpose your array so that each row of your data represents a column.
This example utilises ngClass to provide an object where the keys are CSS classes that get added when the expression given in the value evaluates to true.
masonry.component.ts
export class MasonryComponent {
wall = [['T', 'T', 'T'], ['S', 'A', 'S'], ['T', 'S', 'T']];
constructor() { }
transpose(arr: any[]){
return arr.map((col, i) => arr.map((row) => row[i] ));
}
}
masonry.html
<div class="wall" >
<ng-container *ngFor="let blockCol of transpose(wall)">
<div *ngFor="let block of blockCol" class="block" [ngClass]="{
'tall' : block === 'T',
'short': block === 'S',
'special': block === 'A' }">{{ block }}</div>
</ng-container>
</div>
masonry.css
.wall {
width: 170px;
column-count: 3;
}
.block {
width: 50px;
border: 1px solid black;
}
.tall { height: 50px; }
.special { height: 50px; }
.short { height: 25px; }
Related
I know this seems like a basic question, but despite all the great writings about sass and bem I'm missing how this inheritance works with nesting. Maybe someone here can clarify.
For example, a simple nav with links and active links:
.Header {
padding: 1rem;
&__nav {
display: flex;
align-items: center;
&-link {
#include fonts.bold;
font-size: 1.15rem;
&--active {
color: red;
}
}
}
}
And then this component:
const NavLink = props => (
<Link
{...props}
getProps={({ isCurrent }) => ({
className: isCurrent ? "Header__nav-link--active" : "Header__nav-link",
})}
/>
);
const Header = () => {
return (
<header className="Header">
<div className="Header__nav">
<NavLink to="/app/A">PAGE A</NavLink>
<NavLink to="/app/B">PAGE B</NavLink>
<NavLink to="/app/C">PAGE C</NavLink>
</div>
</header>
);
};
PROBLEM
Links that are not active - Header__nav-link get the font settings but the --active link does not. Is the "correct" way to do this by adding the base class to the markup along with active?
Like this: className="Header__nav-link Header__nav-link--active"
Yes, the correct way is what you described. Modifiers in BEM are intended to be used with a block class to alter it in some way from the base. If you think about it, a modifier class cannot be by itself because it has no defined block to modify.
I want to color grid lines, depending on a condition.
I try this:
Java:
gridEtudiant.setClassNameGenerator(t -> {
if (t.getEtud_numero().startsWith("2")) {
return "error_row";
}
return "";
});
Css:
td.error_row {
background-color: red;
}
HTML
<td id="vaadin-grid-cell-1" tabindex="0" role="gridcell" part="cell body-cell" first-column="" reorder-status="undefined" aria-selected="false" class="error_row" style="width: 100px; flex-grow: 1; order: 10000000;"><slot name="vaadin-grid-cell-content-1"></slot></td>
We can see the 'class="error_row"' but it's not colored in red.
Vaadin version is 13.0.1
Your java code looks good.
Make sure you have a html file like webapp/frontend/styles/shared-styles.html containing something like:
<dom-module id="my-grid-theme" theme-for="vaadin-grid">
<template>
<style>
[part~="cell"].error_row {
background: red;
}
</style>
</template>
</dom-module>
If you then have your Layout containing the grid annotated with #HtmlImport("frontend://styles/shared-styles.html") (which you already seem to have as your custom css class is already applied) it should work.
Example:
grid.addColumn(Customer::getFirstname).setHeader("Firstname");
grid.addColumn(Customer::getLastname).setHeader("Lastname");
grid.addColumn(Customer::getEmail).setHeader("Email");
grid.setClassNameGenerator(customer -> {
if (customer.getFirstname().equals("Marco")) {
return "error_row";
} else {
return "";
}
});
becomes:
I have a circle+arrow next to a text in a CTA button and i'd like both to change color at the same time when hovering over either of them. Right now when hovering over the text the arrow does not change color, not sure how to write the :
<div class="cta-div">
<a class="cta-btn" href="#" role="button">SAVE NOW <i class="fa fa-
chevron-circle-right " style="font-size:34px;color:#efd43d; vertical
-align:middle; padding:0 0 3px;"></i></a>
</div>
sass rule:
.cta-btn, .fa-chevron-circle-right {
&:hover {
color: $btn-bkg-hover-color !important;
}
}
I have set this up and working in a fiddle: https://jsfiddle.net/roob/9Lsjstf7/1/
Any help is appreciated. If this is a duplicate post then please post a link.
You do not hover on them separately - you just hover on the anchor and when you do that you also hover the child so:
.cta-btn:hover, {
color: #e8e2bb !important;
.fa-chevron-circle-right {
color: #e8e2bb !important;
}
}
Not sure about the !important ... left it as you may need it for some reason.
I would like to use a kendo drop-down list, which has a fixed size since is constrained by other fields in the page, but when it shows the drop-down items of the list, the drop-down area should resize to the maximum length of the items. Sort of fixed width for the item displayed, but auto width for the drop down list.
Something like
|my choice | <-- fixed width displayed on the page
|next choice |
|previous choice | <-- dropdown area to select another item
|dummy |
Is this possible through CSS or drop-down list properties set through jQuery?
You can set the width of a DropDown List both using a CSS or using a method.
If the id of you DropDownList is my-dropdown then you should write:
Using CSS
#my-dropdown-list {
width: auto !important;
}
NOTE: We have appended -list to the original id. The "!important" is important since you want to overwrite original width definition.
Using a method
$("#my-dropdown").data("kendoDropDownList").list.width("auto");
In addition to use "auto" for getting the width automatically adjusted to the text, you can use a fixed width:
#my-dropdown-list {
width: 300px !important;
}
or:
$("#my-dropdown").data("kendoDropDownList").list.width(300);
The above answer didn't work for me. I have a the advantage of knowing that my dropdown is inside of a div.
<div class="myDivClass">
<select id="myDropDown"><option>First</option><option>Second></option></select>
<!--... other stuff in the div-->
<div>
I found that the span has the class k-dropdown so I added the CSS
.myDivClass span.k-dropdown {
width: 300px
}
What worked for me is to render an extra class on the base element:
<input .. class="ExtraLarge ..
Which produced:
<span style="" class="k-widget k-dropdown k-header ExtraLarge" ..
With this ExtraLarge class in place, this worked great in FireFox and Chrome:
span.k-dropdown.ExtraLarge
{
width:400px;
}
Using the following code to be the template of the kendo dropdownlist:
<div class="myDivClass">
<select id="myDropDown"><option>First</option><option>Second></option></select>
<!--... other stuff in the div-->
<div>
you will initiate the kendoDropDownList using jQuery as follows:
$("#myDropDown").kendoDropDownList().data("kendoDropDownList");
Now, to set this controller to take up the full width, what you have to do, is to set the width of the select element to 100%, or whatever is your desire.
e.g.:
<select id="myDropDown" style="width: 100%"><option>First</option><option>Second></option></select>
OR, is a css file:
#myDropDown { width: 100% }
If the id of you DropDownList is my-dropdown then you should write:
#my-dropdown-list {
width: auto !important;
-moz-min-width: 120px;
-ms-min-width: 120px;
-o-min-width: 120px;
-webkit-min-width: 120px;
min-width: 120px;
/*max-width: 210px;*/
}
Read the explanation below.
http://docs.telerik.com/kendo-ui/controls/editors/dropdownlist/how-to/auto-adjust-the-width
I wanted to know if I its possible to create a right click context menu which is activated on jqGrid's header row and has ability to add column to right or left or the column in question or hide the current column (without using ui-multiselect).
Any code in this respect would greatly be appreciated.
I suggest that you use contextmenu plugin which you would find in the plugins/jquery.contextmenu.js of jqGrid. In the answer and in this one for example are described how it could be used inside of jqGrid body. With the following code you can use it in the column header too:
var cm = $grid.jqGrid("getGridParam", "colModel");
$("th.ui-th-column").contextMenu('myMenu1', {
bindings: {
columns: function(trigger) {
var $th = $(trigger).closest("th");
if ($th.length > 0) {
alert("the header of the column '" + cm[$th[0].cellIndex].name +
"' was clicked");
}
}
},
// next settings
menuStyle: {
backgroundColor: '#fcfdfd',
border: '1px solid #a6c9e2',
maxWidth: '600px', // to be sure
width: '100%' // to have good width of the menu
},
itemHoverStyle: {
border: '1px solid #79b7e7',
color: '#1d5987',
backgroundColor: '#d0e5f5'
}
});
where menu myMenu1 are defined as
<div class="contextMenu" id="myMenu1" style="display:none">
<ul style="width: 200px">
<li id="columns">
<span class="ui-icon ui-icon-calculator" style="float:left"></span>
<span style="font-size:11px; font-family:Verdana">Choose columns</span>
</li>
</ul>
</div>
The demo demonstrate how it could be used: