Java 我们如何调整 p:commandbutton 的大小或宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20905179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:12:09  来源:igfitidea点击:

How can we adjust p:commandbutton size or width

javajsf-2primefaces

提问by Sarz

My working environment is: Primefaces 4.0 with JSF 2.0 My aim is to set width of command button same in the form. I find style="font-size:10px"to set button's font size which is changing button's label size. I want to change button's size

我的工作环境是:Primefaces 4.0 和 JSF 2.0 我的目标是在表单中设置相同的命令按钮宽度。我发现style="font-size:10px"设置按钮的字体大小正在改变按钮的标签大小。我想改变按钮的大小

采纳答案by Adarsh

You can use the style attribute in the commandButton with the css properties width and height.

您可以将 commandButton 中的 style 属性与 css 属性 width 和 height 一起使用。

<p:commandButton id="button" value="Click"                              
                 actionListener="#{myBean.doAction}" 
                 style="width:100px;height:100px"/>

To set the same value for all the commandButtons on a page,add the following css to your jsf page.

要为页面上的所有命令按钮设置相同的值,请将以下 css 添加到您的 jsf 页面。

       .ui-button{
            width:100px;
            height:100px;
        }

回答by rekiem87

For that you have to play with the CSS, for example, i don't like that much space between buttons and their borders (it looks so big when are 2 or three buttons side by side, or they look bigger with text surround them), so, I first make the font smaller (the old font-size: .8em) and then a override the padding of the button (yes, the padding is huge in the buttons, at least for me), something like:

为此,您必须使用 CSS,例如,我不喜欢按钮与其边框之间的太大空间(当 2 或 3 个按钮并排时看起来很大,或者它们看起来更大,周围有文字) ,因此,我首先将字体变小(旧字体大小:.8em),然后覆盖按钮的填充(是的,按钮中的填充很大,至少对我而言),例如:

.ui-button-text-only .ui-button-text {
    padding: .1em .5em;
}