如何使用CSS向JavaFX元素添加边距? [英] How do I add margin to a JavaFX element using CSS?
问题描述
我有以下FXML片段:
I have the following fragment of FXML:
<VBox fx:id="paneLeft">
<TextField promptText="Password"/>
<Button fx:id="btnLogin" text="Login" maxWidth="10000"/>
<Hyperlink text="Registration"/>
</VBox>
是否可以使用CSS在Button
和Hyperlink
元素之间添加10px的间距?
Is it possible to add a spacing of 10px between the Button
and Hyperlink
elements using CSS?
提前谢谢!
推荐答案
看来你做不到. JavaFX目前对CSS的支持有限.
It seems you cannot. JavaFX has a limited support on CSS right now.
但是,某些脚本支持CSS padding和margins属性 JavaFX场景图对象.
However, the CSS padding and margins properties are supported on some JavaFX scene graph objects.
表示官方CSS参考指南.因此,解决方法可能是使用其他布局,例如另一个VBox:
says the official CSS Reference Guide. So workaround could be to use extra other layout, another VBox for instance:
<VBox fx:id="paneLeft" spacing="10">
<VBox fx:id="innerPaneLeft">
<TextField promptText="Password"/>
<Button fx:id="btnLogin" text="Login" maxWidth="10000"/>
</VBox>
<Hyperlink text="Registration"/>
</VBox>
更新:
找到了一些更完美的方法,但CSS仍然没有.
Update:
Found a bit more perfect way of doing it, but still not by CSS.
<?import javafx.geometry.Insets?>
<VBox fx:id="paneLeft">
<TextField promptText="Password"/>
<Button fx:id="btnLogin" text="Login" maxWidth="10000">
<VBox.margin>
<Insets>
<bottom>10</bottom>
</Insets>
</VBox.margin>
</Button>
<Hyperlink text="Registration"/>
</VBox>
这避免了定义不必要的额外布局.
This avoids defining an unnecessary extra layout.
这篇关于如何使用CSS向JavaFX元素添加边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!