gpt4 book ai didi

html - CSS 按钮未知居中

转载 作者:太空宇宙 更新时间:2023-11-04 03:23:32 25 4
gpt4 key购买 nike

好吧,我有一个按钮,我不知道为什么它会自己居中。我的第一个怀疑是在 css 中,但我使用/更改的任何类型的 alignposition 都不起作用。

这是 html 和 css。你可能会比我更快找到它。(如果有人感兴趣,这里还有 jsfiddle 链接:http://jsfiddle.net/takkun/63uktgyo/)

/* ROUNDED ONE */
.Gcheckbox {
/*CHANGES GRAY SQUARE DIMENSIONS*/
width: 16px;
height: 33px;
background: #ff0000;

/*GRAY SQUARE BACKGROUND FADER*/
background: linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
background: -webkit-linear-gradient(top, 0000ff 100%, 0000ff 0%, #ff0000 0%);
background: -moz-linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
background: -o-linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
background: -ms-linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0 );
margin: 0px auto;

position: relative;
}

.Gcheckbox label {
cursor: pointer;
position: absolute;
width: 10px;
height: 10px;

/*MAKES THE GREEN CIRCLE A CIRCLE*/
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
/********************************/

left: 3px;
top: 11.25px;

box-shadow: inset 0px 0px 0px rgba(239,239,238,1), 0px 0px 0px rgba(239,239,238,1);
-webkit-box-shadow: inset 0px 0px 0px rgba(239,239,238,1), 0px 0px 0px rgba(239,239,238,1);
-moz-box-shadow: inset 0px 0px 0px rgba(239,239,238,1), 0px 0px 0px rgba(239,239,238,1);

/*BEHIND GREEN CIRCLE BACKGROUND*/
background: -webkit-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: -moz-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: -o-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: -ms-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: linear-gradient(top, #0000ff 0%, #0000ff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0000ff', endColorstr='#0000ff',GradientType=1 );
}

.Gcheckbox label:after {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
content: '';
position: absolute;
width: 10px;
height: 10px;
background: #00bf00;

background: linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -webkit-linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -moz-linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -o-linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -ms-linear-gradient(top, #00ff00 0%, #00ff00 100%);

-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
bottom: 0px;
right: 0px;

-webkit-box-shadow: inset 0px 0px 0px #00ff00, 0px 0px 0px rgba(42,171,43);
-moz-box-shadow: inset 0px 0px 0px #00ff00, 0px 0px 0px rgba(42,171,43);
box-shadow: inset 0px 0px 0px #00ff00, 0px 0px 0px rgba(42,171,43);
}

/*CHANGE HOVER EFFECT OPACITY*/
.Gcheckbox label:hover::after {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
filter: alpha(opacity=30);
opacity: 0.3;
}

.Gcheckbox input[type=checkbox]:checked + label:after {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
opacity: 1;
}

input[type=checkbox] {
visibility:hidden;
}
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="styleCIRCLE.css" type="text/css">
<title>custom checkbox testing</title>
</head>
<body>


<!--styleCIRCLE -->
<div class="Gcheckbox">
<input type="checkbox" value="None" id="Gcheckbox" name="check" />
<label for="Gcheckbox"></label>
</div>



</body>
</html>

最佳答案

水平居中是因为包含的父元素.Gcheckbox有左右自动外边距,起到了元素水平居中的作用。

通过删除或注释掉该行,我们将使元素按照默认的从左到右布局行为向左对齐。

/* ROUNDED ONE */
.Gcheckbox {
/*CHANGES GRAY SQUARE DIMENSIONS*/
width: 16px;
height: 33px;
background: #ff0000;

/*GRAY SQUARE BACKGROUND FADER*/
background: linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
background: -webkit-linear-gradient(top, 0000ff 100%, 0000ff 0%, #ff0000 0%);
background: -moz-linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
background: -o-linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
background: -ms-linear-gradient(top, #000000 100%, 0000ff 0%, #ff0000 0%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fcfff4', endColorstr='#b3bead',GradientType=0 );
/*margin: 0px auto;*/

position: relative;
}

.Gcheckbox label {
cursor: pointer;
position: absolute;
width: 10px;
height: 10px;

/*MAKES THE GREEN CIRCLE A CIRCLE*/
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
/********************************/

left: 3px;
top: 11.25px;

box-shadow: inset 0px 0px 0px rgba(239,239,238,1), 0px 0px 0px rgba(239,239,238,1);
-webkit-box-shadow: inset 0px 0px 0px rgba(239,239,238,1), 0px 0px 0px rgba(239,239,238,1);
-moz-box-shadow: inset 0px 0px 0px rgba(239,239,238,1), 0px 0px 0px rgba(239,239,238,1);

/*BEHIND GREEN CIRCLE BACKGROUND*/
background: -webkit-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: -moz-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: -o-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: -ms-linear-gradient(top, #0000ff 0%, #0000ff 100%);
background: linear-gradient(top, #0000ff 0%, #0000ff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0000ff', endColorstr='#0000ff',GradientType=1 );
}

.Gcheckbox label:after {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0;
content: '';
position: absolute;
width: 10px;
height: 10px;
background: #00bf00;

background: linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -webkit-linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -moz-linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -o-linear-gradient(top, #00ff00 0%, #00ff00 100%);
background: -ms-linear-gradient(top, #00ff00 0%, #00ff00 100%);

-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
bottom: 0px;
right: 0px;

-webkit-box-shadow: inset 0px 0px 0px #00ff00, 0px 0px 0px rgba(42,171,43);
-moz-box-shadow: inset 0px 0px 0px #00ff00, 0px 0px 0px rgba(42,171,43);
box-shadow: inset 0px 0px 0px #00ff00, 0px 0px 0px rgba(42,171,43);
}

/*CHANGE HOVER EFFECT OPACITY*/
.Gcheckbox label:hover::after {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
filter: alpha(opacity=30);
opacity: 0.3;
}

.Gcheckbox input[type=checkbox]:checked + label:after {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
opacity: 1;
}

input[type=checkbox] {
visibility:hidden;
}
<div class="Gcheckbox">
<input type="checkbox" value="None" id="Gcheckbox" name="check" />
<label for="Gcheckbox"></label>
</div>

关于html - CSS 按钮未知居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27494677/

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