【问题标题】:how to make the search box auto position and auto resize irrespective of the screen resolution?无论屏幕分辨率如何,如何使搜索框自动定位和自动调整大小?
【发布时间】:2013-09-25 12:15:51
【问题描述】:

我正在为我的项目创建一个响应式网站,但我被我的搜索栏在主页上的绝对位置所困扰,这对我来说非常重要。

代码如下:

<div class="span4">

<form class="well form-search" 

style="position:fixed; display:block; 

left: 50%; top: 35.5%; 

margin-top: -12.5px;  

margin-left: -150px;" 

action="{$GLOBALS.site_url}/search-results/">

<input type="text" class="input-medium search-query" value="I am Searching For" 

style="width: 300px; height: 25px; ">

<button class="btn btn-large btn-primary" type="submit" > GO </button>

</form>

</div>

</div>

我搜索了很多,看到了例子,但为了让它响应,然后将位置从像素更改为百分比,但问题仍然存在。

在桌面上看起来不错,但问题是当我在手机或 iPad 上看到它时,搜索框的位置没有改变。我只想修复框位置,而不管不同屏幕尺寸的屏幕分辨率。


我已经更改了代码,它工作得更好了,除了按钮“Go”按钮在这里打破了界限并向下移动。我希望它在同一行。请检查代码:

<form class="well form-search" 
style="position:absolute; display:block; 

left: 47.7%; top: 29.5%; 
margin-top: -12.5px;  
margin-left: -22.5%;


width: -webkit-calc(47.7% - 10px);
width: -moz-calc(47.7% - 10px);
width: calc(47.7% - 10px);"


action="{$GLOBALS.site_url}/search-results-jobs/">
<input type="text" class="input-medium search-query"              
value=" I am Looking For" 

style="width: 100%; height: 25px;

width: -webkit-calc(100% - 10px);
width: -moz-calc(100% - 10px);
width: calc(100% - 10px);">

<button class="btn btn-large btn-primary" type="submit" > GO </button></center>
</form>                                                                               

【问题讨论】:

  • 去吗?不,我不这么认为。另外没有代码。

标签: javascript jquery html css


【解决方案1】:

阅读此博客 http://bradfrostweb.com/blog/mobile/fixed-position/ 关于移动设备上的固定定位。

【讨论】:

  • 感谢您的链接。但它并没有帮助在不同的屏幕尺寸上调整搜索栏的大小。我想让同一个网站的“搜索栏”在同一个位置自动调整大小。
【解决方案2】:

看看这个:http://jsfiddle.net/4bPuT/1/

如果我理解正确,您可以在绝对定位输入中执行的操作是将左右 css 属性设置为 0,以便获得当前容器的最大宽度。

<div class="container">
    <input id="search" type="text" name="search" placeholder="I resize">

    <!-- other content -->

</div>

css:

.container{
    width:100%;
    height:auto;
    position:relative;
}

.container #search{
    position:absolute;
    top:0px;
    left:0px;
    right:0px;
}

【讨论】:

  • 非常感谢...我尝试使用上面的代码,但我想再次将其固定在不同屏幕尺寸的某个位置。首先,搜索栏位置是静态的,即 left: 500px;顶部:246 像素;然后我将其更改为像素,即 left: 50%;最高:35.5%;在不同的屏幕尺寸上可以正常工作但不能正常工作。此外,我必须根据屏幕尺寸保持搜索栏的宽度和高度,但在桌面版本上它必须是“宽度:300 像素;高度:25 像素;谢谢
  • 那么你可能对媒体查询感兴趣。看看这个:css-tricks.com/snippets/css/media-queries-for-standard-devices
猜你喜欢
  • 2011-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多