Show elements side by side

I need some assistance.
I am trying to find a simple way to horizontally display the circled elements in this image .

My attempted solution:

.calculator {
display: inline-block;  
}

Unfortunately, this did not have any effect. I have provided the HTML code for better understanding.
Thank you in advance

<div class="calculator">
    <div class="input-group input-small">
        <h4>Adult (12+)</h4>
        <button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
        <input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
        <button class="btn theme-btn" id="increase" value="Increase Value">+</button>
        <h4>Child (2-11)</h4>
        <button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
        <input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
        <button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
        <p>£</p><p id="total"></p><p>.00</p><button class="btn green" onclick="myFunction()">Calculate</button>
    </div>
</div>

Answer №1

Enclose the following content in separate divs:

<h4>Adult (12+)</h4>
<button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
<input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
<button class="btn theme-btn" id="increase" value="Increase Value">+</button>

Next, place this content in its own div:

<h4>Child (2-11)</h4>
<button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
<input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
<button class="btn theme-btn" id="increasec" value="Increase Value">+</button>

Lastly, wrap the following content in a separate div:

<p>£</p><p id="total"></p>
<p>.00</p>
<button class="btn green" onclick="myFunction()">Calculate</button>

After that, apply a float property to each of these newly created divs. To keep them organized, consider placing the three divs within a parent div. It is advisable to use float instead of display: inline-block for better browser compatibility, especially in older browsers.

Answer №2

Take a look at this live example on Codepen.

If you're using display: inline-block to style certain elements within the .calculator parent element, remember that they won't automatically inherit that behavior. You'll need to directly target those elements.

To improve your code structure, consider creating separate classes for calculator components, breaking down the calculator into smaller parts, and replacing paragraphs with spans:

HTML:

<div class="calculator">
  <div class="calculator-submodule input-group input-small">
    <h4>Adult (12+)</h4>
    <button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
    <input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
    <button class="btn theme-btn" id="increase" value="Increase Value">+</button>
  </div>
  <div class="calculator-submodule input-group input-small">
    <h4>Child (2-11)</h4>
    <button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
    <input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
    <button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
  </div>
  <div class="calculator-submodule">
    <span>£</span>
    <span id="total"></span><span>.00</span><button class="btn green"     onclick="myFunction()">Calculate</button>
  </div>
</div>

CSS:

.calculator-submodule {
  display: inline-block;
  padding-left: 1em;
  text-align: center;
}

Answer №3

Give this a shot:

.input-group.input-small {
    display: inline-block;  
}

And add this to your code:

<div class="calculator">
                <div class="input-group input-small">
                    <h4>Adult (12+)</h4>
                    <button class="btn theme-btn" id="decrease" value="Decrease Value">-</button>
                    <input type="text" id="adult" value="1" class="form-control input-usmall" min="0">
                    <button class="btn theme-btn" id="increase" value="Increase Value">+</button>
                </div>
                <div class="input-group input-small">
                    <h4>Child (2-11)</h4>
                    <button class="btn theme-btn" id="decreasec" value="Decrease Value">-</button>
                    <input type="text" id="child" value="0" class="form-control input-usmall" min="0" >
                    <button class="btn theme-btn" id="increasec" value="Increase Value">+</button>
                    <p>£</p><p id="total"></p><p>.00</p><button class="btn green" onclick="myFunction()">Calculate</button>
                </div>
            </div>

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

CSS: Experimenting with creating a hover effect that lifts the box upwards

Hey there! I'm currently working on adding a red hover box for my Menu. The issue I am facing is that the hover box is displaying below the menu line. I am attempting to adjust the hover box to move a bit higher or up. You can view the image here: ht ...

What is the best way to monitor and record the height of a div element in a React application?

Exploring the Height of a Div I am interested in monitoring the height of a div element so that I can dynamically adjust distances based on varying screen widths. The animation should respond to changes in screen width, such as when text stacks and the he ...

Having trouble loading my app.js in Angular - Seeking help on Coursera!

I've followed the instructions provided thus far and inserted the HTML code accordingly. However, upon attempting to load the page, all I see is: The tabs: The Menu Appetizers Mains Desserts The description: image: dish.name , dish.name , dish.labe ...

What is the best way to customize bootstrap styles?

Currently, I am attempting to modify basic CSS attributes within the default theme that is included with a new ASP.NET MVC 5 application in Visual Studio 2013. Specifically, my goal is to change the background color of the navigation menu. With the help o ...

