0

我有这个

            <td width="312" valign="center" height="157" background="{{ 'BT_S3.png' | asset_url }}">
             <div style="width:95%; text-align: left; height:52px; background-image:url('{{ 'search_bar.png' | asset_url }}');" float="left">
            <form action="/search" method="get">
            <input type="text" name="q" src="{{ 'search_bar.png' | asset_url }}" />
            <input type="image" value="Search"  src="{{ 'search_button.png' | asset_url }}"  />
            </form>
            </div>
            </td>

这是我的搜索框的 HTML,位于 http://clarkbetty.myshopify.com/# 密码: betweu

我希望搜索按钮浮动,以便搜索框和按钮位于同一行。我尝试了很多东西,但没有任何效果。有人可以帮忙吗?

4

3 回答 3

1

您应该添加style="float:left"到文本框和按钮元素。

<input type="text" [...] style="float:left" />
<input type="image" [...] style="float:left" />

另请注意,最好将这些规则放入 css 文件中,并通过它们的 id 或类来引用这些元素。

于 2012-04-25T22:29:07.617 回答
0

另一种方法是将相对定位应用于包装form元素,并在内部控件(搜索字段和按钮输入)上使用绝对定位来控制其内部布局。

这些方面的东西:

form {
    position: relative;
}
input[type='text'],
input[type='image'] {
    position: absolute;
    top: 0;
}
input[type='text'] {
    left: 0;
    width: 100%;
    padding-right: 20px;
}
input[type='image'] {
    right: 0;
    width: 20px;
}
于 2012-04-25T22:28:41.920 回答
0

更改此行:

<input type="text" name="q" src="{{ 'search_bar.png' | asset_url }}" />

对此:

<input type="text" style="float:left;" name="q" src="{{ 'search_bar.png' | asset_url }}" />

float:left 必须在 style 属性内。

于 2012-04-25T22:30:41.063 回答