What is the method for positioning the cursor at the beginning of a center-aligned placeholder within a contenteditable element?

Here is the code snippet I am working with:

HTML:

<div class="title" contenteditable="true" placeholder="Title"></div>

CSS:

.title {
   width: 500px;
   margin: 0 auto;
   text-align: center;
}

[contenteditable=true]:empty:before{
   content: attr(placeholder);

}

Currently, the editable div is centered with a placeholder. However, the issue I am facing is that when the div is focused for the first time, the cursor appears at the beginning of the text, not at the placeholder: !

I would like the placeholder to stay visible until a character is entered, with the cursor positioned at the beginning of the placeholder text. Are there any suggestions on how to achieve this?

Thank you!

Answer №1

Here's a solution to the problem at hand:

Modify your CSS as follows:

.header {
   width: 600px;
   margin: 0 20%;
}

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

Overflow issue occurs in react-bootstrap when a Table is placed within the Card.Body

Looking to design a responsive table with a row details section inside a card using react bootstrap. I have applied different colors to the sections for better visual understanding. However, I am facing an issue where the card body slightly overflows the ...

An instructional guide on utilizing Python to extract the URLs of companies from a LinkedIn search

I'm having an issue extracting company profile URLs from a LinkedIn search as I keep getting a "not found" message. Despite my code running smoothly, the problem persists. Here is my code: import requests import csv import time import numpy from bs4 ...

Sinon - the ultimate guide to intercepting the save() function in a mongoose schema

Currently, I am in the process of writing unit tests for an API that utilizes MongoDB in conjunction with mongoose for database access. Within my codebase, there exists a model file that defines and exports a mongoose model as shown below: const { Schema, ...

Vue.js The mp3 files have been successfully added to an array, yet the audio remains silent

While coding, I faced an issue that I resolved by doing some research online and tweaking the sample code. As I added more lines of code, I encountered sections that were a bit confusing to me, but I managed to make them work. My main objective is to devel ...

Is your preference selecting made a breeze by dragging the input field?

Looking to create a form that allows users to indicate their preference between Option A and Option B by dragging a slider. I know there must be a library out there that already does this, but I can't seem to figure out what it's called to searc ...

There was an issue encountered when trying to call a PHP file within an HTML table using Ajax and data.html

For a small project, I have various news items that need to be included from the "news_all.php" file into table data within the "dashboard.php" file. Due to the predefined root structure restrictions, using include('news.php') is not an option. I ...

Converting JSON into key-value pairs using ReactJS

Here is a JSON object that I have: [ { "crime": "LARCENY-NON_VEHICLE", "count": "23217" }, { "crime": "AUTO_THEFT", "count": "13675" ...

Master your code with Rxjs optimization

Looking at a block of code: if (this.organization) { this.orgService.updateOrganization(this.createOrganizationForm.value).subscribe(() => { this.alertify.success(`Organization ${this.organization.name} was updated`); this.dialogRef.close(true ...

The content is not adapting properly for mobile devices (Bootstrap)

Currently, I am in the midst of a project and require assistance in ensuring an element on my webpage is responsive. Specifically, I need the text within a box to overlap the accompanying image when the browser window is resized. Should I add a class to th ...

Customizing the appearance of several elements in CKEditor by applying inline styles

I am looking to apply inline styling to multiple HTML elements using the CKEditor's inline style option. In order to achieve this, I have included the following code snippet in the styles.js file: { name: 'Red italics', element: 'p&apo ...

Guide to implementing the Office 365 Javascript API in your application

Looking to integrate an Office 365 Excel sheet with the necessary toolbars into my web-based application, similar to this setup (including the Excel Online toolbar above). Link Here Unsure of the process - is there a way to implement tables and toolbars ...

php failure to execute included file

Hey there! I'm currently facing an issue with including a file that contains all of my 'head' information. My goal is to simplify and streamline my page by breaking it down. In my index.php file, here's what I did: <?php include & ...

Steps for setting up single sign on in an Angular 2 application

Currently, I am working on a web application that has been developed using angular2. One of the requirements for this application is to incorporate a single sign-on feature, where users do not have to manually input their login credentials. Instead, the ap ...

Generating unique ID's for data posting in PHP and JavaScript

I've developed a dynamic form that includes an "add more" button to generate an XML file for data import purposes. Users can fill out the form and add as many entries as needed by clicking on the "add more" button. The inputted data is then processed ...

Modify the content while leaving the button's design intact

So I have this unique scenario where I've created a button with an icon using bootstrap and font-awesome: <button id="btnFavorite" class="btn btn-warning pull-right" style="margin-right: 5px;" onclick="addToFavorites()"> <i id="imgFavori ...

Modifying linked dropdown selections with jQuery

I'm trying to create a recurrent functionality where I have 3 select elements. When the first select is changed, it should update the second and third selects accordingly. If the second select is changed, then it should also affect the third select. ...

Integrate JavaScript into your HTML code

I'm a beginner in HTML and am working on creating a login form. Here is the code that I have written so far. I need help with importing my JavaScript code into the HTML form. C:\Program Files\xampp\htdocs\forsiteSystem\thems& ...

Refresh the vue-owl-carousel following a dynamic data update

Utilized vue-owl-carousel with dynamic content <script> import carousel from 'vue-owl-carousel' export default { components: { carousel }, } <carousel :items="1"> <img v-for="(img, index) in images" ...

Merge rxjs streams, identify modifications, and yield a single result

In the context of using Angular with .net Core WebApi, let's consider the development of a time management application designed to monitor task durations. The user initiates a task on the front end which triggers a timer displaying elapsed time. The ...

Having Trouble with Bootstrap and jQuery AJAX .post Function

My login form functions properly when submitted with a traditional HTML form post method. <form class="form-horizontal" id="loginform"> <div class="control-group"> <label class="control-label" for="user_name"> Use ...