Addressing three visual problems with an html form input, dropdown menu, and clickable button

Currently, the output of my code looks like this:

https://i.stack.imgur.com/pl5CJ.jpg

The first box (squared) represents an <input>, while the second box (rectangled) is a <select>. There are several issues that I am facing:

  1. The text entered in the <input> box does not appear, and similarly, the selected option does not display in the <select> box.
  2. The green button should be centered, and despite using the CSS properties text-align: center and align-content: center, it remains off-center.
  3. Upon hovering over the button, it should increase in size by 1.1 times using the CSS line transition: scale(1.1), but this effect is not taking place.

<template>
  <div id="food-info">
    <div class="division center">
      <h3 class="division">Banana</h3>
      <h4 class="division">Serving size</h4>
      <input class="division quant-input" />
      <select class="division quant-sizes">
        <option>100g</option>
        <option>large</option>
      </select>
    </div>
    <div>
      <button class="add-entry center">Add to Diary</button>
    </div>
  </div>
</template>

<style scoped>
.center {
  text-align: center;
  align-content: center;
}
.division {
  display: inline-block;
  padding: 1rem 1rem;
}
.quant-input {
  height: 10px;
  width: 10px;
}
.quant-sizes {
  height: 10px;
  width: 80px;
  top: 40px;
}
.add-entry {
  width: 300px;
  background-color: #4caf50;
  color: white;
  border-radius: 10px;
}
.add-entry:hover {
  transition: scale(1.1);
}
</style>

Answer №1

It appears there are multiple errors in your code:

  1. The padding is set on the .division element, which does not leave room for content in the input and select elements.
  2. To center elements vertically using align-items instead of -content, you should use the following CSS:
.parent-elmnt {
    display: flex;
    justify-content: center;
}
  1. Instead of using transition, you should be using transform.
.add-entry:hover {
    transform: scale(1.1);
}

Please review the following:

      /* Add these codes to variables.css */

      :root {
        --primary-color: #4caf50;
        --text-color: #fff;
      }

      /* Add this code to your reset.css */

      :root {
        font-size: 16px;
      }

      * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
        font: inherit;
      }

      h1 {
        font-weight: bold;
        font-size: 1.25rem
      }

      button {
        outline: none;
      }

      /* Add this code to utilities.css */

      .p-2 {
        padding: 0.5rem;
      }

      .p-4 {
        padding: 1rem;
      }

      .mb-4 {
        margin-bottom: 1rem;
      }

      .flex {
        display: flex;
      }

      .column {
        flex-direction: column;
      }

      .justify-center {
        justify-content: center;
      }

      .justify-space-between {
        justify-content: space-between;
      }

      .w-full {
        width: 100%;
      }

      .rounded-pill {
        border-radius: 500rem;
      }

      /* Add these codes to your components.css */
      .btn {
        background-color: var(--primary-color);
        color: var(--text-color);
        border: none;
        padding: 0.5rem;
        transition: all 0.5s;
      }

      .btn:hover {
        transform: scale(1.02);
      }
      
      /* Then import all of these files into your main.css */
      
    <div class="p-4 mb-4 flex column justify-center">
      <h1 class="mb-4">Banana</h1>

      <div class="flex justify-space-between">
        <h2>Serving size</h2>
        <div>
          <input class="p-2" />
          <select class="p-2">
            <option>100g</option>

            <option>large</option>
          </select>
        </div>
      </div>
    </div>
    <div class="p-4">
      <button class="btn w-full rounded-pill">Add to Diary</button>
    </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

Can you explain how I can use AJAX in HTML to change the text of a link once it has been clicked on?

I have a link titled Save to Favorites. This link triggers an AJAX function when clicked, which updates the text of the link to say Remove from Favorites. Clicking it again changes it back to Save to Favorites. What code should I include in the link itsel ...

Utilizing jQuery to Perform Calculations with Objects

Can someone help me with a calculation issue? I need to calculate the number of adults based on a set price. The problem I'm facing is that when I change the selection in one of the dropdown menus, the calculation doesn't update and continues to ...

Programmatically control the opening and closing of a React Material UI Snackbar component

Currently, I am facing some challenges while working on programming a Single Page Application (SPA) using React and Material-UI. In my project, I have created a modal login box that gets triggered by a button on the navigation bar. Upon clicking submit, I ...

Transform JSON reply in JavaScript/Typescript/Angular

Looking for assistance with restructuring JSON data received from a server API for easier processing. You can find the input JSON file at assets/input-json.json within the stackblitz project: https://stackblitz.com/edit/angular-ivy-87qser?file=src/assets/ ...

Displaying a collection of items using Rails, implementing form_for and integrating Ajax functionality

Looking to display a list of "Interests" for users to "follow" by clicking on a button linked to the Interest's image. Once the follow button is clicked, the Interest and its image should be removed from the list. Attempting to use a hide function in ...

Tips for automatically updating the time in a React application while utilizing the 'date-fns' library

I've been working on my personal Portfolio using React and I'm looking to add a feature on the landing page that showcases my local time and timezone to potential recruiters. However, there's a small hiccup in my implementation. The displaye ...

I am trying to figure out how to properly utilize server-only functions within Next.js middleware

In my current project, I am utilizing Next.js 13 along with the App Router feature. While attempting to include a server-specific fetch function in middleware.js, an error message is encountered: Error: Unable to import this module from a Client Compone ...

When a d3 event is triggered by clicking, the value should be saved in a textbox

After clicking the checkbox, I would like to have all the checked client IP values automatically populate a textbox within the div called "ip." Here is my code snippet: <html> <body> <div id="ipDiv"> Client_ip :<input ty ...

What is the best way to attach a jQuery UI event handler to a button that has been dynamically generated?

Currently, I have a jquery ui modal dialog box form that inserts items into a table. A specific column in the table contains a button which serves as a link to edit the particular row. My goal is to attach an event handler to this button so that when a use ...

Ways to enable file/result downloads on a website using HTML

Could you please take a look at this repository: https://github.com/imsikka/ArtGallery I am looking to create a downloadable result using a download button. I can create the button, but I am unsure of how to make the file actually downloadable. Do I need ...

Attempting to fetch the user's username using jQuery from the database

echo "<form method='post' action='regprocess.php' id='registerform'>"; echo '<fieldset class="register">'; echo"<h2>Register</h2>"; echo "<ul>"; ...

Utilize jQuery to substitute numbers with strings through replacement

My question pertains to the topic discussed here. I am looking for a more refined jQuery replacement function that can substitute a number with a string. My PHP script returns numbers in the format of 1.27 Based on a specified range, these numbers need ...

Angular form array inputs

Currently delving into the world of Angular.js, I have encountered a simple problem that has left me baffled. My objective is to generate form inputs with the value of "connectedTeams" in HTML: <input type="text" name="connectedTeam[]"> <input ...

Generating additional react-select dropdowns depending on the selection made in the initial dropdown menu

I am currently working on a travel website. I am in need of a dropdown menu for users to select the number of children they will be traveling with, with options for 1, 2, or 3. If the user chooses 1 child, then an additional react-select element should ...

Encountering an error with NextJs & Strapi when utilizing the getStaticPaths functionality

Currently, my project involves using Strapi to develop a custom API and NextJs for the frontend. I am experimenting with utilizing getStaticPaths to generate pages based on different categories. In Strapi, I have set up a collection for categories that is ...

Retrieve all colors from the style attribute

I'm on the hunt for a method to extract all CSS colors from a website. Currently, I have been able to manage internal and external stylesheets by utilizing document.styleSheets. However, my issue lies in the fact that any styles directly assigned to a ...

Struggling to incorporate a basic drop-down into my design despite implementing transitions

Looking to optimize space on a webpage, I am interested in creating a hover effect for topics that reveals sub-topics with a smooth ease-out animation. Here is an example of the effect I am aiming for: https://jsfiddle.net/170z6pj1/ I have been strugglin ...

Encountering difficulty in retrieving the outcome of the initial HTTP request while utilizing the switchMap function in RxJS

My goal is to make 2 HTTP requests where the first call creates a record and then based on its result, I want to decide whether or not to execute the second call that updates another data. However, despite being able to handle errors in the catchError bl ...

Unable to access the attributes of the mongoose model

I'm experiencing an issue with my mongoose model.find code below Displayed here is my node.js code that utilizes mongoose to interact with MongoDB. However, upon running it, I encounter the following error message: Starting... (node:7863) Unhandl ...

Varied selection menu feature

Looking to build a new component: The idea is to create something similar to a dropdown list. I aim to incorporate this component into every cell (td) of table rows. The challenge lies in displaying the second div (item list) under the first div, but abov ...