drew-kun
(Drew Kun)
September 21, 2024, 8:49pm
1
Hi everyone. Is there any way to align text to the right using markdown?
I currently use “<center>” as a backup option, but I would like the IPv6 addresses to be aligned to the right.
- type: conditional
entity: sensor.andrew_smartphone_ipv6_addresses
conditions:
- entity: sensor.andrew_smartphone_ipv6_addresses
state_not: 0
row:
card_mod:
style: |
:host {
--ha-card-border-width: 0px;
}
ha-markdown.no-header {
padding-top: 0px !important;
padding: 0 0 0 8px;
}
type: custom:hui-element
card_type: markdown
icon: 'mdi:numeric-6-box'
entity: sensor.andrew_smartphone_ipv6_addresses
content: |-
<ha-icon icon='mdi:numeric-6-box'></ha-icon> IPv6
{% for ipv6 in state_attr('sensor.andrew_smartphone_ipv6_addresses','ip6_addresses') %}
<center>{{ ipv6 }}</center>{{"\n"}}
{% endfor %}
Adding the following does not seem to work(
style:
text-align: right
drew-kun
(Drew Kun)
September 21, 2024, 9:06pm
2
So the question is basically, how to achieve something like this, using markdown or card_mod (or both):
Rudd-O
(Rudd-O)
September 22, 2024, 1:19am
3
i just use the HTML template card and stole styles from the Atomic Calendar Revive card.
WallyR
(Wally)
September 22, 2024, 6:37am
4
Markdown cards allow usage of HTML tags, so you could just put your values in a table and use align in the data fields.
This also allow you to use width on the table and the fields.
drew-kun
(Drew Kun)
September 22, 2024, 6:42pm
5
I thought so, but it seems like I do something wrong. I have tried multiple ways and only <center>
tag seems to work:
content: |-
<ha-icon icon='mdi:numeric-6-box'></ha-icon> IPv6
{% for ipv6 in state_attr('sensor.andrew_smartphone_ipv6_addresses','ip6_addresses') %}
<center>{{ ipv6 }}{{"\n"}}</center>
<p align="right">{{ ipv6 }}{{"\n"}}</p>
<td style="text-align: right;">{{ ipv6 }}{{"\n"}}</td>
<p style="text-align: right;">{{ ipv6 }}{{"\n"}}</p>
<div style="text-align: right;">{{ ipv6 }}{{"\n"}}</div>
{% endfor %}
Console:
I am probably misunderstanding the way markdown works. It seems that it already adds one <p>
tag when adding text in content:
(see the looong green marker). Therefore, I guess there should be some key-value to privide this style into that default <p>
tag in markdown?? (not sure)…
I am not a programmer, so not sure how to do it with HTML tags (or any other way). Or at least let me know what am I doing wrong…
WallyR
(Wally)
September 22, 2024, 6:49pm
6
No idea with the p-tag, but tables work well.
Here is an example from another thread.
Markdown cards can do a lot, if it does not need to be able to input values.
type: markdown
title: rainfall
content: |
<table width=100%>
<tr><td align_left><ha-icon icon="mdi:weather-cloudy"></ha-icon> Year</td><td align=right>{{ states('input_number.rainfall_yearly')|float(0)|round(2, 'common') }}</td></tr>
<tr><td align_left><ha-icon icon="mdi:weather-cloudy"></ha-icon> Month</td><td align=right>{{ states('input_number.rainfall_monthly')|float(0)|round(2, 'common') }}</td></tr>
<tr><t…
1 Like
drew-kun
(Drew Kun)
September 22, 2024, 8:47pm
7
Great, thank you for that example. Still no idea why other options did not work, but this works:
content: |-
<ha-icon icon='mdi:numeric-6-box'></ha-icon> IPv6
{% for ipv6 in state_attr('sensor.andrew_smartphone_ipv6_addresses','ip6_addresses') %}
<table width=100%>
<tr><td align=right>{{ ipv6 }}</td></tr>
</table>
{% endfor %}