【问题标题】:Align nested h:panelGrid in center将嵌套的 h:panelGrid 居中对齐
【发布时间】:2016-10-15 07:00:59
【问题描述】:

我正在尝试将一个 panelGrid 包含到另一个中,例如:

 <h:panelGrid id="A" border="1" columns="1" style="width: 100%; text-align:center; display: table">
            <h:panelGrid id="B" border="1" columns="3">
                <h:outputText value="Name : "></h:outputText>
                <h:inputText></h:inputText>
                <h:commandButton value="Add"></h:commandButton>             
            </h:panelGrid>              
        </h:panelGrid>

我已经生成了类似的html:

    <table id="j_idt1:A" border="1" style="width: 100%; text-align:center; display: table">
<tbody>
<tr>
<td><table id="j_idt1:B" border="1">
<tbody>
<tr>
<td>Name : </td>
<td><input type="text" name="j_idt1:j_idt3" /></td>
<td><input type="submit" name="j_idt1:j_idt4" value="Add" /></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

...尽管有 css text-align:center :P

,但 panelGrid "B" 总是左对齐

这就是我在 Eclipse Web 编辑器中所拥有的:

这就是我在 Firefox 中所拥有的:

所以我的问题是如何找到包含的 panelGrid(s)使用 eclipse wtp css 编辑器

谢谢

【问题讨论】:

  • 用浏览器开发工具查看客户端生成的html。然后尝试让它在那里工作并将CSS“转换”为正确的css以与jsf标签一起使用。内联样式通常不是正确的选择。对 html 子元素使用类和更具体的 css 规则是
  • 我想使用eclipse css编辑器为facelet创建居中的单元格;所以请保留eclipse标签,我需要它
  • @BalusC 谢谢我明白你想要最好的但我想知道如何使用 eclipse wtp css 编辑器工具包来解决这个问题;我不知道如何编辑我手动创建的每个网格表 :) 我知道这不是由 J2EE 引起的 :) 通常知道 J2EE 的人都知道相关的最接近的 Java Web 客户端技术,所以如果他们知道,我希望他们也能提供帮助他们通常如何使用 eclipse 处理这个问题;

标签: jsf jsf-2 panelgrid


【解决方案1】:

我认为您不会以正确的方式将 panelGrid 居中。这已在本网站上的其他几个问题中讨论过。 panelGrid 呈现为一个块级元素。 text-lign: center 只会将文本居中。您应该使用margin: 0 auto 来调整边距。

看看这些答案会有帮助:

How to align PanelGrid to center? JSF-Primefaces

Center a div in CSS - 不好的问题,好的答案

编辑: 我用您的页面做了一个快速项目,并且能够将所有 3 个 panelGrids 居中:

它的代码如下,(我添加了 10px 上边距而不是 0 以便更容易区分面板):

    <h:panelGrid id="A" border="1" columns="1" style="margin: 10px auto; width: 100%; ">                            
        <h:panelGrid id="B" border="1" columns="2" style="margin: 10px auto;  width: 460px">
            <h:panelGrid border="1" columns="1" style="margin: 10px auto;">
                <h:inputText style="width: 310px; " ></h:inputText>                             
            </h:panelGrid>
            <h:commandButton value="Add"></h:commandButton>
        </h:panelGrid>
    </h:panelGrid>

【讨论】:

  • 我有兴趣在上部表格单元格的中心对齐表格;我不知道如何在表格的单元格中找到表格:(问题是如果将裸命令按钮插入单元格,它可以与单元格中心对齐,但另一个网格面板不能:(
  • 附注我正在尝试使用eclipse web editor css editor来对齐;
  • 你能告诉我如何设置所有提到的与eclipse工具对齐;
  • @cbhogf 在 style 属性中用 'margin: 0 auto' 替换旧的中心样式。我无法测试它是否适用于弓,但我认为应该。
  • 问题是我不想手动编辑每个 panelGrid 这就是我使用 Eclipse Web 编辑器的原因;我试图用 eclipse css 编辑器控制边距,我有 请给我小费
猜你喜欢
  • 1970-01-01
  • 2011-04-12
  • 1970-01-01
  • 2011-11-25
  • 1970-01-01
  • 2018-05-21
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
相关资源
最近更新 更多