Designing Beautiful Buttons Using HTML

I have been practicing my skills in html, css, and javascript by working on a project I find quite useful - a recipe finder based on the recipes available at home. However, I am facing an issue with aligning certain elements on the html page.
The section of the html page that is causing confusion is:

<form>
<select size=10 id="first"></select>
<button type="button" id="addAll" onclick="rightAll()">
    Add All
</button>
<button type="button" id="removeAll" onclick="leftAll()">
    Remove All
</button>
<button type="button" id="add" onclick="right()">
    >>
</button>
<button type="button" id="remove" onclick="left()">
    &lt;&lt;
</button>
<select size=10 id="second"></select>
</form>

Here is a snippet from my css document:

html, body {
  height: 100%;
  min-height: 100%;
}
select{
    width: 300px;
}

Due to all elements being within a form tag, they are displaying inline. I attempted to use a table for organizing the buttons, but it caused formatting issues where the first select appeared on one line, the table on another line, and the second select on yet another line.
This is how the current layout looks like:https://i.sstatic.net/8E67s.png
and this is the desired layout (as illustrated using paint):https://i.sstatic.net/qiQjM.png
I believe I could manage centering the buttons vertically within the form, but any assistance you could provide on that front would be highly appreciated!

Answer №1

HTML

<form>
    <div id="sel1">
        <select size=10 id="first"></select>
    </div>
    <div id="buttons">
        <div id="buttons1">
             <button type="button" id="addAll" onclick="rightAll()">
             Add All
             </button>
             <button type="button" id="removeAll" onclick="leftAll()">
             Remove All
             </button>
        </div>
        <div id="buttons2">
             <button type="button" id="add" onclick="right()">
             >>
             </button>
             <button type="button" id="remove" onclick="left()">
             &lt;&lt;
             </button>
        </div>
     </div>
     <div id="sel2">
         <select size=10 id="second"></select>
     </div>
</form>

CSS

html, body {
  height: 100%;
  min-height: 100%;
}
select{
    width: 300px;
}
div {
  float: left;
}  
#buttons1, #buttons2 {
  float: none;
  text-align: center;
}

Feel free to adjust padding and margins as you see fit.

Answer №2

If you're looking to expand your design further, it's recommended to use div elements instead of tables. Tables are not directly responsive and can lead to a fixed layout with messy code. Consider using divs along with other CSS properties for more flexibility.

For the middle section of your table, you can try incorporating div elements within your table cells like this:

<div style="width:100%;">
<div style="width:50%;float:left;">
<button type="button" id="addAll" onclick="rightAll()">
    Add All
</button>
<div>
<div style="width:50%;float:right;">
<button type="button" id="removeAll" onclick="leftAll()">
    Remove All
</button>
<div>
<div style="clear:both;"></div>
</div>

<div style="width:100%;">
<div style="width:50%;float:left;">
<button type="button" id="add" onclick="right()">
    >>
</button>
<div>
<div style="width:50%;float:right;">
<button type="button" id="remove" onclick="left()">
    &lt;&lt;
</button>
<div>
<div style="clear:both;"></div>
</div>

Cheers!

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

JavaScript Logic to Check if an Element is Hidden

I'm having trouble figuring out how to close an element when another element collapses. I've searched for solutions without success. My structure is updated using Bootstrap and JavaScript, but it doesn't function as expected. Specifically, ...

This message is designed to validate the form as it is dynamic and

Is there a way to dynamically determine which .input fields have not been entered yet? In the following code snippet, you can observe that if I input data out of sequence, the #message displays how many inputs have been filled and shows the message in sequ ...

Struggling with uploading files in AngularJS?

