What's the reason for the initial letter of the `textarea` and `input` not being displayed in red color?

Google Chrome 58.0.3029.110 (x64), Firefox 53.0.2 (x64), Linux

Why is the first letter of the textarea element not appearing in red?

The CSS selector textarea::first-line seems to work fine in Google Chrome, but it doesn't in Firefox. However, the textarea::first-letter does not work properly in my example. I am experiencing a similar issue with an input element as well.

I do not encounter any problems when using the p tag instead of textarea or input.

input::first-line,
textarea::first-line {
  color: green;
}

input::first-letter,
textarea::first-letter {
  color: red;
}
<textarea cols='40' rows='4'>Sfrrr sdfsdfsd dsf ddsfds fds fdsfds fsdfds fsdfdsf sd fdss d dsf ssdfddfsddsfdssdsf ss dfsds sdf sdf sdfs fsf sf sdfsdfsdfs df sdffsdf sf sdf sdf sf sf sdf sdf sdf sdf sf sdf sdf sf sdf sdf sdf sfsdfsdf sdf sdf sdfs sdf sdfds dsf sdf sdf sdfsdf sdf dsfs</textarea>
<input value='Sfrrr sdfsdfsd dsf ddsfds fds fdsfds fsdfds' />

Answer №1

To make use of the ::first-letter pseudo-element, you must ensure that your element's display property is set to block and utilize a block level container:

In CSS, the ::first-letter pseudo-element is applicable to block-like containers like block, list-item, table-cell, table-caption, and inline-block elements.

The ::first-letter pseudo-element can be utilized with any such elements containing text or having a descendant in the same flow with text content.

Source: https://www.w3.org/TR/css3-selectors/#first-letter

textarea, input {
  display: block;
}

input::first-line,
textarea::first-line {
  color: green;
}

p::first-letter {
  color: red;
}
<p><textarea cols='40' rows='4'>Sfrrr sdfsdfsd dsf ddsfds fds fdsfds fsdfds fsdfdsf sd fdss d dsf ssdfddfsddsfdssdsf ss dfsds sdf sdf sdfs fsf sf sdfsdfsdfs df sdffsdf sf sdf sdf sf sf sdf sdf sdf sdf sf sdf sdf sf sdf sdf sdf sfsdfsdf sdf sdf sdfs sdf sdfds dsf sdf sdf sdfsdf sdf dsfs</textarea></p>
            <p><input value='Sfrrr sdfsdfsd dsf ddsfds fds fdsfds fsdfds' /></p>

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

Tips for utilizing a function to assess ngClass conditional statement in Angular 2

So as I loop through my list using *ngFor, the code snippet is like this: [ngClass]="{'first':isStartDate(event,day)}" The function isStartDate is defined in my component. An error message appeared: "Unexpected token : " ...

I am having trouble loading the .woff file

I have almost finished the design of my site, but I'm encountering a problem with installing and using a specific font. Do .woff files only display on the web once connected to a server? I'm quite confused about this. Despite following the provid ...

Display a specific element only if another element exceeds a specified height

A snippet of HTML code is given below: <span class="day-number">{{day-number}}</span> <div class="event-box"> <div class="event-container"> </div> <div class="more-events">more ...</div> </div> The .e ...

CSS division style not being properly implemented across entire form

