- Change background color of the selected line in a textarea
- 1 Answer 1
- CSS Styling text areas like notebook-look
- 6 Answers 6
- textarea линиями?
- 15+ CSS Textarea Styles
- CSS Textarea Styles
- How to Style HTML with CSS (Quick Hacks)
- How to Style Textarea Placeholder
- How to Style Text in Textarea
- How to Add Default Text in Textarea
- Remove Resize Handler in Textarea
- How to Resize Textarea Vertically
- How to Resize Textarea Horizontally
- How to Remove The Glow Around Textarea
- Textarea Nowrap
- How to Make Textarea Responsive
- How to Style Scrollbar in Textarea
- How to Remove Default Scrollbars in Internet Explorer
- All HTML Textarea Attributes
- Conclusion
Change background color of the selected line in a textarea
I have textarea control in MVC project. Also I have two buttons «UP» and «DOWN». Imagine that in textarea exist 3 lines of text. I want after load page backlight in background first line of textarea. When I press «DOWN» button, the first line will be usual background and second is with background that was first line before. So my question is: Can I with jQuery script backlight one line in text area? If yes, How can I do it? From HTML I have only this:
Question is a little broad. Could you post what you’ve tried? Can you post your HTML/DOM structure? What is meant by «backlight»?
1 Answer 1
Keeping in mind that the question seems to be a prime candidate for XY, here is a solution to this specific scenario, although it’s not particularly elegant.
For HTML, you can not render (the vast majority of) markup within a textarea, so to manipulate the CSS it’s easiest to use and create items within the div with classes/ids to access the DOM elements by.
Simple CSS to apply your background color. It’s a bit silly but you can use either .focused class or :focus functionality, I prefer the built in :focus because the .focused class is a little contrived.
The Javascript was taken largely from another Stackoverflow thread, adding our customization (up/down keys, codes 38/40 respectively) and e.preventDefault() and e.stopImmediatePropagation(); . Which is a bit finicky and requires more knowledge on what else you want the keydown event to trigger.
$(document).keydown(function(e) < if (e.keyCode == 38) < e.preventDefault(); e.stopImmediatePropagation(); if($('.focused').prev('.focusColor').length)< $('.focused').removeClass('focused').prev('.focusColor').focus().addClass('focused'); >> if (e.keyCode == 40) < e.preventDefault(); e.stopImmediatePropagation(); if($('.focused').next('.focusColor').length)< $('.focused').removeClass('focused').next('.focusColor').focus().addClass('focused'); >> >);
CSS Styling text areas like notebook-look
It is possible to style a text area so each row have a dotted underline (like a notebook or a notes-block)? The number of lines should be fixed to lets say 10.
6 Answers 6
Here’s probably what you looking for:
Or you can read this articles that tells you how to do it from scratch:
You can dynamically create an SVG background image based on the line height: stackoverflow.com/questions/18572303/…
That’s why you shouldn’t use your personal website to upload examples. I think JSFiddle is way more reliable.
It takes 5 seconds to do a fiddle on your own. This is one, with the exact code: jsfiddle.net/Wolfsblvt/qc9rgm7r
Great solution, thanks! If You want the lines to scroll along with the textarea’s contents, add background-attachment: local .
I took the other answer and upgraded it to SCSS to make it configurable. You can now easily change size and color of the holes and rules and everything will size accordingly.
Also, I added another example that uses an editable div instead of a textarea.
// rule config $rule-height: 20px; //
Unfortunately, Stackoverflow doesn't support SCSS, so I just included a snapshot of one fixed configuration here:
@import url("https://fonts.googleapis.com/css?family=Reenie+Beanie"); html < height: 100%; >body < background-color: #f5f5f5; >.editable < color: #000000; border: 1px solid #EEEEEE; box-shadow: 1px 1px 0 #DDDDDD; display: inline-block; vertical-align: top; /*font-family: 'Marck Script', cursive;*/ font-family: 'Reenie Beanie', cursive; font-size: 24px; line-height: 20px; margin: 2% auto; padding: 22px 20px 3px 40px; resize: none; min-height: 200px; width: 300px; background-color: #FFFFFF; background-image: -moz-linear-gradient(top, transparent, transparent 19px, #E7EFF8 0px), -moz-radial-gradient(4% 50%, circle closest-corner, #f5f5f5, #f5f5f5 39%, transparent 0%), -moz-radial-gradient(3.9% 46%, circle closest-corner, #CCCCCC, #CCCCCC 43.5%, transparent 0%); background-image: -webkit-linear-gradient(top, transparent, transparent 19px, #E7EFF8 0), -webkit-radial-gradient(4% 50%, circle closest-corner, #f5f5f5, #f5f5f5 39%, transparent 0%), -webkit-radial-gradient(3.9% 46%, circle closest-corner, #CCCCCC, #CCCCCC 43.5%, transparent 0%); -webkit-background-size: 100% 20px; background-size: 100% 20px; >
Editable div: This is the first line.
See, how the text fits here, also if there is a linebreak at the end?
It works nicely.
Great.
textarea линиями?
Всем доброго времен суток. Нужно чтобы textarea были линии вниз параллельно тем что слева, ну и чтобы в них когда пишешь текст по линии шел начиная с того где placeholder написан(он потом будет вверх поднматся), не пойму что делаю не так? Вот как нужно
.form-project__content < display: flex; justify-content: center; margin: 0px 0px 35px 0px; background: #161616; height: 150px; >.form-project__left < flex: 0 1 366px; margin: 0px 15px 0px 0px; height: 110px; >.form-project__inputs < position: relative; z-index: 1; display: inline-block; width: 100%; overflow: hidden; padding-top: 9px; >.form-project__inputs-textarea < position: relative; z-index: 1; display: inline-block; width: 100%; overflow: hidden; >.form-project__input < position: relative; display: block; padding: 0.8em; width: 100%; border: none; border-radius: 0; background: transparent; color: #ccba96; font-weight: 400; padding: 0em 0em 0.5em 0em; width: 100%; background: transparent; color: #ccba96; font-size: 16px; resize: none; >.form-project__input-textarea < background-attachment: local; width: 100%; color: #ccba96; font-size: 16px; background-image: repeating-linear-gradient(#161616, #161616 33px, #ccba96 33px, #ccba96 33px, white 34px); line-height: 35px; border: none; resize: none; padding: 40px 0px 0px 0px; >.form-project__label < position: absolute; top: -20px; font-size: 16px; left: 0; display: block; width: 100%; text-align: left; color: #ccba96; padding: 0px 0px 0px 0px; pointer-events: none; transform-origin: 0 0; transition: transform 0.2s 0.15s, color 1s; transition-timing-function: ease-out; font-weight: 400; >.form-project__label span < position: relative; display: block; padding: 25px 0px 15px 0px; width: 100%; >.form-project__graphic < position: absolute; top: 0; left: 0; width: 300%; height: 100%; fill: none; stroke: #ccba96; pointer-events: none; transition: transform 0.7s, stroke 0.7s; transition-timing-function: cubic-bezier(0, 0.25, 0.5, 1); >.form-project__right < flex: 0 1 366px; margin: 0px 0px 0px 15px; height: 110px; .form-project__input._form-focus+.form-project__label < top: -2px; >.form-project__input._form-focus+.form-project__label, ._form-focus .form-project__label < color: #ccba96; transform: translate3d(0, -1.25em, 0) scale3d(0.75, 0.75, 1); >.form-project__input._form-focus~.form-project__graphic, ._form-focus .form-project__graphic
15+ CSS Textarea Styles
Hello there! In this article, you will find 15+ Textarea Styles Using Html And CSS with complete sources.
CSS Textarea Styles
We have the best handpicked CSS Textarea Styles. Custom-made free Textarea Styles using Html And CSS code and demo for you. So you can just simply copy and paste them into your project and implement it easily.
First, let’s quickly see what a text area is, The HTML element represents a multi-line plain-text editing control, useful when you want to allow users to enter a sizeable amount of free-form text, for example, a comment on a review or feedback form. Textarea can be used in many different circumstances as well.
Here are Textarea Styles Using Html And CSS with code examples from codepen.
Let’s see some cool CSS Textarea styles.
Do you want to learn HTML to JavaScript? 🔥
If yes, then here is our Master Frontend: Zero to Hero eBook! 📚 In this eBook, you’ll learn complete HTML, CSS, Bootstrap, and JavaScript from beginner to advance level. 💪 It includes 450 Projects with source code.
How to Style HTML with CSS (Quick Hacks)
Styling a is not the same as styling an HTML because both have different types of usages. We use when we need to write multiple lines of text.
That's why sometimes it seems difficult to style a and also does not match with other boxes. Textarea also has some extra things to handle and customize like, scrollbar, font, and placeholder, we can resize the textarea, etc.
In this article, you will learn how you can style HTML very easily. You will get detailed information about this topic.
How to Style Textarea Placeholder
You can use many attributes with this tag. For example, title, cols, rows, wrap, etc. You will find a list of attributes that accepts at the end of this article.
In order to, add a placeholder like any other tag you have to use placeholder attribute in .
To add style to the placeholder in you can use the following code. We select ::placeholder in the CSS file to add any style to the placeholder.
/* Modern Browsers */ textarea::placeholder < font-size: 1rem; color: #9c9c9c; font-family: 'Roboto', sans-serif; >/* WebKit, Edge */ textarea::-webkit-input-placeholder < font-size: 1rem; color: #9c9c9c; font-family: 'Roboto', sans-serif; >/* Firefox 4-18 */ textarea:-moz-placeholder < font-size: 1rem; color: #9c9c9c; font-family: 'Roboto', sans-serif; >/* Firefox 19+ */ textarea::-moz-placeholder < font-size: 1rem; color: #9c9c9c; font-family: 'Roboto', sans-serif; >/* IE 10-11 */ textarea:-ms-input-placeholder < font-size: 1rem; color: #9c9c9c; font-family: 'Roboto', sans-serif; >/* Edge */ textarea::-ms-input-placeholder
Most of the modern browsers support just ::placehoder but to support other browsers we can use other versions like, -ms- , -moz- , -webkit- etc.
In the demo, I have used font-size , color, and font-family but you can use any CSS style you want. From now on you can customize your textarea placeholder according to your need.
How to Style Text in Textarea
You can style text inside textarea similarly as you can do with any other HTML inputs. You can also use any CSS property like font-size , font-family , color , etc.
To add the fonts to your website Google Fonts would be a great choice because they provide a lot of options and this is absolutely free. When someone writes text inside then the text will use that font.
How to Add Default Text in Textarea
You can add default text in your input. This text will be shown automatically inside textarea input box. Users can change that or completely replace it with their own text.
This is especially helpful if users have to write a similar type of text all the time. In this case, you can set a default text and users will edit the default text. It will save them time.
To add default text in textarea input you just have to place your text in between the opening tag . It is done.
Remove Resize Handler in Textarea
By default, browsers add resize handler in to the bottom right corner. You can click and drag to increase or decrease the size of the textarea input.
If you don't need this feature, you can disable this with just one line of CSS.
How to Resize Textarea Vertically
If you don't want to remove the resize handler completely then you have other options as well. You can allow your users to resize the vertically.
If you add the following CSS property then users will be able to resize your textarea only vertically.
How to Resize Textarea Horizontally
On the other hand, if you don't want to change the size of your vertically but horizontally, you can do that too.
Following CSS property will make your textarea horizontally resizable.
How to Remove The Glow Around Textarea
In most browsers, when you focus or write inside the a glow or border appears. Some people like it but some don't.
If this glow border does not fit with your design and you want to remove it, you can do that.
You can also apply this style using :focus pseudo-class as well both work the same.
Textarea Nowrap
Normally we use white-space: nowrap; to prevent text from wrapping. In this way, you can write in an input box as long as you want without any line breaks. The browser will show a horizontal scrollbar.
You can customize this default scrollbar if you want. I will show you how you can style textarea scrollbar in the next sections.
When you press Enter , you move to the next line. But this CSS property does not work with . To get a similar result, you have to use the wrap="off" attribute in your input.
How to Make Textarea Responsive
You can make the responsive in many ways. As you have seen, you can control resize handler in textarea.
You can also apply width , height , min-width , max-width , min-height and max-height properties to make it responsive.
In the above code, we have set width: 100%; so by default textarea will take the full area. But max-width: 900px; means textarea will not be bigger than 900px.
If screen size increases, textarea size will increase up to 900px not more than that. It is also helpful if you set resize: horizontal; .
Users can resize textarea input but when you set max-width: 900px; users will be able to increase the textarea up to 900px. You can also set min-width if you want. Then users will not be able to decrease the size more than that.
It also works a similar way when you use the height property. Here default height of the will be 300px.
But when you set resize: vertical; then users will be able to increase its height up to 500px and decrease its height up to 200px.
How to Style Scrollbar in Textarea
When we add height to the and users write multiple lines of text then the browser shows a default scrollbar. Scrollbar may come horizontally and vertically.
If you don't like the default look of those, you can style them according to your need. You can change their color, width, background, etc. And you don't have to do this separately. You can customize both of them at the same time.
textarea::-webkit-scrollbar < width: 15px; background-color: #f5f5f5; box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1); -moz-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1); -webkit-box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.1); >textarea::-webkit-scrollbar-thumb
This will add a custom scrollbar to your input on both sides. Here, textarea::-webkit-scrollbar will style the background of the scrollbar and textarea::-webkit-scrollbar-thumb will style the scrollbar thumb, the part that moves.
But the above code will not work on the Firefox browser. Don't worry you have another option.
You should add this code along with the above code then users will be able to see a custom scrollbar in both Chrome and Firefox browsers.
Firefox does not provide much customization options as Chrome does. You can not set a custom width for the scrollbar. The property scrollbar-width accepts only 3 values auto , thin , and none .
Here, auto is the default value and none will remove your scrollbar in the Firefox browser. This is also an experimental technology. So I would suggest you not use this part on your main website.
If you want to know more about scrollbars, you can follow our ultimate guide on scrollbar customization.
But you can use 1 st part textarea::-webkit-scrollbar and textarea::-webkit-scrollbar-thumb , this will work just fine.
How to Remove Default Scrollbars in Internet Explorer
Internet Explorer adds a vertical scrollbar by default in the textarea even if there is no text in it. It does not look good.
You can hide the default scrollbar using overflow: hidden; property. But the problem is you don't get any scrollbar at all when a user writes multiple lines of text. So, it is not an ideal solution.
Therefore, we should use overflow: auto; this to remove the default scrollbar and it appears when needed.
All HTML Textarea Attributes
Here is the list of attributes that you can use in the HTML tag.
Conclusion
In this article, we have seen multiple ways how you can style your HTML textarea. I hope from now on you will be able to customize your textarea input according to your need.