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

Issue with parentNode.replaceChild not functioning properly in Internet Explorer 6

In my HTML file created with FCK editor, I attempted to replace an existing table element with a new one using the parentNode.replaceChild method. While this change was successful in Internet Explorer 8, it resulted in errors when viewed in IE6 and IE7. ...

The ace.edit function is unable to locate the #javascript-editor div within the mat-tab

Having trouble integrating an ace editor with Angular material Error: ace.edit cannot locate the div #javascript-editor You can view my code on StackBlitz (check console for errors) app.component.html <mat-tab-group> <mat-tab label="Edito ...

Is it possible for a search box selection toggle to reveal a hidden information box underneath it containing all the compiled data?

Improve the user experience on my website by implementing a search feature for US states and Canadian territories. When visitors type in their selection, I want them to be able to click on an icon that will reveal relevant information about that choice. T ...

Establishing a unique URL and updating Vue.js Vuex state based on its parameters

My Vue.js Single Page Application allows users to input multiple values to create a recipe, all stored in Vuex state. I want to generate a URL based on these values so that users can share the recipes they create via a link. I envision a "share" button th ...

Tips for creating horizontal scrolling in the div element

I'm working with a div element that looks like this: <div id="tl" style="float:right;width: 400px; height:100px; background-color:Green; overflow-x: scroll;overflow-y: hidden;"> <div id='demo' style="float:left;height ...

Unable to set the correct title view for mobile devices

We have successfully styled the products for desktop view and larger phones, but we are facing challenges in adjusting them properly for smaller phones. Below you will find a photo and corresponding code snippets: /* Products list - view list */ .product ...

Leveraging useEffect and useContext during data retrieval

I'm currently in the process of learning how to utilize React's Context API and Hooks while working on a project that involves using fetch(). Although I am able to make the request successfully, I encounter an issue where I can't retrieve t ...

How to Use Jquery to Retrieve the Selected Option Value and Append a Parameter

I am attempting to expand the value by adding "&fullpage=true" <select name="navMenu" onchange="go(this.options[this.selectedIndex].value)"> <option value="-">Choose</option> <option value="page.html&amp;nyo=0" class="ccbnLnk" ...

Ensure that the div spans the entire width of the page, prioritize maintaining the aspect ratio, but allow for variable

I have a dilemma with a div containing multiple elements. My goal is to make the div 100% in width, while also attempting to preserve the aspect ratio if feasible. Should the enclosed elements exceed the div's boundaries, then the height will adjust a ...

Create a table within the B-Col element that automatically adjusts its size to match the column width using Vue-Bootstrap

Within my Vue component, I have the following code snippet: <b-modal ...> <b-row> <b-col sm="12"> <table > <tr v-for=... :key="key"> <td><strong>{{ key }}: </str ...

Wait for Axios Request Interceptor to complete before sending another ajax call

One feature I have added is a request interceptor for all axios calls. This interceptor checks the JWT token and automatically refreshes it if necessary. axios.interceptors.request.use((config) =>{ const currentState = store.getState(); // get upd ...

Alert displayed on console during transition from MaterialUI lab

Whenever I try to run my MUI application, an error pops up in the console It seems you may have forgotten to include the ref parameter in your forwardRef render function. import { LoadingButton } from "@mui/lab"; const LoadData = ({loading,sig ...

Trouble with the ejs <%- body %> rendering properly

I plan to utilize a predefined layout template named layout.ejs, and here is the code present in the file: <html> <head> <title></title> </head> <body> <%- body %> </body> </html> Currently, I ...

The component is unable to access VueJS references

Below is a simplified version of the code I am working with: <html> <head> <script src="file:///D:/OtherWork/javascript/vue/vue.js"></script> </head> <body> <div id="app"> & ...

Sending Location Data From JavaScript to PHP via Cookies

I encountered an issue while attempting to send Geolocation coordinates from JavaScript to PHP using Cookies. The error message I am receiving is: Notice: Undefined index: data in /Applications/XAMPP/xamppfiles/htdocs/samepage.php on line 24 The file name ...

Utilizing various Material UI Sliders on a single page with shared color properties

After creating a component called "SliderBox", I noticed that it returns a div containing a Material UI Slider with createMuiTheme and an input component. The "SliderBox" component utilizes an onHover method on the parent div to change the component' ...

The function fs.createReadStream does not exist

Snippet to Submit Career Form: import axios from 'axios'; import FormData from 'form-data'; var fs = require('fs'); submitCareerForm(e){ e.preventDefault(); let formData = new FormData(); //formdata obje ...

Choosing to maintain an open server connection instead of regularly requesting updates

Currently, I am in the process of developing an innovative online presentation tool. Let's dive into a hypothetical situation: Imagine one person is presenting while another connects to view this presentation. >> How can we ensure that the viewer&ap ...

Fill a dropdown menu with options from a JSON object, arranging them in ascending order

I have a JSON hash that I am using to populate a combo box with the following code: $.each(json_hash, function(key, value) { $("#select").append("<option value='" + key + "'>" + value + "</option>"); }); The functionality w ...

Why isn't my function being triggered by the Click event?

I can't figure out why the click event isn't triggering the btn() function. function btn() { var radio = document.getElementsByTagName("input"); for (var i = 0; i > radio.length; i++){ if (radio[i].checked){ alert(radio[i].value); } ...