Horizontal rule

Hi everyone,

Is there a way to add a horizontal rule? Example:


I have to separate a title from a list and the horizontal line always seems to look nice for separating sections on a page. This was requested here.

I tried to simulate this by setting a label with a background color and changing its fontsize to 0, but the box is still to big to pass as a thin line.

You can use a custom HTML Form to make a custom component thatā€™s a <hr>:

image

https://anvil.works/ide#clone:VC4LF2U6ARGTEXRD=UFOGA4CEJT7HWGITWN7HIH6W

Youā€™ll probably want to style it to look more prominent.

image

2 Likes

Thanks @shaun! That is a great idea.

@shaun Iā€™ve never used custom components before. I canā€™t figure out how to start using this horizontal rule component in an app I made previously. Is it supposed to show up in the tool window somewhere so I can drag/drop?

To use a custom component from the app it is defined in, click on the arrow next to the Form in the App Browser and click ā€˜use as componentā€™. Then it will appear in the Toolbox:

image

Docs:

https://anvil.works/doc#-div-id-custom_components-custom-components-div-

To use a custom component from AppA in AppB, add AppA as a dependency in AppB. Use the ā€˜Dependenciesā€¦ā€™ dialog in AppB for this:

image

Youā€™ll get a window with an ā€˜Add a dependencyā€™ dropdown that shows all your apps. Select HorizontalRule and you should see HorizontalRule in the toolbox.

https://anvil.works/doc/#-div-id-app_dependencies-app-dependencies-div-

2 Likes

Thanks very much. This is fantastic.

Hello Friends:

I need a Horizontal Rule as well, but looking at the helpful instructions above, I might need additional guidance because the UI has changed.

So far, Iā€™ve added the Horizontal Rule as a standalone App, where I was notified that the teams needs to enable Python2. But what next when they do that? ā€“ Because the down-downs in the above screenshots seem unavailable to me. Perhaps itā€™s because my personal subscription tier does not permit that UI anymore.

I guess I need a 2022 version of the above.

Thank you in advance! :relaxed:

EDIT: Or perhaps I can simply use a Rich Text Box in Markdown mode, and specify three dashes (ā€”) to render a Horizontal Rule. That may or may not be the optimal (look & feel, performance, etc), and guidance and/or alternatives is always welcome.

Currebtly an irregular Anvil user here (but enthusiastic admirer).

The following may work:

  • use ā€œā€”ā€ in a rich text component
  • use canvas with height=1 (credit @stefano.menci)
  • use custom HTML component (this is likely described in the docs and on the forum).
1 Like

Here is a conversation about it

TLDR;

I created a role by adding the following to my native libraries:

<style>
.anvil-role-bottom_thin_border {
  border-bottom: thin solid;
}
</style>

Then I created a role called bottom_thin_border in the theme/role section of the IDE.

If you donā€™t restrict the role, you can then apply it to any component using the role drop-down in the appearance section of the component properties.

image

or via code

self.component.role = "bottom_thin_border"

2 Likes

@campopianoa Thank you for the options! Iā€™ll use the first option for now. I have to look into the Canvas option (Iā€™m unfamiliar with it), as well as the HTML custom component also unfamiliar with it. Again, thank you. :slight_smile:

@anthonys Thank you for the pointer. Iā€™m reading up on it now, as well. :slight_smile:

1 Like

Thank you. When I get a chance (soon), I walk through your example and see if I can get to understand roles, IDE theme, and then see if I see it in component role-dropdowns (via unrestricted). Thank you for the step-by-step! :slight_smile:

1 Like

of course, also addressing the original question, you might be in the BETA IDE.

To make a form a component you can click the three vertical dots next to the form name and select ā€œuse as componentā€.

1 Like

Ah, I see it now ā€“ Use as Component ā€“ after clicking a Forms Hamburger Menu. Thank you.

Now, I have learn how to add Horizontal Rule code to a new Form (or add whatever I might need, not just a Horizontal Rule).

But sticking with the Horizontal Rule for a moment to keep things simple, could these steps accomplish it:

  1. Create an new Form
  2. Drag in a Rich-Text-Box in Markdown mode
  3. Type three dashes (ā€”) in itā€™s Content attribute/field
  4. Finally, select Use as Component for that Form

Perhaps itā€™s a naive / newbie approach (and it may not be the best design pattern - I donā€™t know), but would it at least work? I guess Iā€™ll try it later (too afraid of messing up my current project. LoL).

1 Like

Looks like it definitely could!

1 Like

A post was split to a new topic: Labeled horizontal rule