473,388 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Width of textarea in Mozilla

Dear CSS Experts,

I want to make a textarea fill all the available width. This is
something I've done before but mostly by trial and error; now I want to
understand what is going on. So I try:

textarea {
margin-left: 0;
margin-right: 0;
width: auto;
}

But it doesn't work, I get something narrow. (All testing with Firefox
1.0. I'll worry about issues with other browsers later.) Of course,
if I do

width: 100%;

it seems to work, but actually because the 100% is the content width
and there are a few pixels of borders present it is overflowing
slightly. You find a lot of sites with width: 95% or similar for this
reason.

But why doesn't the original style work? It seems that mozilla
implements a textarea as approximately display:inline-block where
width:auto means shrink-wrap (CSS2.1). OK, so let's change it:

textarea {
display: block;
margin-left: 0;
margin-right: 0;
width: auto;
}

But this doesn't work either. I was hoping that explicitly giving it
display:block would change the meaning of width:auto, but it doesn't.

So is this a Mozilla bug ("meaning of width:auto does not change when
textarea has display:block")? Am I misunderstanding something? Is
there a better solution? Currently I think that the best method is to
put an extra div around it in the markup:

<div class="textareactr">
<textarea/>
</div>

div.textareactr textarea {
width:100%;
}

(Previous experience also suggests that this is the best way to avoid
some of IE's weirdnesses, but I'm not worrying about them right now.)

Any thoughts?

--Phil.

Jul 21 '05 #1
3 14464
I think if you define width:auto for a textarea, the browser gets the
width from the cols-attribute.
But not sure.

Chris
ph*******@treefic.com wrote:
Dear CSS Experts,

I want to make a textarea fill all the available width. This is
something I've done before but mostly by trial and error; now I want to
understand what is going on. So I try:

textarea {
margin-left: 0;
margin-right: 0;
width: auto;
}

But it doesn't work, I get something narrow. (All testing with Firefox
1.0. I'll worry about issues with other browsers later.) Of course,
if I do

width: 100%;

it seems to work, but actually because the 100% is the content width
and there are a few pixels of borders present it is overflowing
slightly. You find a lot of sites with width: 95% or similar for this
reason.

But why doesn't the original style work? It seems that mozilla
implements a textarea as approximately display:inline-block where
width:auto means shrink-wrap (CSS2.1). OK, so let's change it:

textarea {
display: block;
margin-left: 0;
margin-right: 0;
width: auto;
}

But this doesn't work either. I was hoping that explicitly giving it
display:block would change the meaning of width:auto, but it doesn't.

So is this a Mozilla bug ("meaning of width:auto does not change when
textarea has display:block")? Am I misunderstanding something? Is
there a better solution? Currently I think that the best method is to
put an extra div around it in the markup:

<div class="textareactr">
<textarea/>
</div>

div.textareactr textarea {
width:100%;
}

(Previous experience also suggests that this is the best way to avoid
some of IE's weirdnesses, but I'm not worrying about them right now.)

Any thoughts?

--Phil.

Jul 21 '05 #2
ph*******@treefic.com wrote:
I want to make a textarea fill all the available width.
So I try:

textarea {
margin-left: 0;
margin-right: 0;
width: auto;
}

I get something narrow. if I do
width: 100%;

it seems to work, but actually because the 100% is the content width
and there are a few pixels of borders present it is overflowing
slightly. OK, so let's change it:

textarea {
display: block;
margin-left: 0;
margin-right: 0;
width: auto;
}

But this doesn't work either. I was hoping that explicitly giving it
display:block would change the meaning of width:auto, but it doesn't.

So is this a Mozilla bug Currently I think that the best method is to
put an extra div around it in the markup:

<div class="textareactr">
<textarea/>
</div>

div.textareactr textarea {
width:100%;
}

(Previous experience also suggests that this is the best way to avoid
some of IE's weirdnesses, but I'm not worrying about them right now.)

Any thoughts?

--Phil.

In mozilla, as is compliant, the width is the width of the contents. In
any circumstances as has been pointed out to me recently here the cols
and rows attributes should be stated. This markup demonstrates the
treatment of width in the two browsers you mention.

div style="width:80%;margin:auto;border:1px solid #000000;">

<textarea cols="50" rows="5"></textarea>

<textarea cols="50" rows="5" style="width:100%;"></textarea>

<textarea cols="50" rows="5"
style="width:100%;padding:1em;margin:1em;"></textarea>

</div>

Louise
Jul 21 '05 #3
boclair wrote:
ph*******@treefic.com wrote:
I want to make a textarea fill all the available width. So I try:

textarea {
margin-left: 0;
margin-right: 0;
width: auto;
}

I get something narrow.


if I do width: 100%;

it seems to work, but actually because the 100% is the content width
and there are a few pixels of borders present it is overflowing
slightly.


OK, so let's change it:

textarea {
display: block;
margin-left: 0;
margin-right: 0;
width: auto;
}

But this doesn't work either. I was hoping that explicitly giving it
display:block would change the meaning of width:auto, but it doesn't.

So is this a Mozilla bug


Currently I think that the best method is to
put an extra div around it in the markup:

<div class="textareactr">
<textarea/>
</div>

div.textareactr textarea {
width:100%;
}

(Previous experience also suggests that this is the best way to avoid
some of IE's weirdnesses, but I'm not worrying about them right now.)

Any thoughts?

--Phil.

In mozilla, as is compliant, the width is the width of the contents.


Badly put. For input and textareas elements it is the internal width.
Still badly put.

Louise
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Phil Powell | last post by:
The customer made a wild request: they want on their admin panel a textarea that will display an existing resume. This textarea, however, must have a dynamic width, one that "fills the screen...
3
by: Phil Powell | last post by:
<script type="text/javascript"> <!-- function getWinWidth() { isNav = (document.all) ? false : true; isIE = (document.all) ? true : false; if (isNav && !isIE) return(window.innerWidth); else...
9
by: Paul Gorodyansky | last post by:
Hi, FAQ tells how to insert (or replace0 a text at a caret position in Mozilla (and same works for Opera 8+), for example, at http://www.faqts.com/knowledge_base/view.phtml/aid/1661 it talks...
1
by: Nic | last post by:
Hi - I am battling to find the a resource, so maybe some one in here can help The problem is as follows: I am trying to build a mod_perl source code editor for the web - to edit Perl source code...
1
by: NullBock | last post by:
Hi, I'm trying to create a form with a text-input (not textarea) that expands to the size available, using CSS. I thought that a simple display:block would work: <form> <div> <input...
1
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
8
by: Csaba Gabor | last post by:
Is there any way in Mozilla/Firefox to add an event listener to all textarea elements? Something along the lines of HTMLTextAreaElement.prototype.onkeydown = function() {alert('mom');} only it...
1
by: tranky | last post by:
Hola boys, i've a question for you! It's possible to highlight some text inside a textarea? (not all text, but a portion!) For example, i've this text inside a textarea. INSERISCI TESTO i...
4
by: Keith Bentrup | last post by:
Hi all, I wrote a simple search function to find text in a textarea where not all the text is visible (ie. the text box displays 10 lines but there may be more than 1000 lines to search). I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.