不在div中居中

时间:2019-03-07 10:11:27

标签: javascript html css 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”。
〜filip

5 个答案:

答案 0 :(得分:1)

您正在寻找:text-align:center

只需将该属性添加到包含您的输入的div中即可:

.kobel_input_cont {
    justify-content: center;
    align-items:center;
    text-align:center;

}

答案 1 :(得分:0)

您需要将占位符居中吗? 用伪元素将它们居中,如下所示:

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

答案 2 :(得分:0)

如果要将占位符设置在中间,则只需编写

::-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>

答案 3 :(得分:0)

在CSS中添加以下代码

::-webkit-input-placeholder {
   text-align: center;
}

答案 4 :(得分:0)

只需添加text-align:center

Here is the working code.