Text area featuring unique border design, with border color change upon focus?

Currently, I have a text area with borders that are designed in a unique way. However, I am looking to change the border color when the user focuses on the text area.

Do you have any suggestions on how I can achieve this effect without affecting the current design?

Answer №1

To achieve this effect with images, you can follow a similar approach to what you would do for non-image elements:

.profilePic {
    background-image: url('frame.jpg');
}

.profilePic:hover, .profilePic:focus {
    background-image: url('frame-highlight.jpg');
}

Of course, your image frames may be more intricate than this example, but the basic idea remains the same. Even if you have nested elements, the technique should still apply. If you encounter any challenges, feel free to share your code, and I will offer my assistance.

Answer №2

Here is a clever workaround using only CSS that focuses on the focus event (unfortunately, :focus pseudoclass does not work in IE<=8)

Just tested this on Firefox. It may need some adjustments and extra styles for webkit browsers, but it serves as a good starting point. Personally, I find using a background solution much simpler considering the amount of CSS and element positioning tricks needed.

Here are the relevant HTML and CSS snippets:

<fieldset>
    <textarea></textarea>
    <label>insert text here</label>
</fieldset>

fieldset { 
   position: relative; /* Rest of the properties */   
}

label {
   position : absolute; /* Rest of the properties */
}

textarea {
   position : relative; /* Rest of the properties */   
}

label:before {
  content   : ""; /* Rest of the properties */
}

label:after {
  content   : ""; /* Rest of the properties */
}

textarea:focus, 
textarea:focus + label:before {
   border-color : red; /* Changing border color when focused */
}

Answer №3

An effective method using only CSS: Place the textarea within a div, and then add another div after the textarea to achieve the desired border shape.

SEE DEMO

Here is the HTML code:

<div class='content'><textarea></textarea><div class='borders'></div></div>

This is the CSS code:

.content { display: inline-block; position: relative; }
textarea {
    width: 18em;
    border: solid 1px;
}
.borders {
    position: absolute;
    top: -.3em; left: 1.8em;
    width: 0.9em;
    height: 0.9em;
    border-top: solid 1px;
    border-left: solid 1px;
    transform: rotate(45deg);
    background: white;
}
textarea:focus, textarea:hover, textarea:focus + .borders, textarea:hover + .borders {
    border-color: blue;
    outline: none;
}

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 customizing the color of mat-select placeholder text?

I've been attempting to modify the color of a mat-select placeholder. It functions properly when using 'background-color' but not when using 'color'. Below is my CSS code: /deep/ .mat-select-placeholder { color: red; } .mat-s ...

Is there a way to adjust the input type date format to show mm/dd/yy?

My input type is set to "date" with the default format of mm/dd/yyyy. However, I would like to change it to mm/dd/yy. Is there a way to adjust the format of a date input? Date: <input type="date" id="date" name="date" value="mm/dd/yy" required/> ...

Express encounters difficulties loading JavaScript files

I'm currently working on building an express web app, but I'm encountering a problem with importing a javascript file. Within board.js, there's a line const utility = require('./utility');. However, this line is causing an error: ...

Every time I try to utilize "useCallback," it results in a TypeError error popping up

I am struggling with an issue related to a const experience that involves creating 6 experiences with their respective popovers. I have been instructed to use useCallback, but every time I attempt to do so, I encounter an error message. This relates to my ...

``Considering the compatibility issues with position: absolute in Internet Explorer 8

Here's an example snippet of code in HTML: <form> <input type="file" id="iefile"> </form> <form> <input type="file" id="iefile"> </form> This is how it looks with some CSS styling: form{ position:rela ...

Double invocation of useEffect causing issues in a TypeScript app built with Next.js

My useEffect function is set up with brackets as shown below: useEffect(() => { console.log('hello') getTransactions() }, []) Surprisingly, when I run my app, it logs "hello" twice in the console. Any thoughts on why this might be ...

fullpage.js: the content exceeds the height limit

I am currently working on customizing the jquery script fullpage.js for a website built on the French CMS "SPIP" (). This script is used to create a one-page website with both horizontal and vertical navigation. However, I have encountered an issue with ...

Tips for designing a navbar specific to a profile section

I am currently working on an angular application with a navigation bar composed of anchor tags. When the user logs in, I have an ngIf directive to display my profile icon with dropdown options. However, I am facing challenges in styling it correctly. I aim ...

Exploring the benefits of leveraging Express with SSL security features

I recently acquired a Comodo SSL certificate for setting up an SSL server with express. The certificates I have include: AddTrustExternalCARoot.crt COMODORSAAddTrustCA.crt COMODORSADomainValidationSecureServerCA.crt mysite.com.key mysite.com.csr mysite_co ...

Saving the created PDF documents on the server

Utilizing the jsPDF plugin, I am currently generating a .pdf file upon clicking a button to initiate a download. Rather than downloading the file, I would like it to be saved onto my server when the button is clicked. Specifically, I want the file to be sa ...

What is causing the search feature to malfunction on the Detail page?

In my project, I have different components for handling shows. The Shows.jsx component is responsible for rendering all the shows, while the ProductDetails component displays information about a single show. Additionally, there is a Search component which ...

Saving, displaying, and removing a JSON document

As someone new to the world of JavaScript, I am encountering an issue with JavaScript and AJAX. I am aiming to create a function that allows me to add new elements with unique indexes. After saving this information to a JSON file, I want to display it on a ...

Ways to position a div at the center of a page

I've encountered a challenge while creating a mobile website. Within the main div, there are three nested divs. Initially, I aimed for left alignment but now desire to center-align these three divs on the page. Essentially, if the device screen is wid ...

Toggle visibility of a div with bootstrap checkbox - enforce input requirements only if checkbox is marked

Lately, I've been facing a strange issue with using a checkbox that collapses a hidden div by utilizing bootstrap. When I include the attribute data-toggle="collapse" in the checkbox input section, the div collapses but it mandates every single one o ...

Storing data in a TypeBuffer and then retrieving it from a file can lead to surprising outcomes

Upon executing the following code: var list = new Uint32Array(16); for (var i=0; i<16; ++i) list[i] = i; fs.writeFileSync("list", new Uint8Array(list).buffer); console.log([].slice.call(new Uint32Array(fs.readFileSync("list")))); We anticipate the out ...

What methods can be used to test scss subclasses within an Angular environment?

Exploring different background colors in various environments is a task I want to undertake. The environments include bmw, audi, and vw, with each environment having its own unique background color. Need help writing an Angular test for this? How can I mod ...

Setting a default value in react-select

Recently, I developed a react-select component that is compatible with redux-form. The SelectInput component looks like this: const MySelect = props => ( <Select {...props} value={props.input.value} onChange={value => props.input.on ...

Library of User Interface components for React Native applications

As I embark on my journey of building my first major app using React Native, a question comes to mind. Is there a UI framework available for React Native that offers pre-styled components right out of the box? Similar to how Ionic provides a base theme a ...

There seems to be a problem with the text-to-speech API: It looks like there's a ReferenceError stating that

Currently, I am developing a program using the Quasar framework which is based on Vue and can be compiled for mobile using Cordova. However, I am encountering some issues when trying to run it on mobile. Below is the function causing problems: activat ...

Turn off the option to select a specific time from the dropdown menu on the datepicker. Additionally, if a particular

I have successfully implemented most of the code I need, but I require assistance with one final aspect. jQuery("#date_num").datepicker({ beforeShowDay: function(d) { var day = d.getDay(); var array = ['28/09/ ...