Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly style a text area with inner shadows and scrollbar

I'm putting an inner-shadow on all my controls, inputs and textareas by using the following CSS:

input {
  padding: 7px;
  -webkit-box-shadow: inset 2px 2px 2px 0px #dddddd;
  -moz-box-shadow: inset 2px 2px 2px 0px #dddddd;
  box-shadow: inset 2px 2px 2px 0px #dddddd;
}

and, with some other styling, looks like this (in Firefox, and similar in other browsers):

enter image description here

But the padding that helps separate the content from the inner shadow breaks the textarea around the scrollbar:

enter image description here

and if I remove the padding, the text overlaps the shadow, like this:

enter image description here

I can add padding only to the left, solving the overlap with the left shadow but not with the top shadow, while having the scrollbar look good:

enter image description here

I can also add padding everywhere but on the right side, having the text displayed correctly but the toolbar still looks rather odd:

enter image description here

Is there any way to solve this?

like image 338
pupeno Avatar asked Jan 17 '12 13:01

pupeno


People also ask

Which style property would you use to create the shadow behind the text?

The text-shadow CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its decorations .


1 Answers

Getting the padding property to affect only the content but not the scrollbar is not possible using standard textarea elements. For that you can use a contenteditable DIV. For example, check this fiddle: http://jsfiddle.net/AQjN7/

HTML:

<div class="outer" contenteditable="true">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>

CSS:

.outer {
    -webkit-box-shadow: inset 2px 2px 2px 0px #dddddd;
    -moz-box-shadow: inset 2px 2px 2px 0px #dddddd;
    box-shadow: inset 2px 2px 2px 0px #dddddd;
    height: 200px;
    margin: 10px;
    overflow: auto;
    padding: 7px 10px;
    width: 300px;    
    font-family: tahoma;
    font-size: 13px;
    border: 1px solid #aaa;
}
​
like image 105
techfoobar Avatar answered Oct 26 '22 22:10

techfoobar