难以将输入和带边框的文本居中
Having difficulties centering input and text with borders
我在将我创建的文本的输入和边框居中时遇到困难。我正在尝试以基于百分比的设置将其居中,以便它变得更加灵敏。似乎百分比不对,每次我超过 left: 35%;
,它就不再移动了。
这同样适用于我的提交按钮,位于搜索输入内。我把百分比遗漏了,因为它什么也没做。
我已经将我所有的代码存储在这个 fiddle:
https://jsfiddle.net/ghp4t489/
但是,要获得查看我正在尝试做的事情的最佳选择,是访问我的网站。房地产经纪人。com/test_index
如何让带有 borders/search 栏的文本在页面中居中?
这是我的 CSS
.search_option_container_out {
text-align: center;
top: 450px;
left: 30%;
position: absolute;
z-index: 111;
}
.search_option_box {
position: absolute;
text-align: center;
left: 40%;
}
.search_option_box li {
display: inline;
border: 1px solid black;
line-height: 2em;
padding: 20px 75px;
background: rgba(24, 24, 24, 0.3);
color: #FFFFFF;
cursor: pointer;
}
.search_option_box li:hover {
background: rgba(0,0,255, 0.3);
}
.home_searchbar_out {
text-align: center;
padding-top: 60px;
}
.home_searchbar {
padding: 10px;
}
.home_search_input {
position: absolute;
left: 45%;
width: 575px;
padding: 14px;
font-size: 1.1em;
}
#home_search_submit {
padding: 11px 20px;
position: absolute;
background-color: blue;
color: #FFFFFF;
cursor: pointer;
font-size: 1.1em;
z-index: 1;
}
您的代码演示在这里:https://jsfiddle.net/ghp4t489/4/
本质上,您想像这样在页面中使用居中容器的概念:
div {
width: 100px;
height: 100px;
border: 1px solid black;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
<div>my div here</div>
此代码使用 margin: auto
使 div 在页面中居中。
编辑: https://jsfiddle.net/ghp4t489/7/ 按钮在右边和输入旁边
https://jsfiddle.net/ghp4t489/9/ 输入框右侧的按钮
我在将我创建的文本的输入和边框居中时遇到困难。我正在尝试以基于百分比的设置将其居中,以便它变得更加灵敏。似乎百分比不对,每次我超过 left: 35%;
,它就不再移动了。
这同样适用于我的提交按钮,位于搜索输入内。我把百分比遗漏了,因为它什么也没做。
我已经将我所有的代码存储在这个 fiddle:
https://jsfiddle.net/ghp4t489/
但是,要获得查看我正在尝试做的事情的最佳选择,是访问我的网站。房地产经纪人。com/test_index
如何让带有 borders/search 栏的文本在页面中居中?
这是我的 CSS
.search_option_container_out {
text-align: center;
top: 450px;
left: 30%;
position: absolute;
z-index: 111;
}
.search_option_box {
position: absolute;
text-align: center;
left: 40%;
}
.search_option_box li {
display: inline;
border: 1px solid black;
line-height: 2em;
padding: 20px 75px;
background: rgba(24, 24, 24, 0.3);
color: #FFFFFF;
cursor: pointer;
}
.search_option_box li:hover {
background: rgba(0,0,255, 0.3);
}
.home_searchbar_out {
text-align: center;
padding-top: 60px;
}
.home_searchbar {
padding: 10px;
}
.home_search_input {
position: absolute;
left: 45%;
width: 575px;
padding: 14px;
font-size: 1.1em;
}
#home_search_submit {
padding: 11px 20px;
position: absolute;
background-color: blue;
color: #FFFFFF;
cursor: pointer;
font-size: 1.1em;
z-index: 1;
}
您的代码演示在这里:https://jsfiddle.net/ghp4t489/4/
本质上,您想像这样在页面中使用居中容器的概念:
div {
width: 100px;
height: 100px;
border: 1px solid black;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
<div>my div here</div>
此代码使用 margin: auto
使 div 在页面中居中。
编辑: https://jsfiddle.net/ghp4t489/7/ 按钮在右边和输入旁边
https://jsfiddle.net/ghp4t489/9/ 输入框右侧的按钮