6

Given the following CSS

.comment {
    margin: 10px;
    display: block;
    overflow: auto;
    border-top-left-radius: 5px 5px;
    border-top-right-radius: 5px 5px;
    border-bottom-right-radius: 5px 5px;
    border-bottom-left-radius: 5px 5px;
    -webkit-box-shadow: rgba(0, 0, 0, .2) 1px 1px 3px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    min-height: 200px;
    width: 100% 
}

This is applied to a textarea but the right margin is ignored and the textarea goes off the screen.

why is this?

Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
maxum
  • 2,825
  • 4
  • 33
  • 49

2 Answers2

11

By setting the width to 100% and a margin of 10px the textarea will be a 100% width of it's container shifted down and to the left 10px

To get your desired result you'll probably need to use a container around the textarea with a 10px padding.

See example.

  • commentA is using a container with padding
  • commentB is your original CSS

so something like:

<div class="comment-container">
    <textarea class="commentA"></textarea>
</div>

and

.comment-container {
    padding:10px;
}
.commentA {
    width:100%;
    min-height: 200px;
}

to get started.

s.alem
  • 12,579
  • 9
  • 44
  • 72
MikeM
  • 27,227
  • 4
  • 64
  • 80
  • I had to use 'margin: 10px' rather than padding for it to work. But the put it in a container was the solution. – maxum Jun 11 '11 at 02:54
0

Just use:

display: inline

Instead of:

display: block
André Kool
  • 4,880
  • 12
  • 34
  • 44