div 不是所有内容的中心
Center not everything in div
这是我的 HTML 代码:
.kobel_perm {
height: auto;
border-radius: 5px;
box-shadow: 1px 1px 5px #0d0d0d;
}
.kobel_input_cont {
justify-content: center;
align-items:center;
}
.kobelK {
padding: 5px;
background-image: linear-gradient(to right, #7ef6a9, #86a8e7);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.kobel_perm input {
width: 95%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
background-color: #212121;
color: #ffffff;
}
.kobel_perm input::placeholder {
color: #ffffff;
}
.kobel_perm input[type=button] {
cursor: pointer;
border: 1px solid #7ef6a9;
}
.kobel_perm input[type=button]:hover, .kobel_in input[type=button]:focus {
border: 1px solid #7ef6a9;
animation: color_change 1s;
background-color: #7ef6a9;
color: #212121;
}
@-webkit-keyframes color_change {
0% {
background-color: #00251d1d;
color: #ffffff;
}
100% {
background-color: #7ef6a9;
color: #212121;
}
}
<div class='kobel_perm'>
<p class="kobelK">Kobeltage</p>
<div class="kobel_input_cont">
<input type="text" id="kobel_weekday" name="kobel_weekday" placeholder="Wochentag">
<input type="text" id="kobel_date" name="kobel_date" placeholder="Datum">
<input type="text" id="kobel_topic" name="kobel_topic" placeholder="Thema">
<input type="text" id="kobel_host" name="kobel_host" placeholder="Kobelwirte">
<input type="button" value="Kobel hinzufügen" onclick="addKobel()">
<input type="button" value="Kobel entfernen" onclick="removeKobel()">
</div>
</div>
这是我得到的结果:https://www.dropbox.com/s/37kor9k1lccctl3/look.PNG?dl=0
当您查看图像时,您会看到输入未水平居中。我寻找一种方法来解决这个问题,因为我只想将输入居中,而不是上面的文本 "Kobeltage"。
~菲利普
您正在寻找:text-align:center
只需将 属性 添加到包含您的输入的 div 中:
.kobel_input_cont {
justify-content: center;
align-items:center;
text-align:center;
}
您需要将占位符居中吗?
用伪元素居中,像这样:
.kobel_perm {
height: auto;
border-radius: 5px;
box-shadow: 1px 1px 5px #0d0d0d;
}
.kobel_input_cont {
justify-content: center;
align-items:center;
}
.kobelK {
padding: 5px;
background-image: linear-gradient(to right, #7ef6a9, #86a8e7);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.kobel_perm input {
width: 95%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
background-color: #212121;
color: #ffffff;
}
.kobel_perm input::placeholder {
color: #ffffff;
}
.kobel_perm input[type=button] {
cursor: pointer;
border: 1px solid #7ef6a9;
}
.kobel_perm input[type=button]:hover, .kobel_in input[type=button]:focus {
border: 1px solid #7ef6a9;
animation: color_change 1s;
background-color: #7ef6a9;
color: #212121;
}
@-webkit-keyframes color_change {
0% {
background-color: #00251d1d;
color: #ffffff;
}
100% {
background-color: #7ef6a9;
color: #212121;
}
}
::-webkit-input-placeholder {
text-align: center;
}
:-moz-placeholder { /* Firefox 18- */
text-align: center;
}
::-moz-placeholder { /* Firefox 19+ */
text-align: center;
}
:-ms-input-placeholder {
text-align: center;
}
<div class='kobel_perm'>
<p class="kobelK">Kobeltage</p>
<div class="kobel_input_cont">
<input type="text" id="kobel_weekday" name="kobel_weekday" placeholder="Wochentag">
<input type="text" id="kobel_date" name="kobel_date" placeholder="Datum">
<input type="text" id="kobel_topic" name="kobel_topic" placeholder="Thema">
<input type="text" id="kobel_host" name="kobel_host" placeholder="Kobelwirte">
<input type="button" value="Kobel hinzufügen" onclick="addKobel()">
<input type="button" value="Kobel entfernen" onclick="removeKobel()">
</div>
</div>
如果你想在中心设置占位符那么你只需要写,
::-webkit-input-placeholder {
text-align: center;
}
这将使您的占位符居中
.kobel_perm {
height: auto;
border-radius: 5px;
box-shadow: 1px 1px 5px #0d0d0d;
}
.kobel_input_cont {
justify-content: center;
align-items:center;
}
.kobelK {
padding: 5px;
background-image: linear-gradient(to right, #7ef6a9, #86a8e7);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.kobel_perm input {
width: 95%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
background-color: #212121;
color: #ffffff;
}
.kobel_perm input::placeholder {
color: #ffffff;
}
.kobel_perm input[type=button] {
cursor: pointer;
border: 1px solid #7ef6a9;
}
.kobel_perm input[type=button]:hover, .kobel_in input[type=button]:focus {
border: 1px solid #7ef6a9;
animation: color_change 1s;
background-color: #7ef6a9;
color: #212121;
}
::-webkit-input-placeholder {
text-align: center;
}
@-webkit-keyframes color_change {
0% {
background-color: #00251d1d;
color: #ffffff;
}
100% {
background-color: #7ef6a9;
color: #212121;
}
}
<div class='kobel_perm'>
<p class="kobelK">Kobeltage</p>
<div class="kobel_input_cont">
<input type="text" id="kobel_weekday" name="kobel_weekday" placeholder="Wochentag">
<input type="text" id="kobel_date" name="kobel_date" placeholder="Datum">
<input type="text" id="kobel_topic" name="kobel_topic" placeholder="Thema">
<input type="text" id="kobel_host" name="kobel_host" placeholder="Kobelwirte">
<input type="button" value="Kobel hinzufügen" onclick="addKobel()">
<input type="button" value="Kobel entfernen" onclick="removeKobel()">
</div>
</div>
在您的 css
中添加以下代码
::-webkit-input-placeholder {
text-align: center;
}
只需添加text-align:center
这是我的 HTML 代码:
.kobel_perm {
height: auto;
border-radius: 5px;
box-shadow: 1px 1px 5px #0d0d0d;
}
.kobel_input_cont {
justify-content: center;
align-items:center;
}
.kobelK {
padding: 5px;
background-image: linear-gradient(to right, #7ef6a9, #86a8e7);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.kobel_perm input {
width: 95%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
background-color: #212121;
color: #ffffff;
}
.kobel_perm input::placeholder {
color: #ffffff;
}
.kobel_perm input[type=button] {
cursor: pointer;
border: 1px solid #7ef6a9;
}
.kobel_perm input[type=button]:hover, .kobel_in input[type=button]:focus {
border: 1px solid #7ef6a9;
animation: color_change 1s;
background-color: #7ef6a9;
color: #212121;
}
@-webkit-keyframes color_change {
0% {
background-color: #00251d1d;
color: #ffffff;
}
100% {
background-color: #7ef6a9;
color: #212121;
}
}
<div class='kobel_perm'>
<p class="kobelK">Kobeltage</p>
<div class="kobel_input_cont">
<input type="text" id="kobel_weekday" name="kobel_weekday" placeholder="Wochentag">
<input type="text" id="kobel_date" name="kobel_date" placeholder="Datum">
<input type="text" id="kobel_topic" name="kobel_topic" placeholder="Thema">
<input type="text" id="kobel_host" name="kobel_host" placeholder="Kobelwirte">
<input type="button" value="Kobel hinzufügen" onclick="addKobel()">
<input type="button" value="Kobel entfernen" onclick="removeKobel()">
</div>
</div>
这是我得到的结果:https://www.dropbox.com/s/37kor9k1lccctl3/look.PNG?dl=0
当您查看图像时,您会看到输入未水平居中。我寻找一种方法来解决这个问题,因为我只想将输入居中,而不是上面的文本 "Kobeltage"。
~菲利普
您正在寻找:text-align:center
只需将 属性 添加到包含您的输入的 div 中:
.kobel_input_cont {
justify-content: center;
align-items:center;
text-align:center;
}
您需要将占位符居中吗? 用伪元素居中,像这样:
.kobel_perm {
height: auto;
border-radius: 5px;
box-shadow: 1px 1px 5px #0d0d0d;
}
.kobel_input_cont {
justify-content: center;
align-items:center;
}
.kobelK {
padding: 5px;
background-image: linear-gradient(to right, #7ef6a9, #86a8e7);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.kobel_perm input {
width: 95%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
background-color: #212121;
color: #ffffff;
}
.kobel_perm input::placeholder {
color: #ffffff;
}
.kobel_perm input[type=button] {
cursor: pointer;
border: 1px solid #7ef6a9;
}
.kobel_perm input[type=button]:hover, .kobel_in input[type=button]:focus {
border: 1px solid #7ef6a9;
animation: color_change 1s;
background-color: #7ef6a9;
color: #212121;
}
@-webkit-keyframes color_change {
0% {
background-color: #00251d1d;
color: #ffffff;
}
100% {
background-color: #7ef6a9;
color: #212121;
}
}
::-webkit-input-placeholder {
text-align: center;
}
:-moz-placeholder { /* Firefox 18- */
text-align: center;
}
::-moz-placeholder { /* Firefox 19+ */
text-align: center;
}
:-ms-input-placeholder {
text-align: center;
}
<div class='kobel_perm'>
<p class="kobelK">Kobeltage</p>
<div class="kobel_input_cont">
<input type="text" id="kobel_weekday" name="kobel_weekday" placeholder="Wochentag">
<input type="text" id="kobel_date" name="kobel_date" placeholder="Datum">
<input type="text" id="kobel_topic" name="kobel_topic" placeholder="Thema">
<input type="text" id="kobel_host" name="kobel_host" placeholder="Kobelwirte">
<input type="button" value="Kobel hinzufügen" onclick="addKobel()">
<input type="button" value="Kobel entfernen" onclick="removeKobel()">
</div>
</div>
如果你想在中心设置占位符那么你只需要写,
::-webkit-input-placeholder {
text-align: center;
}
这将使您的占位符居中
.kobel_perm {
height: auto;
border-radius: 5px;
box-shadow: 1px 1px 5px #0d0d0d;
}
.kobel_input_cont {
justify-content: center;
align-items:center;
}
.kobelK {
padding: 5px;
background-image: linear-gradient(to right, #7ef6a9, #86a8e7);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.kobel_perm input {
width: 95%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
background-color: #212121;
color: #ffffff;
}
.kobel_perm input::placeholder {
color: #ffffff;
}
.kobel_perm input[type=button] {
cursor: pointer;
border: 1px solid #7ef6a9;
}
.kobel_perm input[type=button]:hover, .kobel_in input[type=button]:focus {
border: 1px solid #7ef6a9;
animation: color_change 1s;
background-color: #7ef6a9;
color: #212121;
}
::-webkit-input-placeholder {
text-align: center;
}
@-webkit-keyframes color_change {
0% {
background-color: #00251d1d;
color: #ffffff;
}
100% {
background-color: #7ef6a9;
color: #212121;
}
}
<div class='kobel_perm'>
<p class="kobelK">Kobeltage</p>
<div class="kobel_input_cont">
<input type="text" id="kobel_weekday" name="kobel_weekday" placeholder="Wochentag">
<input type="text" id="kobel_date" name="kobel_date" placeholder="Datum">
<input type="text" id="kobel_topic" name="kobel_topic" placeholder="Thema">
<input type="text" id="kobel_host" name="kobel_host" placeholder="Kobelwirte">
<input type="button" value="Kobel hinzufügen" onclick="addKobel()">
<input type="button" value="Kobel entfernen" onclick="removeKobel()">
</div>
</div>
在您的 css
中添加以下代码::-webkit-input-placeholder {
text-align: center;
}
只需添加text-align:center