Below is the code snippet from my controller file where I aim to retrieve the values of various input elements (name, price, date, image) and store them in an array of objects... $scope.addBook = function(name, price, date, image) { name = $scope ...

Get the input value and display it on the PHP page

I've been struggling for hours trying to figure out how to read the value from an input box in HTML and use it to dynamically create dropdown boxes using PHP within the same file. Despite my efforts, I haven't been able to find a working solution ...

Troubleshooting problem with resizing the sidebar in Bootstrap's responsive

I'm facing an issue with my responsive sidebar. I want the sidebar to maintain its size when resizing the window, but still collapse when the screen becomes too small. I attempted setting a min-width, however, it only made things worse. The jsfiddle ...

CSS, Struggling to align element in the center due to varying sizes of its children

Greetings everyone! I wanted to share a snapshot of my current layout: https://i.sstatic.net/Cl8x6.png My grid consists of 3 rows and 3 columns, where each column is set to min-content, and the elements are centered within each cell. While it looks alrig ...

Comparison between Login popups and Login pagesIt's time

Curious about the most effective approach for handling multiple login forms? Would you rather: A) Keep each form on a separate web page. B) Utilize modal popups with update panels. Weighing SEO considerations as well. Cheers! ...

The JQuery code is failing to remove the dynamically added field when the delete icon is clicked

Information: I am currently navigating the world of programming and attempting to build a To-Do List feature. When the create list button is clicked, a dynamically generated div with the class 'wrap' is created. This div contains two nested divs: ...

Rearrange the entire div container by simply dragging and dropping it. (Shift the Pop-up Modal dialog box)

How can I make a Modal pop-up draggable and change the color of the "Ok" and "Cancel" buttons on hover using a single CSS class? .hidModal{ position: fixed; font-family: Arial, Helvetica, sans-serif; top: 0; right: 0; bottom: 0; ...

How can I create responsive buttons with icons using material-ui?

I'm working with a material-ui Button that has a startIcon, and I need to hide the button text on smaller screens while still showing the icon. One common solution would be to use the useMediaQuery hook to identify the browser size and render a diffe ...

To prevent the default alignment in case the text exceeds the input length, stop the automatic alignment

I have a query regarding an input field with a maximum length of 4 characters. The appearance is such that these 4 characters seem to be delineated by borders which are actually 3 lines displayed above the input field. When I enter the fourth character, a ...

What is the process for updating tabs and their content in React?

Here is where the error occurs in my JavaScript code. I have successfully implemented it in HTML, CSS, and simple JavaScript, but encountered issues when trying to do so in React. My goal is to switch tabs and their corresponding data/content: ...

In this guide, we will explore the process of designing unique styles for ng

What is the proper way to customize CSS for a specific element? &.ng-select-focused { &:not(.ng-select-opened) > .ng-select-container { border-color: $ng-select-highlight; box-shadow: $ng-select-box-shadow; } } The offi ...

The document's event listener for the "click" event on the element with the ID of "myId" is unable to properly update the owl carousel

I have been experimenting with the Carousel example and modifying the function to enable loading on click. Here is my updated code snippet: $(document).on("click","#myId",function(){ $("#owl-demo").owlCarousel({ autoPlay : 3000, //Set AutoPlay ...

Leveraging @font-face for various styles and designs

Google web fonts presents the Droid Serif font in these styles: DroidSerif.ttf DroidSerif-Bold.ttf DroidSerif-BoldItalic.ttf DroidSerif-Italic.ttf I am interested in using the @font-face CSS rule to import all of these variations with the "Droid Serif" f ...

Prevent collapsing when clicking twice

This section is designed to collapse and expand in its default mode. It will close when the user selects "No" and open/close when the user selects "Yes". I am looking to modify it so that it only closes when the user picks "No" and reopens only when the u ...

Styling CSS for disabled nested elements

In a project I am currently working on, I've noticed that disabled items do not appear disabled enough. My initial plan was to easily address this issue with some CSS. Typically, adjusting the opacity is my go-to solution to achieve the desired effec ...

Tips for creating a dynamic Web App - Design

I have limited experience in developing web applications. I am currently tasked with creating a responsive and accessible web application using a Delphi built simple web server that can handle sessions through session cookies and respond to AJAX queries. U ...

Adjusting the size of HTML checkboxes for creating PDF documents

Currently facing a dilemma. When it comes to resizing checkboxes in HTML, the common recommendation is to use JavaScript to prompt the browser to adjust the size of the elements. However, in our scenario, we rely on wkhtmltopdf, a command line tool that u ...

Select a radio button when it is in focus

I am having trouble figuring out how to automatically check a radio button when a user clicks on an input field. The code I have attempted is not working as expected... $(function() { $('.searchInput').focus(function() { $(this).prev( ...