Utilizing jQuery to Manage Trays | Automatically Close Tray on Second click

I am working on a navigation menu with four buttons and a section that contains four additional sections. The functionality I am trying to achieve is that when a navigation button is clicked, a corresponding section slides out while the previous one slides ...

Ways to align elements horizontally while preventing them from shifting positions

I'm faced with a layout challenge where I need to place 2 components side by side, but I want one component to stay on the right without affecting the orientation of the other component. Example: https://i.stack.imgur.com/T5Ram.png Currently, when I ...

Dealing with 'this' while using an addEventListener

I need to trigger the function handleRangeUpdate in a way that it responds to the event calling it and decides whether to run console.log(this.value). The problem arises when I pass e into handleRangeUpdate using addEventListener, causing the value of thi ...

The Alchemy feature on hover is not functioning

I am currently using alchemy.js to display a graph, but I am encountering issues with showing the "onMouseOver" caption of the graph's node. The console is displaying some errors which you can see here. Here is the code snippet: <html> < ...

Ways to align items in the middle of a list

I'm having trouble figuring this out. How can I properly center list items within the ul? body {margin: 0} ul { width: 1000px; margin: 0 auto; padding: 0; list-style-type: none; margin-top: 30px; overflow: hidden; background-color: # ...

Angular is unable to fetch the chosen option from a dropdown selection

Recently, I encountered an issue with a module form that appears as a pop-up. Within this form, users can input data required to create a new object of a specific class. One field allows users to select a ventilation zone for the new room object being crea ...

PHP generated timetable displaying improperly formatted HTML cells

Having some trouble with my HTML table for a school timetable. This is what I want: Required Timetable. But instead, I'm getting something like this: Incorrect Timetable Here's the code snippet: // days of week array $days = array( 1 => &ap ...

Including a Script Tag in an Angular 2 Application with a Source Attribute retrieved from a Web API Request

Situation: Within my Angular 2+ application, I am utilizing a web API to retrieve URLs for script tags created by a function called loadScript during the AfterViewInit lifecycle hook. The web API is providing the expected JsonResult data, which I have suc ...

Ways to turn off the adaptive transient feature

Is there a way to turn off the responsive features and grid layout of Bootstrap? While creating a website for a company, I ensured that it was responsive for mobile devices. However, the company now wants a different design specifically for mobile, with t ...

Tips for resolving div overlap issues when utilizing a customized div within a container-fluid layout (Bootstrap)

As a newcomer to HTML, CSS, and Bootstrap, I encountered an issue with overlapping divs when resizing the screen to be smaller. The problem arose when using container-fluid as a section and implementing a customized div for the section header. Despite atte ...

Tips for troubleshooting grid display issues in Internet Explorer

.container{ display: grid; grid-template-columns: minmax(200px, 7fr) 4.4fr; grid-column-gap: 64px; } .item{ background: red; height: 100px; } <div class="container"> <div class='item item-1'></div> <div class=&a ...

When using Tailwind CSS with flexbox, elements do not expand horizontally as expected

Is there a way to prevent the label from expanding along with the description in tailwindcss? <script src="https://cdn.tailwindcss.com"></script> <div class="flex items-center"> <div>block</div> <div class="m ...

Tips for sending an HTML form through Ajax, storing the data in a file, and then showcasing the results in a div

Embarking on my journey in Web Development, I am currently delving into JavaScript (specifically JQuery) and have decided to kick things off with a Simple Chat project. However, I'm facing an issue with preventing the page from refreshing after a mess ...

I possess a pair of UI tabs. Whenever a button located outside the tab is clicked, I am required to activate a distinct tab

As a beginner in Javascript, I recently encountered an issue with a UI tab element that contains two tabs. My goal is to create a button that, when clicked, will scroll up and activate the second tab. <style> .tab-container { overflow-x: ...

Should I generate an array or pull data directly from the database?

Hey there, I've got this JavaScript app and could really use some input or tips. Here's the idea: Users log in to try and defeat a 'boss', with each player working together in the game. Let's say the 'boss' has 10 millio ...

Populate the database with values when the button is clicked

Hello, I encountered an issue with my code where it is adding empty values to the database when attempting to enter input text values. I am using PHP and MySQL for this task. <html> <body> <input type="text" name="value" /> <input ...