How can I center one middle position for my inputs and have the span align to the left?

How can I center my input fields with all the spans aligned to the left?

I would like the inputs to be centered on the page, with supporting spans aligned to the left or right of the input lane.

I am utilizing some Bootstrap 4 classes for this layout.

CSS

span {
    color: oldlace;
}

input {
    position: relative;
    display: inline-block;
}

HTML

<form (submit)="submit()">

  <div id="egg" class="invisible">
    <span class="p-1">Egg</span>
    <input class="text-center rounded-pill border border-danger p-1 m-1" type="number" title="Egg" name="egg"
      placeholder="gram" [(ngModel)]="protein.egg">
    <!-- <span class="p-1"> size</span><br> -->
  </div>

  <div id="bread" class="invisible">
    <span class="p-1">Bread</span>
    <input class="text-center rounded-pill border border-danger p-1 m-1" type="number" title="Bread" name="bread"
      placeholder="gram" [(ngModel)]="protein.bread">
    <!-- <span class="p-1"> slices , 30g pre slice</span><br> -->
  </div>

</form>

https://i.sstatic.net/Mr0N7.jpg https://i.sstatic.net/85xqq.jpg

Answer №1

Applying width to span elements is possible.

.spanE {
    display: inline-block;
    width: 5rem;
}
<form (submit)="submit()">
<div id="egg" class="invisible">
<span class="p-1 spanE">Egg</span>
<input class="text-center rounded-pill border border-danger p-1 m-1" type="number" title="Egg" name="egg"
placeholder="gram" [(ngModel)]="protein.egg">
<!-- <span class="p-1"> size</span><br> -->
</div>

<div id="bread" class="invisible">
<span class="p-1 spanE">Bread</span>
<input class="text-center rounded-pill border border-danger p-1 m-1" type="number" title="Bread" name="bread"
placeholder="gram" [(ngModel)]="protein.bread">
<!-- <span class="p-1"> slices , 30g pre slice</span><br> -->
</div>
</form>

Answer №2

Utilize the tablet in a singular column layout where the first column is designated for entering field names and the second column is reserved for input fields.

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

When transformed into clickable links, the list items start piling up on

Here are two groups of code along with a straightforward question that most people can answer easily, but still worth asking. Below is the initial piece of code with working CSS implementation: <div class="subTopHolder"> <ul class="language ...

Why does the HTML and CSS slider fail to load upon page refresh, yet works perfectly when the next or previous button is clicked?

There seems to be an issue with the slider images not loading on page refresh. Oddly enough, they appear only after clicking the next button. However, upon refreshing the page again, the images disappear. <div class="slide-banner"> < ...

Having an issue with a cropped CSS box?

I have created a CSS box with a red background color, but for some reason the bottom left corner is being cut off. Can you provide an explanation for this issue? (Refer to the image below) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

Tips for changing the default height of Elastic UI dropdown menus

I am attempting to adjust the height of the Task combobox to match that of the Date Picker, but the styling is not being applied when done through a class or inline. https://i.sstatic.net/3Cua1.png I have tried inline styling the element as: <EuiForm ...

Tips for deactivating dropdown values based on the selection of another dropdown

There are two dropdown menus known as minimum and maximum, each containing numbers from 1 to 25. If a value is selected from the minimum dropdown (e.g. 4), the maximum dropdown should only allow values that are equal to or greater than the selected value ...

Navigate audio tracks with JavaScript

I'm currently facing an issue with using a button to switch between two audio tracks being played in the browser. The method I have implemented switches to the second track, but it doesn't change the audio that is played afterward - instead, it s ...

What distinctions are there between placing a `<link rel="stylesheet" href=..video.scss>` in the index.html versus utilizing `import '../video.scss'`?

As a newcomer to React.js, I've observed that there are different ways to include stylesheets in a React Component. Some developers use the import method like this: import '../../styles/video.scss while others prefer to link the stylesheet dire ...

The little DIV strayed beyond the boundaries of its parent DIV

I am facing a challenge with the positioning of nested divs within my parent div. The first two are aligned correctly, but the third one is dropping down outside of the parent div on the y-axis. I have tried various solutions from StackOverflow without suc ...

react-datepicker displaying error message "Preventing default action not possible within a passive event listener invocation"

I've integrated the react-datepicker library in portal mode. While it functions well on browsers, I encounter an error when using mobile browser mode. An issue arises stating: "Unable to preventDefault inside passive event listener invocation" Des ...

Styling certain UL and LI elements with CSS properties

Greetings everyone! I constantly struggle when it comes to making my CSS cooperate. I have some code that involves using ul and li tags. However, I only want to apply that styling to specific sections of my HTML code rather than all instances of the ul and ...

Tips for including a line within a circular canvas

My progress bar crafted with css, javascript and html looks great (left image). However, I'm facing a challenge in adding white color dividers to enhance the appearance of the progress bar as shown in the image on the right. Despite my various attemp ...

I Tried Adding Up All the Numbers, but It Doesn't Seem to Work for Every Dynamic Total Field

In my project, I am utilizing Laravel 5.7 and VueJs 2.5.*. The issue I am facing is that when I input values, the Total field calculates correctly. However, when I dynamically add rows for items, the calculation only works for the first row and not for the ...

tainted ajax outcome

Check out this HTML page I am using: <html> <head> <title>AJAX Example</title> <meta http-equiv="Content-Type" content="text/html"; charset="iso-8859-1"> </head> <script language="JavaScript" src="ajaxlib.js"> ...

Tips for setting up a popup menu when clicking a button on a webpage

I am currently working on developing a popup menu with a greyed-out background that appears when the user clicks on a button in React. My code implementation is as follows: // The ifButtonClicked function is called when another button is clicked // Some ...

make changes to the current selection in the drop-down menu

Imagine I have a select list with 3 options: <select> <option>1</option> <option>2</option> <option>3</option> </select> My goal is to create a textfield and button that will allow me to upd ...

Achieving Dynamic Alignment in CSS: How to Responsively Align a Div to the Width of its Parent Using Padding and Margins

My dilemma could not be clearer - I am struggling to properly align 4 divs within a width of 1150px (the maximum width of the content div). When resizing the screen, I want them to adjust accordingly: 4 in a row when possible, then 3 in the center, and so ...

Is there a way to position one DIV behind another?

Hey, I'm working on my first project and running into some trouble with divs. I'm trying to position the firework behind the central text but can't figure it out. Can anyone lend a hand? I need to add more details in order to submit the que ...

Can you explain the purpose of the text-align property set to justify-all?

Can you explain what the CSS property text-align: justify-all does? According to MDN, it should justify even the content of the last line. However, I am not seeing any changes in my Chrome browser: <p style="text-align: justify-all"> one two thre ...

Guide on resolving the issue of disabled button's tooltip not appearing upon being hovered over

I have a button that looks like this: <a data-toggle="tab" href="#part4" class="btn btn-info tabcontrol mainbutton col-2 offset-8 disabled" id="part3to4" title="Please acknowledge the checkbox before going next" data-toggle="tooltip" data-html="true" d ...

Ensure that Bootstrap collapse is opened on desktop devices but closed on mobile devices

Is there a way to make a collapse open on desktop and closed on mobile using only Bootstrap? On Desktop: https://i.sstatic.net/IwHCv.png On Mobile: Here, the content should only be displayed when you click on the title of each group https://i.sstatic.n ...