简体   繁体   English

GWT标签对齐方式和CSS

[英]GWT Label alignments and CSS

I am having some trouble with GWT Labels and html/css. 我在使用GWT标签和html / css时遇到了一些麻烦。

I have a horizontalPanel, and I am trying to align the 2 labels so that each 1 is on an end of the Horizontal Panel 我有一个horizo​​ntalPanel,并且我试图对齐2个标签,以便每个标签位于“水平面板”的一端

1) [Label 1      --~500px--      Label 2]

However, it seems that the 500 px is divided up into 250px each for a label, and theres a white space. 但是,似乎将500 px分成一个标签每个250 px,并且存在空白。 (First I tried to make it like like this) (首先,我试图使它像这样)

2) [Label 1 Label 2 --~500 whitespace px-- ]

but what happens is this 但这是怎么回事

3) [Label 1 -~250 whitespace px- Label 2 -~250px whitespace-- ]

I would like It to be like 2) so then i can set the HorizontalAllignment on the Horizontal Panel to ALIGN_JUSTIFY which would put on one each end. 我希望它像2),因此我可以将“水平面板”上的Horizo​​ntalAllignment设置为ALIGN_JUSTIFY,这将放在每一端。 I have no idea how to do it. 我不知道该怎么做。 I tried using display: inline but that doesnt seem to work as I hoped (it makes the border just go around the text but the whitespace is there) 我尝试使用display:inline,但是它似乎并没有按我希望的那样工作(它使边框仅绕过文本,但是有空白)

Here is the code I am messing around with .border is just (border: 1px solid Red) so i can visualize how the border and size is calculated 这是我正在处理的代码.border只是(border:1px纯红色),所以我可以看到边框和大小的计算方式

HorizontalPanel p = new HorizontalPanel();

p.setWidth("500px");


//p.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
//p.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_JUSTIFY);
Label l1 = new Label("Label 1");
Label l2 = new Label("Label 2");

l1.addStyleName("border");
l2.addStyleName("border");

p.add(l1);
p.add(l2);

I just threw this together from memory, give it a try and let me know if it works like you expect. 我只是将其从内存中放到一起,尝试一下,让我知道它是否如您所愿地工作。

HorizontalPanel p = new HorizontalPanel();

p.setWidth("500px");
p.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_JUSTIFY);

Label l1 = new Label("Label 1");
Label l2 = new Label("Label 2");

l1.addStyleName("border");
l2.addStyleName("border");

p.add(l1);
p.setCellHorizontalAlignment(l1, HasHorizontalAlignment.ALIGN_LEFT);
p.add(l2);
p.setCellHorizontalAlignment(l2, HasHorizontalAlignment.ALIGN_RIGHT);

If that doesn't work, have you tried setting text-align:right; 如果那不起作用,您是否尝试过设置text-align:right; in your css for the second label? 在你的CSS的第二个标签?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM