我正在将 Elm 与 mdgriffiths/elm-ui 结合使用,我真的很享受它。现在,我正在尝试创建一个居中的、包裹的元素行:
我可以做到这一点:
使用此代码:
button : String -> String -> Element Msg
button label url =
link
[ height (px 150)
, width (px 150)
, Border.width 1
, Background.color (rgb255 255 255 255)
]
{ url = url
, label =
Element.paragraph
[ Font.center ]
[ textEl [] label ]
}
row : Element Msg
row =
Element.wrappedRow
[ Element.spacing 25
, Element.centerX
, Element.centerY
, width (fill |> Element.maximum 600)
, Font.center
]
[ button "A" "/a"
, button "B" "/b"
, button "C" "/c"
, button "D" "/d"
]
Run Code Online (Sandbox Code Playgroud)
但是当我尝试将 Element.centerX 添加到我的按钮时
link
[ Element.centerX
, ...
]
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
我也尝试过Font.center没有成功,我不知道我还能尝试什么。
我不确定我是否遗漏了我应该使用的东西,或者整个事情是否需要重新安排,或者我是否只需要使用内置的 CSS 东西。
更新:
将我所看到的问题链接到 Ellie。
这个Github 问题对于这个问题很有用。恐怕你将不得不使用一些CSS(除非我遗漏了一些东西)。我之前用 elm-ui 发现过这个;有时它不能完全满足您的要求,您需要一些 CSS。
这对我有用(摘自上面链接中 AlienKevin 的帖子)。您需要将“marginLeft”和“marginRight”设置为“auto”。
module Main exposing (main)
import Element as E
import Element.Border
import Html.Attributes
box : String -> E.Element msg
box label =
E.paragraph
[ E.width <| E.px 200
, Element.Border.width 1
, E.htmlAttribute (Html.Attributes.style "marginLeft" "auto")
, E.htmlAttribute (Html.Attributes.style "marginRight" "auto")
]
[ E.text label ]
row : E.Element msg
row =
E.wrappedRow []
[ box "A"
, box "B"
, box "C"
]
main =
E.layout [] row
Run Code Online (Sandbox Code Playgroud)
(请参阅此处的艾莉。)