【问题标题】:CSS - Rounded borders look like two buttons overlappingCSS - 圆形边框看起来像两个重叠的按钮
【发布时间】:2018-09-11 07:44:42
【问题描述】:

图片如下:

我的背景是白色的(你可以看到两个不同按钮的两个角之间的小间隙)。我在那张图片中有 4 个按钮,而不是 8 个重叠

按钮的背景都是黑色的,边框是白色的。按钮的高度为 40 像素。

我希望按钮具有圆角边缘/角,而不是黑盒子。该窗口正在 Java 上运行。

这是 CSS 代码:

.button{
-fx-font-size: 12pt;
-fx-text-fill: #ffffff;
-fx-background-color: #000000;
-fx-border-radius: 20px;
-fx-border-color: #ffffff;
-border: 0px;
}

【问题讨论】:

  • 你能提供那个窗口的所有css吗?
  • 请提供一个minimal reproducible example 来说明问题。
  • 谢谢大家,问题已经解决(添加-fx-background-radius)。图像中的窗口没有应用 css,所以一切都设置为默认值(因此您可以在按钮后面看到白色背景,在 fabian 的示例中背景是蓝色)

标签: java css javafx formatting


【解决方案1】:

假设适用于Buttons 的唯一样式是您定义的规则,设置-fx-background-radius 属性就足够了。按钮角上的白色“点”让我怀疑这一点。

以下应该可以实现所需的行为:

@Override
public void start(Stage primaryStage) {
    VBox vbox = new VBox();
    vbox.setStyle("-fx-background-color: blue;");

    for (int i = 0; i < 4; i++) {
        Button button = new Button(Integer.toString(i));
        button.getStyleClass().setAll("button");
        vbox.getChildren().add(button);
    }

    Scene scene = new Scene(vbox);
    scene.getStylesheets().add("style.css");
    primaryStage.setScene(scene);
    primaryStage.show();
}

style.css

.button {
    -fx-font-size: 12pt;
    -fx-text-fill: white;
    -fx-background-color: black;
    -fx-pref-width: 200px;
    -fx-pref-height: 40px;
    -fx-min-height: -fx-pref-height;
    -fx-max-height: -fx-pref-height;
    -fx-background-radius: 20px;
    -fx-border-radius: 20px;
    -fx-border-color: white;
}

【讨论】:

  • 非常感谢您的帮助!正是 -fx-background-radius 有助于去除多余的角并使按钮看起来很圆
猜你喜欢
  • 2016-07-29
  • 1970-01-01
  • 2013-07-07
  • 1970-01-01
  • 2016-05-07
  • 2021-12-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多