[英]Inputs alignment inside container
我有這樣一個問題:容器中有兩個輸入:文本字段和提交按鈕。 問題是當文本被區域設置更改時(例如從英語到法語),該按鈕會被刻錄並重疊文本字段。 以下是示例:
英語:
法國:
有什么辦法,所以搜索字段的長度會自動適合容器嗎?
這個容器的代碼是這樣的:
<div id="searchContainer">
<input type="text" id="searchField" class="search" name="searchQ" />
<?php echo $this->searchButton; ?>
</div>
我自己設計多語言形式時遇到了類似的問題,雖然我從未找到最佳解決方案,但我會分享我最終做的事情以防萬一。
不幸的是,樣式動態表單很少容易,有時甚至是不可能的。 但是,您可以根據頁面的語言設置輸入字段的樣式。 首先確保頁面html反映了您正在使用的語言(我使用服務器端代碼生成此語言,在您的情況下,它應該是一個直接的php echo語句):
<body lang="en">
接下來,根據語言選擇文本輸入
#searchField {
width: 80%; /* default width */
}
body[lang|="en"] #searchField {
width: 70%; /* make space for english button */
}
根據語言還有多種其他選擇方式,請查看http://www.w3.org/International/questions/qa-css-lang
如果您不介意jQuery的幫助,那么以下代碼可以解決您的問題。
HTML代碼 -
<div id="form" class="loading">
<form action="">
<div id="container">
<input type="text" name="input" id="input" value="">
<input type="submit" name="submit" value="submit" id="s">
</div>
</form>
</div>
css和js-
<script>
jQuery(document).ready(function($){
var containerWidth = $("#form #container").outerWidth();
var searchBoxWidth = jQuery("#form #s").outerWidth();
var adjustedWidth = containerWidth - searchBoxWidth - 30 // this is a value i've chosen to separate the button from the input field and the right edge of the wrapper
jQuery("#form #input").width(adjustedWidth);
jQuery("#form").removeClass('loading');
});
</script>
<style>
.loading form{visibility:hidden;background:url(img/loader.gif) no-repeat 50% 50%}
/*url should follow your own link to the gif you want to use*/
#form{width:700px;margin:200px auto;}
#form #container{border-radius: 30px;height: 60px;background: #ccc;border: 0;padding:0}
#form #input{height: 40px;margin: 10px 0 0 10px;border-radius: 30px;border: 0;padding:0;}
#form #s{padding: 13px 28px;border: 0;border-radius: 30px;text-transform: uppercase;}
</style>
編輯:
visibility:hidden
以便內容將保留在該位置,而不顯示它們我正在使用background
屬性顯示加載gif loader
類。 loading
,以便現在可以看到內容。 如果您不介意使用表格進行布局,您可以這樣做( 小提琴 ):
<style>
.search-table {
width:100%;
}
.search-table .search{
box-sizing:border-box;
width:100%;
}
.search-table .btn-cell {
width:1px;
white-space:nowrap;
}
</style>
<div id="searchContainer">
<table class="search-table">
<tr>
<td><input type="text" id="searchField" class="search" name="searchQ" /></td>
<td class="btn-cell"><button>search</button></td>
</tr>
</table>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.