Skip to content

How can I put background on div (pyreact)? #1101

Discussion options

You must be logged in to vote

ReactPy can include CSS styles but there a number of different ways to do so. The simplest way might be to do the following with html.style:

from reactpy import html, component, run

with open("path/to/stylesheet.css") as f:
    css = f.read()

@component
def app():
    return html.div(
        html.style(css),
        ...,
    )

run(app)

As you app grows you may need to consider splitting up your style sheets into different files. In that case you could serve them from a directory and load them with html.link:

from fastapi import FastAPI
from reactpy.backend.fastapi import configure

server = FastAPI()
server.mount("/static", StaticFiles(directory="static"), name="static")

@component
def 

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Archmonger
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@rmorshea
Comment options

Answer selected by rmorshea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants