Adjusting the input label to be aligned inside the input box and positioned to the right side

I am currently working on aligning my input label inside the input box and positioning it to float right.

The input boxes I am using have been extended from b4.

Currently, this is how it appears (see arrow for desired alignment): https://i.stack.imgur.com/VMaye.png Here is the layout structure (it's in vue but purely for reference on element arrangement).

    <label class="input-label" :for="index" v-if="showLabel">{{ label }}

        <span v-if="icon" :class="icon"></span>

        <input v-if="form !== false"
                type="text"
                v-validate="validation"
                v-model="current"
                :id="index"
                :name="index"
               :disabled="disabled"
                :placeholder="label"
                class="form-control"
                :class="{ 'is-invalid': form.errors.has(index) }" @input="triggerEvent">

    </label>

Below is my current attempt at applying CSS styling:

f.input-icon {
    position: relative;
}
.input-icon input {
    text-indent: 30px;
}
.input-icon span {
    position: absolute;
    top: 50px;
    left: 15px;
    font-size: 20px;
}
.input-label {
    color: blue;
}
label {
    float: right;
    width: 10em;
    position: relative;
    margin-right: 1em;
}

Answer №1

I have crafted a solution to your inquiry in the form of this demonstration. Feel free to view my creation at CodePen showcasing Form input with right aligned label. Below, you can refer to the simplified version of my code.

HTML

<div class="form-control">
  <label>Example</label>
  <input type="text" placeholder="input">
</div>

CSS

* {
  box-sizing: border-box;
}
.form-control {
  padding: 0.625rem;
  position: relative;
}
label {
  position: absolute;
  top: 1.7rem;
  right: 1.625rem;
  color: blue;
}
input[type="text"] {
  display: block;
  width: 100%;
  padding: 1rem;
}

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

Position a grid item in the center

Can someone help me with centering my container's item? I am struggling to align the third item to the center using display: grid. Previously, I attempted to use flexbox but found it to be less effective for a responsive layout. .projetos { f ...

Transform shapefiles to geojson format using OpenLayers 5

As I embark on a new project that involves combining Vue.js and OpenLayers, I am thoroughly enjoying the process. While I have successfully implemented various functionalities like drawing, reading, and modifying vectors, I find myself stuck when it comes ...

"Exploring the concept of master pages in web development with the combination

Recently, I have been developing a website that functions similarly to olx, displaying ads based on the visitor's location (for example, showing Mumbai ads if the visitor is from Mumbai). Initially, I was planning to create separate pages for each cit ...

Vue i18n locale update does not always immediately reflect in all components

Currently, I am developing a web application utilizing the **Vue framework**, and for internationalization purposes, I am implementing vueI18n. However, I have encountered a problem where changing the language locale does not immediately reflect in all com ...

Automatically filling out a Pug form using an Express/Node.js web application

My Node.js web app is created with Express and I am attempting to populate a Jade template after querying MongoDB. The goal is to fill the Jade template with the queried values. One thing that puzzles me is that even when I remove everything within the co ...

What could be causing my PHP login page to malfunction?

I'm facing an issue with my code where nothing happens when I click the submit button. This is puzzling as the same code worked perfectly fine in a previous project. I'm unable to pinpoint where the problem lies. Here's the HTML form: < ...

What is the process for combining multiple Vue components into a cohesive npm package?

My project manager at work tasked me with creating a single npm package for all the global components in our Vue project. This package should be easily importable and usable by everyone working on the project, similar to how Vuetify is imported from the no ...

Achieving left text alignment in CSS for an excerpt using the Ultimate Posts Widget on Wordpress

I've been trying to align the text in the excerpt of a widget called "To-Do List" on the left sidebar. I attempted to set the text-align property to left for the excerpt text, targeting the p tag within the .widget_ultimate_posts, .uw posts using CSS ...

What could be causing my dropdown links to malfunction on the desktop version?

I've been developing a responsive website and encountering an issue. In desktop view, the icon on the far right (known as "dropdown-btn") is supposed to activate a dropdown menu with contact links. However, for some unknown reason, the links are not f ...

The outcome when submitting an HTML survey

I have a curiosity about what really happens when you click the submit button on an HTML survey like the one displayed below: <INPUT TYPE="radio" NAME="bev" VALUE="no" CHECKED>No beverage<BR> <INPUT TYPE="radio" NAME="bev" VALUE="tea">Te ...

Error found - PHP if condition inside HTML td element

Whenever I open my browser, I encounter this error message: Parse error: syntax error, unexpected 'if' (T_IF) I have been working on creating an HTML table to display prices for a Woocommerce product. Although I've come across similar issu ...

Sorting price and date with Vue in Laravel - A beginner's guide

Attempting to sort by price and by date. See the code below. I decided not to use the controller for this sorting. Is it feasible to implement it here? It's somewhat functional, but there are some issues. When selecting price, it doesn't seem to ...

Template file for the contact form 7 plugin in Wordpress

I'm currently utilizing the Contact Form 7 plugin on my Wordpress website and I'm curious about which template it directs to when I enter mysite.com/contact/ into the browser. I am interested in making some edits to the template file, but I am un ...

What's the best way to incorporate necessary styles into text using particular fonts?

Is there a way to set letter spacing and word spacing for text on my website with the font 'classylight'? Adding classes to each post in the site map seems like a lengthy process. To save time, I attempted to use the attribute*=style property to ...

Is there a way to retrieve the value from a moment-formatted date picker in the (YYYY-MM-DD) format?

I have a Vue application with a datepicker from Ant Design Vue that is returning the following moment object: Moment {…} _d: Thu Oct 24 1996 00:00:00 GMT+0800 (Malaysia Time) _f: "YYYY-MM-DD" _i: "1996-10-15" _isAMomentObject: (...) _isUTC: (...) _isVal ...

Using the not operator in Selenium IDE XPath for waitForElementNotPresent seems to be ineffective

I am facing an issue with an XPath in Selenium IDE. In a table, there are multiple records. Above the table headers, there are filtering dropdown menus and a funnel icon that triggers an AJAX function to retrieve filtered data. The problem is that Seleniu ...

Adjust the text area to automatically expand or shrink based on the text it contains

Is there a way to automatically adjust the size of a textarea based on its content? Here is the code I am currently using for this purpose: var element = document.getElementById(event.target.id); var content = $(this).val().trim(); if (content == "") { ...

Sending data from a parent component to a child component through a function

In the process of developing an app, I have implemented a feature where users must select options from four dropdown menus. Upon clicking the "OK" button, I aim to send all the selections to a child component for chart creation. Initially, I passed the sel ...

Is it possible for a div to extend beyond the previous div's boundaries using CSS?

When viewing a website like GameFAQs, you may notice that there are two divs positioned next to each other - the main content and an aside (such as a poll). As you resize the window, the aside sometimes moves down below the main content without leaving any ...

Setting up Visual Studio Code for debugging HTML and JavaScript code

Struggling to troubleshoot some HTML/JavaScript using VSCode. After installing the Chrome debugger extension and configuring the launch.json as follows: { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of ex ...