layout-card =========== [![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) Get more control over the placement of lovelace cards For installation instructions [see this guide](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins). Install `layout-card.js` as a `module`. ```yaml resources: - url: /local/layout-card.js type: module ``` ## Usage ```yaml type: custom:layout-card layout: min_height: min_columns: max_columns: column_width: max_width: min_width: flex_grow: justify_content: ltr: cards: card_options: ``` ## Options - `` **Required** A list of lovelace cards to display. - `` are options that are applied to all cards. - `` The layout method to use. `auto`, `vertical` or `horizontal`. See below. Default: `auto`. - `` The minimum length of a column in `auto` layout. Default: `5`. - `` The minimum number of columns to use. Default: `1`. - `` The maximum number of columns to use. Default: `100`. - `` Width of columns. Default: `300px`. - ``, ``, `` Set the `max-width`, `min-width` and `flex-grow` CSS properties of the columns manually. Default: `column_width or 500px`, `undefined`, `undefined`. - `` Set the `justify-content` CSS property of the column container. Default: `center`. ## Layouts The basic concept of this card is that it takes a number of other cards, and places them in the browser window, just like lovelace does normally, but allowing you a bit more control. Since `layout-card` is a card in it self its area of effect will be limited to the width of a card, and thus you will (almost) always want to use it in [panel mode](https://www.home-assistant.io/lovelace/views/#panel-mode): ```yaml views: - title: My view panel: true cards: - type: custom:layout-card ... ``` ### `auto` layout The auto layout works in the same way as the default lovelace layout. It follows a simple process. - A number of columns are prepared based on the screen width and ``. - The number of columns is clamped between `` and `` - Cards have a `cardHeight`, which is calculated from their content. One unit is roughly 50 pixels tall. - Each new card is added to the first row which is less than `` units tall. - If all columns are taller than ``, the card is added to the shortes column. - Once all cards have been placed, any remaining empty columns are removed. ```yaml type: custom:layout-card cards: - type: entities title: 1 entities: - light.bed_light - type: entities title: 2 entities: - light.bed_light - type: entities title: 3 entities: - light.bed_light - type: entities title: 4 entities: - light.bed_light - light.bed_light - light.bed_light - light.bed_light - type: entities title: 5 entities: - light.bed_light - type: entities title: 6 entities: - light.bed_light - type: entities title: 7 entities: - light.bed_light - type: entities title: 8 entities: - light.bed_light ``` ![layout-card 1 - auto](https://user-images.githubusercontent.com/1299821/48088464-62312500-e202-11e8-8ccc-0ef6ac10ec2e.png) > Note: The same 8 cards will be used in the following examples and will be omitted for clarity. ### `horizontal` layout The horizontal layout calculates the number of columns just like the `auto` layout. It then places the first card in the first column, the second card in the second columns, and so on. Once it reaches the last column, it starts over from the first. ```yaml type: custom:layout-card layout: horizontal cards: - ... ``` ![layout-card 2 - horizontal](https://user-images.githubusercontent.com/1299821/48088463-62312500-e202-11e8-875a-5ff836069017.png) ### `vertical` layout The vertical layout calculates the number of columns just like the `auto` layout. It then places every card in the first column. ```yaml type: custom:layout-card layout: vertical cards: - ... ``` ![layout-card 3 - vertical](https://user-images.githubusercontent.com/1299821/48088462-62312500-e202-11e8-8e5e-7f4d1821eeb8.png) It's OK to think I'm out of my mind at this point. And if you don't, you probably will once I claim that this is probably the most useful layout. Still here? OK. Let me tell you about the `break`. ### `- break` Just add `- break` to the list of `` to make card placer move on to the next column for the next card. This is most useful in the `vertical` layout, but will work in the `horizontal` and `auto` layouts too. ```yaml type: custom:layout-card layout: vertical cards: - type: entities title: 1 ... - type: entities title: 2 ... - break - type: entities title: 3 ... - break - type: entities title: 4 ... - type: entities title: 6 ... - break - type: entities title: 7 ... ``` ![layout-card 4 - manual breaks](https://user-images.githubusercontent.com/1299821/48088461-62312500-e202-11e8-96ab-e4f560f8d4fc.png) ## Tweaking layouts - First of all `` and `` options, which can be used to force the number of columns displayed: ```yaml type: custom:layout-card layout: vertical min_columns: 7 cards: - ... ``` ![force-number](https://user-images.githubusercontent.com/1299821/68596569-be74f780-049b-11ea-97a7-1d591edf5a26.png) > Note: See how squeezing cards too tight will make them look weird? Keep this in mind, and don't send me bug reports about it. > Your toggles would pop out too if someone forced you into a 100 pixel box. - The width of columns can be specified either all together...: ```yaml type: custom:layout-card column_width: 200 cards: - ... ``` ![same-width](https://user-images.githubusercontent.com/1299821/68597185-d13bfc00-049c-11ea-8fd4-8d6327a9764a.png) - ...or as a list of column widths: ```yaml type: custom:layout-card column_width: [200, 300, 150] cards: - ... ``` ![varied-width](https://user-images.githubusercontent.com/1299821/68597348-1829f180-049d-11ea-917a-c97be3f1e561.png) If there are more column than values in the list, the last value in the list will be used for the remaining columns. - Values can be specified either in pixels or in percentages: ```yaml type: custom:layout-card column_width: 30% cards: - ... ``` ![percentage](https://user-images.githubusercontent.com/1299821/68598310-d4d08280-049e-11ea-8ea7-48d8b14ffef0.png) - Further tweaks can be made in the same way using `` and ``, but most of the time `` should be enough. - `` (single value or list) and `` (single value) can be used to tweak the CSS flexbox settings of the layout. See [this excellent guide](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) for more info. - `` will make the columns display from right to left instead of left to right. ## A few tips - `card_options` works really well together with [card-mod](https://github.com/thomasloven/lovelace-card-mod). - Layout-cards can be placed inside other layout-cards or in vertical-stack cards: ![stacked](https://user-images.githubusercontent.com/1299821/68598908-f0885880-049f-11ea-814f-b91ee6ee9eef.png) - [gap-card](https://github.com/thomasloven/lovelace-gap-card) can be used to leave a gap in the layout: ![gap](https://user-images.githubusercontent.com/1299821/68599474-eb77d900-04a0-11ea-9b89-f0d090c858b3.png) - The card list can be populated automatically using [auto-entities](https://github.com/thomasloven/lovelace-auto-entities) ```yaml type: custom:auto-entities filter: include: - domain: light options: type: light # Make sure to specify a card type for every filter - domain: climate options: type: thermostat exclude: - state: unavailable sort: method: name ignore_case: true card: type: custom:layout-card ``` ![auto-entities](https://user-images.githubusercontent.com/1299821/68600943-a86b3500-04a3-11ea-8d08-106e77262552.png) --- Buy Me A Coffee