Giter Site home page Giter Site logo

Comments (4)

AlienKevin avatar AlienKevin commented on August 15, 2024 3

I encountered this similar issue when trying to center an input slider in a column. A simple workaround to center one element in a column is:

E.column
        []
        [ ......
        , E.el
            [ E.htmlAttribute (Html.Attributes.style "marginLeft" "auto")
            ,  E.htmlAttribute (Html.Attributes.style "marginRight" "auto")
            ]
            yourElementHere
        , ......
        ]

Also remember to do

import Element as E
import Html.Attributes

in the header.

I also extracted out a function for centering an element:

center : E.Element msg -> E.Element msg
center element =
    E.el
        [ E.htmlAttribute (Html.Attributes.style "marginLeft" "auto")
        ,  E.htmlAttribute (Html.Attributes.style "marginRight" "auto")
        ]
        element

so the above example can be simplified as:

E.column
        []
        [ ......
        , center
          yourElementHere
        , ......
        ]

If you have many elements that needs to be centered, I created this helper function:

centerAll : List (E.Element msg) -> List (E.Element msg)
centerAll elements =
    List.map
    center
    elements

Use centerAll like so:

E.column
        []
        ( centerAll
        [ element1
        , element2
        , element3
        , element4      
        ])

To preserve the spacing of the row/column, you can use centerList:

centerList : List (E.Element msg) -> List (E.Element msg)
centerList elements =
    let
        length =
            List.length elements
    in
    List.indexedMap
        (\index element ->
            if index == 0 then
                E.el
                    [ E.htmlAttribute (Html.Attributes.style "marginLeft" "auto") ]
                    element

            else if index == length - 1 then
                E.el
                    [ E.htmlAttribute (Html.Attributes.style "marginRight" "auto") ]
                    element

            else
                element
        )
        elements

from elm-ui.

alexkorban avatar alexkorban commented on August 15, 2024 3

#unexpected

from elm-ui.

eelcoh avatar eelcoh commented on August 15, 2024 1

Bit late to this one, but had the same problem. Found out that the culprit is the CenterX attribute on the element (not the row). Remove that one, and the row will align left. Or wrap it in an Element.el []

from elm-ui.

simvux avatar simvux commented on August 15, 2024

Another temporary workaround that doesn't require writing and importing css (but might be a bit more hacky) is if you have a Browser.Events.onResize subscription you could do something like

 (if m.window.width < 1100 then
            column
         else
            row) [] <| none
       

from elm-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.