使用 Vaadin 在按钮图像/图标中间设置标题

发布于 2024-12-08 17:32:06 字数 645 浏览 1 评论 0原文

在此处输入图像描述通过 CSS,我能够让 v.nativebutton 看起来像我想要的那样,但我不能'不让标题位于我的图标/图像的中间。附件是我将文本 -align: center 添加到 CSS 样式表时按钮的屏幕截图。知道如何将按钮的标题设置在图标图像的中间吗?我想在圆圈内显示“学生”标签?

CSS IM 使用:

.v-nativebutton-center-text .v-nativebutton-caption {
display: block;
white-space: normal;
text-align: center;
}
.v-nativebutton::-moz-focus-inner {
border: none;
padding: 0;
 }
 .v-nativebutton-center-text span {
  font-size: x-small;
  text-shadow: #fafafa 1px 1px 0;
}
.v-nativebutton-center-text img {
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 5px;

 }

enter image description hereThrough CSS i am able to get the v.nativebutton looking the way i want to, but i can't get the caption to be right in the middle of my icon/image. Attached is the screen shot of what the button looks like when i add text -align: center to my CSS style sheet. Any idea on how i can set the caption of the button to be right in the middle of my icon image? I want to show the 'Students' label inside the circle?

CSS IM USING:

.v-nativebutton-center-text .v-nativebutton-caption {
display: block;
white-space: normal;
text-align: center;
}
.v-nativebutton::-moz-focus-inner {
border: none;
padding: 0;
 }
 .v-nativebutton-center-text span {
  font-size: x-small;
  text-shadow: #fafafa 1px 1px 0;
}
.v-nativebutton-center-text img {
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 5px;

 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眼泪 2024-12-15 17:32:06

如果您调用了

button.addStyleName("center-text");

在您的本机按钮上,以下 CSS 将使文本居中:

以下 CSS 将使标题在换行符处居中:

.v-nativebutton-center-text .v-nativebutton-caption {
    display: block;
    white-space: normal;
    text-align: center;
}

If you have invoked

button.addStyleName("center-text");

on your native button, the following CSS will center the text:

The following CSS will center the caption accross line breaks:

.v-nativebutton-center-text .v-nativebutton-caption {
    display: block;
    white-space: normal;
    text-align: center;
}
迷路的信 2024-12-15 17:32:06

我对 vaadin 没有经验,所以如果我的建议与 vaadin 无关,我深表歉意,但无论如何我都会继续插话!

发布您拥有的代码(指定元素的 css 和 html)可能会有所帮助,但我认为我仍然可以提供帮助。

我建议将圆形元素的定位设置为相对,将标题的定位设置为绝对,然后将标题定位在中间。这是一种解决方案:

#circle {
    position: relative;
}

#caption {
    position: absolute;
    top: 75px; /* Whatever half of the circle is */
    left: 50%;
    width: 50px;
    margin: 0 0 0 -25px /* Sets margin-left to half of the width of the caption */
}

如果将 #circle 定位设置为相对,将 #caption 定位设置为绝对,它会将标题放置在圆圈的右上角,在其顶部。然后,您可以将“top”属性设置为圆的总高度的一半,以将其放置在 y 轴上圆的中心。如果将标题的 left 属性设置为 50%,然后给它一个等于其宽度一半的负左边距,它应该完美居中。确保将 #circle 设置为相对定位,否则标题可能绝对相对于整个页面定位,而不仅仅是相对于圆圈。

如果这不起作用,请告诉我,因为还有其他一些可能的解决方案。一种涉及使用 margin: 0 auto 来代替标题的居中。

我希望这有帮助!

I'm not experienced with vaadin so I apologize if my advice isn't relevant to vaadin, but I'll go ahead and chime in anyway!

It might be helpful to post the code you have (the css and html of the specified elements) but I think I can help still.

I would suggest setting the positioning of the circle element to relative and the positioning of the caption to absolute and then position the caption in the middle. Here's one solution:

#circle {
    position: relative;
}

#caption {
    position: absolute;
    top: 75px; /* Whatever half of the circle is */
    left: 50%;
    width: 50px;
    margin: 0 0 0 -25px /* Sets margin-left to half of the width of the caption */
}

If you set the #circle positioning to relative and the #caption positioning to absolute, it will place the caption in the top right corner of the circle, on top of it. You can then set the "top" property to half of the total height of the circle to place it in the center of the circle on the y-axis. If you set the caption's left property to 50% and then give it a negative left margin equal to half its width, it should center it perfectly. Make sure you set the #circle to relative positioning, or the caption might be positioned absolutely relative to the entire page as opposed to just the circle.

If this doesn't work, let me know because there are some other possible solutions too. One involves using margin: 0 auto for the centering of the caption instead.

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文