What I’m Trying to Do:
I’m trying to style a ColumnPanel
(named content_panel
) in my Anvil app. The goal is to add visible CSS changes such as a bright orange border, rounded corners, shadow, padding, and a light background.
What I’ve Tried and What’s Not Working:
-
Using Roles:
- I defined a custom role in
theme.css
(e.g.,.anvil-role-custom-panel
) and assigned it tocontent_panel
via therole
property. However, the role doesn’t appear in the dropdown, and manually setting it in Python didn’t work.
- I defined a custom role in
-
Targeting the Panel in CSS:
- I used
.anvil-component-content_panel
intheme.css
to apply styles directly by the component name. This also didn’t apply the styles.
- I used
-
Inline Styling in Python:
- I applied styles via
self.content_panel.style = {...}
in Python. No visible changes occurred.
- I applied styles via
-
JavaScript:
- I added JavaScript in a
native.js
file to style thecontent_panel
usingdocument.querySelector()
. This approach didn’t show any errors but still didn’t apply the styles.
- I added JavaScript in a
Code Sample:
Here’s the Python code I used in my app:
from ._anvil_designer import Form1Template
from anvil import *
import anvil.js
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Inline style attempt
self.content_panel.style = {
"border": "3px solid #FF5733",
"border-radius": "20px",
"padding": "20px",
"box-shadow": "0px 4px 8px rgba(0, 0, 0, 0.2)",
"background-color": "#f9f9f9"
}
# JavaScript attempt
anvil.js.call_js("styleContentPanel")
Here’s the native.js
file:
function styleContentPanel() {
const contentPanel = document.querySelector('.anvil-component-content_panel');
if (contentPanel) {
contentPanel.style.border = "3px solid #FF5733";
contentPanel.style.borderRadius = "20px";
contentPanel.style.padding = "20px";
contentPanel.style.boxShadow = "0px 4px 8px rgba(0, 0, 0, 0.2)";
contentPanel.style.backgroundColor = "#f9f9f9";
}
}
Here’s the theme.css
entry I used:
.anvil-role-custom-panel {
border: 3px solid #FF5733;
border-radius: 20px;
padding: 20px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
background-color: #f9f9f9;
}
.anvil-component-content_panel {
border: 3px solid #FF5733;
border-radius: 20px;
padding: 20px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
background-color: #f9f9f9;
}
Additional Notes:
I’ve tried refreshing the Anvil editor, clearing browser cache, and ensuring no conflicting styles are overriding these. Despite these attempts, the content_panel
remains unaffected.
Any advice or insights would be greatly appreciated! Thank you in advance.