How can I create two buttons on one line in a Struts2 form?

My form has two buttons - one for registering and the other for canceling the form. I created them using the following code:

<s:submit name="cancel" key="project.button.cancel" />
<s:submit name="login" key="form.register.registerBtn" />

However, when I view the form, the buttons appear on separate rows instead of in the same row. You can see this in the image below:

How can I fix this issue? Thank you.

Update 2013/9/21 :
Here is the full JSP page code:

<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/css/form.css" />
    <title>Insert title here</title>
</head>
<body>
    <div style="padding-top: 20px;"></div>
    <div style="width: 600px; margin: 0 auto;">
    <div style="float: left; padding: 20px; padding-top: 0px;">
        <img alt=""
            src="${pageContext.request.contextPath}/resources/img/register.png">
    </div>
    <div class="box" style="width: 300px; float: left;" id="col">
        <h1>
            <span class="title"><s:text name="form.register.title" /></span>
        </h1>
        <hr />
        <form action="login" method="post" namespace="/">
            <span class="text"><s:text name="user.nickname" /></span>
            <s:textfield name="nickname" />
            <hr />
            <span class="text"><s:text name="user.username" /></span>
            <s:textfield name="username" />
            <span class="text"><s:text name="user.password" /></span>
            <s:password name="password" />
            <span class="text"><s:text name="user.validation" /></span>
            <s:password name="validation" />
            <s:checkbox name="recoverable" key="user.recoverable" />
            <hr />
            <span class="text"><s:text name="user.email" /></span>
            <s:textfield name="validation" />
            <div style="display: inline-block; white-space: no-wrap;">
                <s:submit name="cancel" key="project.button.cancel"
                    cssClass="button-red" />
                <s:submit name="login" key="form.register.registerBtn"
                    cssClass="button-green" />
            </div>

        </form>
    </div>
</div>

Answer №1

To solve this issue, it is recommended to group them together within a single div element and style it using CSS.

<s:form action="login" method="post" namespace="/" theme="simple">
  ....
  <div style="display:inline-block;white-space:nowrap;">
    <s:submit name="cancel"  key="project.button.cancel" />
    <s:submit name="login"  key="form.register.registerBtn" />
  </div>
</s:form>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discovering an <a> element with an href attribute containing two specified strings

Here's what I have: $("a[href*='string1' && 'string2']") Unfortunately, this code didn't work for me. I also attempted: $("a:contains('string1' && 'string2')") The second one only return ...

The problematic max-width with srcset attribute

Here's the HTML markup I'm working with: <picture> <source srcset="img/home-page/placeholders/placeholder_2560.jpg" media="(max-width: 2560px)"> <source srcset="img/home-page/placeholders/placeh ...

I am looking to enhance my email subscription form by incorporating a URL into the subscription button, all while ensuring that the email subscription function in the HTML remains fully operational

Is it possible to maintain the functionality of an email subscription form while adding a URL to the subscription button in HTML? I need help modifying the code of the button. ...

Endlessly tapping through each tab with no direction

I am attempting to click on all unopened tabs (elements) randomly across this page. While the code below usually does the trick, it sometimes doesn't click on all elements. I suspect that there might be an issue with how it loads indexes or some othe ...

container that fades away, while the popup remains visible

Is it possible to fade the background of a container without affecting the pop-up form inside? I've come across some solutions, but they all seem to treat them separately. Here's what I'm trying to achieve: <div class='wrapper ...

Having trouble loading external CSS in HTML?

I have been attempting to load an external CSS file into my current HTML file without success. I have provided images showcasing the code: View the code here See the output here Currently, I am working on Windows and using Aptana Studio 3 as my IDE. ...

Activate animation when a user clicks on a link

Hey there, I'm a bit unsure about how to word this and I'm still getting the hang of StackExchange so I hope I've posted in the correct place. Currently, I am developing a mobile HTML5 app that utilizes Phonegap/Cordova (as well as Bootstra ...

Having trouble connecting to CSS in a node.js HTML document

My website is encountering an issue where the CSS fails to load, and I am receiving the following error message: Refused to apply style from 'http://localhost:5000/server/nodeClient/public/css' because its MIME type ('text/html') is not ...

"Varying hues on various displays: Exploring RGB values and CSS for video color

Recently, I designed a webpage with a background-color of #f4afac. The video embedded in this page also features the same background color throughout, creating a seamless blend with no visible edges. On one screen, the colors appear perfectly consistent. ...

Creating a horizontal layout for list items that are responsive using CSS

My website has a "Featured" section with 3 equally sized elements displayed horizontally. I want to make the webpage responsive by using percentage widths, but when I resize the window to less than the list width, the items stack on top of each other. Che ...

Converting javascript html object lowercase

Is there a way to dynamically adjust the height of specific letters in my label? Right now, I am overriding the text for the elements: let element = document.getElementById('xxx') element.textContent = 'Label' I attempted using <sup ...

Guide to transmitting HTML form information to a different web server with the click of a button

I operate two distinct web servers. One is responsible for the front-end (example.com), and the other manages the back-end (api.example.com). On my front-end server (example.com), there is a simple HTML website with a form that includes an input field and ...

What is the best way to use shortcodes to display custom fields for post objects, specifically products, within WordPress posts

I'm in the process of displaying 'featured products' within my blog posts. These specific products need to be chosen using custom post objects on the backend for each individual post. I've outlined what I believe the PHP code should lo ...

Ways to move an element beyond specified padding using CSS

In this image below, I have added a 10px padding to the container as it is usually needed. However, for the headings (blue) I do not want any padding. Is there a way to make the heading extend over the padding? I prefer not to give individual padding to e ...

Is there a way to dynamically incorporate line numbers into Google Code Prettify?

Having some trouble with formatting code and inserting/removing line numbers dynamically. The line numbers appear on the first page load, but disappear after clicking run. They don't show at all on my website. I want to allow users to click a button a ...

Achieve a sleek, modern look by using CSS to add a border with crisp square

Hello everyone, I'm currently attempting to add a border to only one side of an a element. However, when I add the border to just one side, it creates a sharp diagonal edge: https://i.stack.imgur.com/pAqMM.png My goal is to eliminate the sharp edge ...

issue arising where the table's border is not displaying

I'm confused about why the border of the first tbody tr's td is not visible. https://i.stack.imgur.com/Fwlv7.png I can't see any reason why the border is not showing up. Here's what I've figured out: If the natural height of th ...

What is the best way to retrieve data from a POST request?

I am attempting to post data from the same site and create a new order when the submit button is clicked. However, I am not receiving any information in my req.body, leading me to suspect that there may be an issue with my ejs file. Any feedback on this ma ...

Why is it that the default theme of Material UI lacks any stylization at all?

After experimenting with both Carbon Design for React (@carbon/react) and Material UI (@mui/material) in conjunction with Next.js, I encountered styling issues with the components. While they functioned correctly to some extent, there were noticeable discr ...

Implementing a dynamic update of an HTML element's content with JSON data - Learn how!

My task involves creating a quiz application where I need to show the answers along with images of the choices stored in my JSON data. However, I encounter an error: Uncaught TypeError: Cannot set properties of null (setting 'src') when I attempt ...