tipsy / j2html

Java to HTML generator. Enjoy typesafe HTML generation.
https://j2html.com/
Apache License 2.0
765 stars 136 forks source link

img width/height and h2 align="center" #148

Closed afarber closed 4 years ago

afarber commented 4 years ago

Good evening,

I have 2 questions for j2html 1.4.0 please:

When trying to translate the following piece of HTML:

        <H2 ALIGN="center">List of players</H2>
        <TABLE ID="ratingTable" CLASS="stripe" STYLE="min-width: 480px;">
            <THEAD>
                <TR>
                    <TH>Elo</TH>
                    <TH>Name</TH>
                    <TH>Photo</TH>
                </TR>
            </THEAD>
            <TBODY>
            </TBODY>
        </TABLE>

        <H2 ALIGN="center">List of games</H2>
        <DIV ID="gamesChart" CLASS="gchart"><IMG SRC="/images/loader.gif" WIDTH="60" HEIGHT="60"></DIV>
  1. How to create h2().withAlign("center")(method not found) ?

  2. And how to specify the img dimensions? There is no img().withWidth()

Here is what I've tried sofar:

        ContainerTag div = div(
                h2("List of players").withStyle("margin: auto;"),
                table(
                        thead(
                                tr(
                                        th("Elo"),
                                        th("Name"),
                                        th("Photo")
                                )
                        ),
                        tbody()
                ).withId("ratingTable").withClass("stripe").withStyle("min-width: 480px;"),
                h2("List of games").withStyle("margin: auto;"),
                div(
                        img().withSrc("/images/loader.gif").withWidth(60)
                ).withId("gamesChart").withClass("gchart")
        );

Thank you Alex

afarber commented 4 years ago

Nevermind - I have found the solution:

        ContainerTag div = div(
                h2("List of players").attr("align", "center"),
                table(
                        thead(
                                tr(
                                        th("Elo"),
                                        th("Name"),
                                        th("Photo")
                                )
                        ),
                        tbody()
                ).withId("ratingTable").withClass("stripe").withStyle("min-width: 480px;"),
                h2("List of games").attr("align", "center"),
                div(
                        img().withSrc("/images/loader.gif").attr("width", 60).attr("heigh", 60)
                ).withId("gamesChart").withClass("gchart")
        );