简体   繁体   English

在容器内输入对齐

[英]Inputs alignment inside container

I have such an issue: There are two inputs in the container: the text field and the submit button. 我有这样一个问题:容器中有两个输入:文本字段和提交按钮。 The problem is that when the text is changed by the locale (For example from English to French), the button gets stratched and overlaps the text field. 问题是当文本被区域设置更改时(例如从英语到法语),该按钮会被刻录并重叠文本字段。 Here are the examples: 以下是示例:

English: 英语: 英语

French: 法国: 法国

Is there any way, so the length of the search field will fit the container automatically? 有什么办法,所以搜索字段的长度会自动适合容器吗?

The code for this container is like that: 这个容器的代码是这样的:

  <div id="searchContainer">
    <input type="text" id="searchField" class="search" name="searchQ" />
    <?php echo $this->searchButton; ?>
  </div>

I had a similar issue when styling a multi-lingual form myself, and while I never found an optimal solution, I'll share what I ended up doing in case it helps. 我自己设计多语言形式时遇到了类似的问题,虽然我从未找到最佳解决方案,但我会分享我最终做的事情以防万一。

Unfortunately, styling dynamic forms is rarely easy and sometimes impossible. 不幸的是,样式动态表单很少容易,有时甚至是不可能的。 You can, however, style the input field based on the language of the page. 但是,您可以根据页面的语言设置输入字段的样式。 First make sure the page html reflects the language you are using (i generate this based on language using server side code, in your case it should be a straight forward php echo statement): 首先确保页面html反映了您正在使用的语言(我使用服务器端代码生成此语言,在您的情况下,它应该是一个直接的php echo语句):

<body lang="en">

Next, select your text input based on the language 接下来,根据语言选择文本输入

#searchField {
    width: 80%; /* default width */
}
body[lang|="en"] #searchField {
    width: 70%; /* make space for english button */
}

There are multiple other ways of selecting depending on language, check out http://www.w3.org/International/questions/qa-css-lang 根据语言还有多种其他选择方式,请查看http://www.w3.org/International/questions/qa-css-lang

If you don't mind the help of jQuery then the following code can solve your problem. 如果您不介意jQuery的帮助,那么以下代码可以解决您的问题。

html code- 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 and js- 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>

edit: 编辑:

  1. I've added a class "loading" in the main wrapper to identify the loading stage. 我在主包装器中添加了一个类“loading”来识别加载阶段。 Initial I don't want any visitor see the contents inside the wrapper so that i set the rule visibility:hidden so that the contents will remain in the position and they are not displayed instead i'm showing a loading gif using the background property of the loader class. 初始我不希望任何访问者看到包装器内的内容,以便我设置规则visibility:hidden以便内容将保留在该位置,而不显示它们我正在使用background属性显示加载gif loader类。
  2. when the width of the input box is set then i'm removing the class loading from the wrapper so that the contents are now visible. 当设置输入框的宽度时,我将从包装器中删除类loading ,以便现在可以看到内容。

If you don't mind having tables for layout you can do it like this ( fiddle ): 如果您不介意使用表格进行布局,您可以这样做( 小提琴 ):

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