I currently have an HTML form linked to a CSS file. Here is the HTML code: .css-form-group{ margin-bottom:10px; clear:both; } .css-form-group label{ font-weight: bold; } .form-input{ float: right; } .form-input:focus{ background: y ...

The system is experiencing an issue: The function $(…).DataTable is not recognized

My PHP file contains a DataTable that works perfectly without any errors. However, if I try to include an HTML page inside the PHP file, it produces the following error: Uncaught TypeError: $(...).DataTable is not a function After reading this answer o ...

Is it possible to add data in MongoDB without specifying a field name?

I have a couple of queries that revolve around the same concept: If I want to insert a new 'row' in MongoDB, can I do so by specifying the order of the fields? For instance, if my collection looks like items = { { name: "John", age: "28" ...

Tips for navigating through a div with an unknown height

I am currently working on developing a sleek messaging system and I have encountered an issue with the interface design. My project is built using Materialize, however, I am open to tweaking it with custom CSS if necessary. The layout consists of a list of ...

Arrange the divs alongside one another within a container and ensure that the container adjusts its width to fit the children

I am in need of a container div: This div should adjust its width based on the content within. I would like the child elements to align horizontally. The container itself should form a single horizontal line. I prefer not to use flex because it tends to ...

Issue with connecting Drupal 8 theme styling to website pages

Although the theme is functioning properly, the CSS styles are not being applied. Even when inspecting the developer console in Firefox, there seems to be a disconnect with the page. I verified that manually applying the CSS through the developer console i ...

Challenges Arising from Creating an EPL Trivia Game with HTML and Javascript

Having some issues with this game functioning properly. Trying to create a dropdown menu that lists 20 EPL teams, and upon selecting a team, display that team's information in a form. Unfortunately, I'm encountering difficulties with the code. An ...

Incorporating header and footer elements into the design

I am facing an issue while editing a layout. Currently, when clicking on some side of the layout, a header and footer appear in a certain way. However, I would like to change this so that the header and footer appear differently, similar to the example s ...

Display a Loading Indicator within a Bootstrap 4 Modal Dialog

I have a question regarding Bootstrap 4 and a simple trick I am trying to implement. I am looking to display a Loading indicator similar to Twitter every time the user opens the modal. I have some code that is working well, but I seem to have misplaced som ...

Customize the columns of your Angular Material 2 table by defining them using TemplateRef and ngTemplateOutlet

Looking to create a flexible material table with the ability to utilize TemplateRef along with ngTemplateOutlet for generating columns. Check out this demo where I have employed the cards component within my custom material-table component. Inside the card ...

Tips for using jQuery to dynamically apply CSS styles to new content added to a webpage

I have encountered this question multiple times on stackoverflow and through google search, but unfortunately none of the suggested solutions have worked for me. My issue involves a page that loads an HTML page with empty sections, which are then dynamica ...

Ensure your HTML5 videos open in fullscreen mode automatically

I managed to trigger a video to play in fullscreen mode when certain events occur, such as a click or keypress, by using the HTML 5 video tag and jQuery. However, I am now looking for a way to have the video automatically open in fullscreen mode when the p ...

Create a copy of a div element once the value of a select element has

After modifying a select option, I'm attempting to replicate a div similar to the example shown in this link: http://jsfiddle.net/ranell/mN6nm/5/ However, instead of my expected lists, I am seeing [object]. Any suggestions on how to resolve this issue ...

Merging columns in Bootstrap 4 grid system

I have been working on creating a Bootstrap grid with the following structure: .facevalue { background: #ffffff61; font-family: Dubai; font-size: 18px; font-weight: 400; line-height: 30px; padding: 0 30px; border: 1px solid #e9e9e9; ma ...

Unable to progress in an HTML5 Drag and Drop application

I am currently learning HTML5 and I have encountered an issue with a specific example. The code is running without errors, but the drag and drop functionality is not working as expected. I have included the code snippet below. Could you please review it fo ...

Creating sequential hover animations with CSS in HTML

I have a total of four divs that I want to hover continuously, one after the other. Here is the code I am currently using: #rij1 .content-overlayz, #rij1 .content-details { animation-duration: 2s; animation-name: stepped-pulse; animation-iterati ...

Creating a card design that responds to user interactions using CSS and HTML

I attempted to create a responsive queue of playing cards that adjusts based on the display width. I want this queue to perfectly fit the display width so that no card is cut off. It should be optimized for phones, tablets, and desktop screens. Additiona ...