gpt4 book ai didi

css - 如何使用 CSS 填充和文本缩进将输入按钮拉伸(stretch)到可用宽度并使其文本居中?

转载 作者:太空宇宙 更新时间:2023-11-04 04:38:37 24 4
gpt4 key购买 nike

我有一个固定宽度为 20px 的输入按钮,使用 box-sizing: content-box

<input data-role="none" type="button" class="icon_text" value="click me" />

按钮的宽度仅使用填充设置。

示例:

.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;
width: 20px;
height: 20px;

虽然这工作正常,但我需要能够生成带有居中文本按钮的全屏。我可以或多或少地将按钮 padding-right 设置为 96% 但我不知道如何将文本居中,因为 text-indent 确实如此不取百分比值。

问题:
仅当按钮宽度固定且按钮长度使用填充设置时,是否可以通过 CSS 拉伸(stretch)按钮并使其文本居中?只是好奇是否有人有想法,如何做到这一点。

谢谢!

最佳答案

使用固定宽度时无法实现这一点。如果您愿意调整宽度,则可以使用以下样式。重要的部分是display:blockwidth:100%text-align:center

.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;
}

工作示例: http://jsfiddle.net/3bCB2/

关于css - 如何使用 CSS 填充和文本缩进将输入按钮拉伸(stretch)到可用宽度并使其文本居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15897108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com