将输入发布到 HTML 内部的 PHP<div id="text_translate"><p> 我对 HTML、PHP 和 javascript 还是很陌生。 所以我正在开发一个简单的音乐搜索网站。 所以基本上在输入关键字后,我的 web 将显示可能的结果列表,然后单击结果会将我重定向到音乐播放器并开始播放音乐。</p><p> 这是我的 HTML 文件: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="container"&gt; &lt;div class="row"&gt; &lt;h1&gt;Search Results&lt;/h1&gt; &lt;!-- BEGIN SEARCH RESULT --&gt; &lt;div class="col-md-12"&gt; &lt;div class="grid search"&gt; &lt;div class="grid-body"&gt; &lt;div class="row"&gt; &lt;div class="table-responsive"&gt; &lt;table class="table table-hover"&gt; &lt;tbody id="mytable"&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p><p> 我将搜索结果插入到带有 javascript 的表中</p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> &lt;script&gt; window.onload= function () { var results = &lt;?php echo json_encode($result_array); ?&gt;; for (i=1;i&lt;=results.length;i++){ document.getElementById("mytable").innerHTML += '&lt;tr action="get_music.php" method="post"&gt;&lt;td class= "number text-center"&gt;' + i +'&lt;/td&gt; &lt;td&gt;&lt;input type="hidden" name="name" value='+results[i-1][0]+'/&gt;&lt;/td&gt;&lt;/tr&gt;'; } } &lt;/sript&gt;</pre></div></div><p></p><p> 我的问题是,每当我点击一个结果(或具体的表格行)时,我都不会被重定向到 get_music.php 并且我也无法将我的输入发布到 get_music.php 文件中。 我知道我的代码一团糟,但请帮忙! 谢谢!</p><p> 更新 - 添加了一些图片只是为了更清楚地描述它! <a href="https://i.stack.imgur.com/Cd5z5.png" rel="nofollow noreferrer">照片链接</a>所以,我搜索了一个关键字并得到了多个结果,我希望从我点击的结果中传递 3 个值(名称、专辑、艺术家)到 get_music.php</p><p> 更新 - 它有效! 感谢 Agustin Mita 的帮助! 所以这是我的最终代码</p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> &lt;script&gt; window.onload= function() { getDataPHP(); } function getDataPHP(){ var results = &lt;?php echo json_encode($result_array); ?&gt;; renderView(results); } function renderView(results){ var data = ""; for (i=0;i&lt;results.length;i++){ data += '&lt;tr&gt;'; data += '&lt;td class="number text-center"&gt;' + (i+1) + '&lt;/td&gt;'; data += '&lt;td class="image" align="left"&gt;&lt;img src="https://discussions.apple.com/content/attachment/881765040" alt=""&gt;&lt;/td&gt;'; data += '&lt;td class="product"&gt;&lt;strong&gt;'+results[i][0]+'&lt;/strong&gt;&lt;br&gt;'+results[i][1]+'&lt;br&gt;'+results[i][2]+'&lt;/td&gt;'; data += '&lt;td&gt;&lt;form method="post" action="get_music.php"&gt;'; data += '&lt;input type="hidden" value="'+results[i][0]+'" name="name" /&gt;'; data += '&lt;input type="hidden" value="'+results[i][1]+'" name="album" /&gt;'; data += '&lt;input type="hidden" value="'+results[i][2]+'" name="author" /&gt;'; data += '&lt;br&gt;&lt;input style="float: right;" type="submit" value="Play music" /&gt;'; data += '&lt;/form&gt;&lt;/td&gt;'; data += '&lt;/tr&gt;'; } document.getElementById('mytable').innerHTML += data; } &lt;/script&gt;</pre></div></div><p></p></div><table></table> - Posting Inputs to PHP inside HTML <table>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bootstrap - 容器流体的对齐问题 - Bootstrap - alignment issues with container-fluid PHP表对齐在foreach循环中不正确 - PHP table alignment is not correct inside foreach Loop div在IE中的列表对齐问题 - div inside list alignment issue in IE 表格内的TCPDF图像底部对齐 - TCPDF image bottom alignment inside table html 段内文本的条件 alignment - Conditional alignment of text inside html paragraph 如何遍历数组中的附加输入 - How to loop through appended inputs inside an array 另一个输入相同的表单中的表单 - Form inside another form with same inputs WordPress问题与ContactForm7上的div内的输入有关 - WordPress issue with inputs inside divs on ContactForm7 将输入发布到 HTML 内部的 PHP<div id="text_translate"><p> 我对 HTML、PHP 和 javascript 还是很陌生。 所以我正在开发一个简单的音乐搜索网站。 所以基本上在输入关键字后,我的 web 将显示可能的结果列表,然后单击结果会将我重定向到音乐播放器并开始播放音乐。</p><p> 这是我的 HTML 文件: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="container"&gt; &lt;div class="row"&gt; &lt;h1&gt;Search Results&lt;/h1&gt; &lt;!-- BEGIN SEARCH RESULT --&gt; &lt;div class="col-md-12"&gt; &lt;div class="grid search"&gt; &lt;div class="grid-body"&gt; &lt;div class="row"&gt; &lt;div class="table-responsive"&gt; &lt;table class="table table-hover"&gt; &lt;tbody id="mytable"&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p><p> 我将搜索结果插入到带有 javascript 的表中</p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> &lt;script&gt; window.onload= function () { var results = &lt;?php echo json_encode($result_array); ?&gt;; for (i=1;i&lt;=results.length;i++){ document.getElementById("mytable").innerHTML += '&lt;tr action="get_music.php" method="post"&gt;&lt;td class= "number text-center"&gt;' + i +'&lt;/td&gt; &lt;td&gt;&lt;input type="hidden" name="name" value='+results[i-1][0]+'/&gt;&lt;/td&gt;&lt;/tr&gt;'; } } &lt;/sript&gt;</pre></div></div><p></p><p> 我的问题是,每当我点击一个结果(或具体的表格行)时,我都不会被重定向到 get_music.php 并且我也无法将我的输入发布到 get_music.php 文件中。 我知道我的代码一团糟,但请帮忙! 谢谢!</p><p> 更新 - 添加了一些图片只是为了更清楚地描述它! <a href="https://i.stack.imgur.com/Cd5z5.png" rel="nofollow noreferrer">照片链接</a>所以,我搜索了一个关键字并得到了多个结果,我希望从我点击的结果中传递 3 个值(名称、专辑、艺术家)到 get_music.php</p><p> 更新 - 它有效! 感谢 Agustin Mita 的帮助! 所以这是我的最终代码</p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> &lt;script&gt; window.onload= function() { getDataPHP(); } function getDataPHP(){ var results = &lt;?php echo json_encode($result_array); ?&gt;; renderView(results); } function renderView(results){ var data = ""; for (i=0;i&lt;results.length;i++){ data += '&lt;tr&gt;'; data += '&lt;td class="number text-center"&gt;' + (i+1) + '&lt;/td&gt;'; data += '&lt;td class="image" align="left"&gt;&lt;img src="https://discussions.apple.com/content/attachment/881765040" alt=""&gt;&lt;/td&gt;'; data += '&lt;td class="product"&gt;&lt;strong&gt;'+results[i][0]+'&lt;/strong&gt;&lt;br&gt;'+results[i][1]+'&lt;br&gt;'+results[i][2]+'&lt;/td&gt;'; data += '&lt;td&gt;&lt;form method="post" action="get_music.php"&gt;'; data += '&lt;input type="hidden" value="'+results[i][0]+'" name="name" /&gt;'; data += '&lt;input type="hidden" value="'+results[i][1]+'" name="album" /&gt;'; data += '&lt;input type="hidden" value="'+results[i][2]+'" name="author" /&gt;'; data += '&lt;br&gt;&lt;input style="float: right;" type="submit" value="Play music" /&gt;'; data += '&lt;/form&gt;&lt;/td&gt;'; data += '&lt;/tr&gt;'; } document.getElementById('mytable').innerHTML += data; } &lt;/script&gt;</pre></div></div><p></p></div><table></table> - Posting Inputs to PHP inside HTML <table> 将iframe内部,表单内部的一些输入发布为整个表单 - post some inputs that is inside an iframe,that is inside a form,as a whole form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM