Search code examples
cssgsp

Align g:form elements horizontally


Having a Grails/GSP issue. I want to horizontally align elements within a g:form tag.

My code looks like this currently, though the submitButton is still below the textField.

    <g:form controller="objectSearch" action="search" >
        <g:textField name="searchText" value="${searchText}"  />
        <g:submitButton name="search" value="Search" />         
    </g:form>

Thanks

UPDATE:

I've managed to get the desired result by creating a table within the form, and putting elements within the same <tr> tag (see code below). Surely there is a better way to do this?

<g:form controller="objectSearch" action="search" >
    <table>
        <tr>
            <td>
                <g:textField name="searchText" value="${searchText}"  />
            </td>
            <td>
                <g:submitButton name="search" value="Search" />     
            </td>
        </tr>
    </table>        
</g:form>

Solution

  • Thanks to the comments from codehx and Fernando, I ended up fixing my problem by including the float attribute of my form elements. See code below:

            <g:form controller="objectSearch" action="search" >
                        <g:textField name="searchText" value="${searchText}"  style="float: left;" />
                        <g:submitButton name="search" value="Search" style="float: right;" />       
            </g:form>