如何将输入按钮拉伸到可用宽度并将其居中';使用CSS填充和文本缩进来填充文本?
我有一个固定宽度为20px的输入按钮,使用如何将输入按钮拉伸到可用宽度并将其居中';使用CSS填充和文本缩进来填充文本?,css,input,padding,text-alignment,Css,Input,Padding,Text Alignment,我有一个固定宽度为20px的输入按钮,使用框大小:content-box <input data-role="none" type="button" class="icon_text" value="click me" /> } 虽然这样做很好,但我需要能够生成一个带有居中文本按钮的全屏。我可以或多或少地将按钮padding right设置为96%,但我不知道如何将文本居中,因为text indent不采用百分比值 问题: 只有在按钮宽度固定、按钮长度使用填充设置的情况下,才可以通
框大小:content-box
<input data-role="none" type="button" class="icon_text" value="click me" />
}
虽然这样做很好,但我需要能够生成一个带有居中文本按钮的全屏。我可以或多或少地将按钮padding right
设置为96%
,但我不知道如何将文本居中,因为text indent
不采用百分比值
问题:只有在按钮宽度固定、按钮长度使用填充设置的情况下,才可以通过CSS拉伸按钮并将其文本居中吗?只是好奇,如果有人有想法,怎么做
谢谢 使用固定宽度时无法实现这一点。如果您愿意调整宽度,以下样式将起作用。重要的部分是
显示:块
,宽度:100%
,文本对齐:中心
.icon_text {
border: 1px solid #aaa;
border-radius: .7em;
-moz-border-radius: .7em;
-webkit-border-radius: .7em;
color: white !important;
font-size: 16px;
font-weight: 800;
cursor: pointer;
background-color: #7EB238;
background-image: url("p.png");
background-image: url("p.png"), -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(rgba(52,109,28,1)), color-stop(rgba(52,109,28,0) )), -webkit-gradient(linear, left top, left bottom, from( #9ad945 ), to( #7eb238 ));
background-image: url("p.png"), -webkit-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -webkit-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), -moz-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -moz-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), -ms-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -ms-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), -o-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -o-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), radial-gradient(ellipse at center, rgba(52,109,28,1) 67%, rgba(52,109,28,0) 69%), linear-gradient( #9ad945, #7eb238 );
background-attachment: scroll, scroll, scroll;
background-repeat: no-repeat, no-repeat, no-repeat;
background-position: -100px 50%, 7px 50%, center center;
background-size: 864px 18px, 20px 20px, auto auto;
-webkit-background-size: 864px 18px, 20px 20px, auto auto;
background-clip: content-box, content-box, padding-box;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
text-indent: 2.1em;
padding-top: 6px;
padding-bottom:7px;
padding-left: 7px;
padding-right:92px;
height: 20px;
display: block;
width: 100%;
text-align: center;
}
工作示例:是的,那就行了。现在,我无法使用它,因为我正在使用按钮
width
(设置为20px)和box size:content box
(请参阅)裁剪背景精灵(p.png)。诀窍是找到另一种方法来剪辑精灵,这样宽度仍然可用。
.icon_text {
border: 1px solid #aaa;
border-radius: .7em;
-moz-border-radius: .7em;
-webkit-border-radius: .7em;
color: white !important;
font-size: 16px;
font-weight: 800;
cursor: pointer;
background-color: #7EB238;
background-image: url("p.png");
background-image: url("p.png"), -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(rgba(52,109,28,1)), color-stop(rgba(52,109,28,0) )), -webkit-gradient(linear, left top, left bottom, from( #9ad945 ), to( #7eb238 ));
background-image: url("p.png"), -webkit-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -webkit-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), -moz-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -moz-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), -ms-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -ms-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), -o-radial-gradient(center, ellipse cover, rgba(52,109,28,1), rgba(52,109,28,0) ), -o-linear-gradient( #9ad945, #7eb238 );
background-image: url("p.png"), radial-gradient(ellipse at center, rgba(52,109,28,1) 67%, rgba(52,109,28,0) 69%), linear-gradient( #9ad945, #7eb238 );
background-attachment: scroll, scroll, scroll;
background-repeat: no-repeat, no-repeat, no-repeat;
background-position: -100px 50%, 7px 50%, center center;
background-size: 864px 18px, 20px 20px, auto auto;
-webkit-background-size: 864px 18px, 20px 20px, auto auto;
background-clip: content-box, content-box, padding-box;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
text-indent: 2.1em;
padding-top: 6px;
padding-bottom:7px;
padding-left: 7px;
padding-right:92px;
height: 20px;
display: block;
width: 100%;
text-align: center;
}