473,785 Members | 2,829 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get text input box to fill remaining space?

Hi, I have some simple HTML like this:

<div id="container" style="width:10 0%;">
<input type="text" <input type="button" style="float:ri ght;"
value="Click here...">
</div>

I want the button to remain the normal size and be right-aligned, and
the edit box to automatically take up the remaining width of the
container.

I suspect I'm missing something obvious, but how can I do this with
CSS?

Thanks in advance.
Jun 29 '08 #1
11 12429
Scripsit Mike Harrison:
Hi, I have some simple HTML like this:
Please post a URL, not a snippet of code.
<div id="container" style="width:10 0%;">
<input type="text" <input type="button" style="float:ri ght;"
value="Click here...">
</div>
"Click here..." is clueless. Just an example, maybe, but it's a _bad_
example, and people actually use such button texts, which are
(literally) clueless, i.e. give no clue of the meaning and effect of the
button.

A text input field without a label is clueless, too.

It is not obvious at all how the text field and the button relate to
each other. If they do, why not use <fieldsetwith a descriptive
<legend>? Then you have a _different_ styling problem, and perhaps one
that is worth addressing.

Besides, such a button is normally quite pointless, since <input
type="button"on ly works (if it works at all) via scripting, and there
isn't any scripting in your snippet.

So how about starting a from a good and real example, presented by
providing the URL?
I want the button to remain the normal size and be right-aligned, and
the edit box to automatically take up the remaining width of the
container.
Really? Even if the canvas is ten meters wide?

What happens when CSS is off? The width will be then set by browser
defaults, which are rather small (typically, about 20 characters). So
maybe you should first choose a suitable size="..." value; it's
inconvenient guesswork, but it's better to make an intelligent guess
that to let browsers default.
I suspect I'm missing something obvious,
We obviously miss the URL.
but how can I do this with CSS?
We miss the definition of what "this" consists of.

To begin with, when the button element appears after the text input
element, it will appear below it, though right-aligned. If you want them
to appear on the same line visually, you need to put the button element
before the text input element.

You haven't actually made _any_ attempt to set the text input field
width, in HTML or in CSS, in your snipped. The 100% width is set for the
container element, for which it has no effect, since the default
rendering is to make a <divelement as wide as possible.

There does not seem to be any direct CSS way of achieving what you want
(except using table-related properties that are not supported by IE),
but it's trivial in HTML, with one simple piece of CSS:

<table width="100%">
<tr><td width="100%"><i nput type="text" style="width:10 0%"></td>
<td><input type="button" value="Click here..."></td></tr>
</table>

However, what would be the point? If the field needs as much space as
possible, why waste space by putting a button on its right? And why not
make it a textarea if it may need a lot of space?

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jun 29 '08 #2
Jukka K. Korpela wrote:
Scripsit Mike Harrison:
>Hi, I have some simple HTML like this:

Please post a URL, not a snippet of code.
One doesn't need a URL of a fully formed page to ask how to do
something. His illustrative snippet is short and clear. I'm awarding you
one cluelessness point of your own.
><div id="container" style="width:10 0%;">
<input type="text" <input type="button" style="float:ri ght;"
value="Click here...">
</div>

"Click here..." is clueless. Just an example, maybe, but it's a _bad_
example, and people actually use such button texts, which are
(literally) clueless, i.e. give no clue of the meaning and effect of the
button.
Another cluelessness point for Jukka, who doesn't understand it's
perfectly OK for an example to be generic and stripped-down, and that
all that's required of it is that it be sufficiently illustrative for
the question being asked.
A text input field without a label is clueless, too.
A third cluelessness point for Jukka, to whom it doesn't occur that the
OP almost certainly intends to have a label in the real page but just
didn't bother included it in the example, where it wasn't necessary for
the purposes of his question.
It is not obvious at all how the text field and the button relate to
each other. If they do, why not use <fieldsetwith a descriptive
<legend>? Then you have a _different_ styling problem, and perhaps one
that is worth addressing.
It's an example. The clarity of their working relationship in the final
product is extraneous here and in fact might even detract from the
example's ability to illustrate the OP's question. A fourth cluelessness
point for Jukka.
Besides, such a button is normally quite pointless, since <input
type="button"on ly works (if it works at all) via scripting, and there
isn't any scripting in your snippet.
Cluelessness point number five. Jukka still hasn't figured out that the
example isn't intended to be the whole page.
So how about starting a from a good and real example, presented by
providing the URL?
Probably because there isn't anything else on the page that would have
anything to do with getting an answer to the OP's technical question.
>I want the button to remain the normal size and be right-aligned, and
the edit box to automatically take up the remaining width of the
container.

Really? Even if the canvas is ten meters wide?
If 1em = 20cm on that particular canvas, why not? Cluelessness point
number six.
What happens when CSS is off? The width will be then set by browser
defaults, which are rather small (typically, about 20 characters). So
maybe you should first choose a suitable size="..." value; it's
inconvenient guesswork, but it's better to make an intelligent guess
that to let browsers default.
Wow, one helpfulness point.
>
>I suspect I'm missing something obvious,

We obviously miss the URL.
>but how can I do this with CSS?

We miss the definition of what "this" consists of.
Attention deficit disorder acting up? Even if you lose track of
pronominal antecedents that easily, you can always go back and reread.
To begin with, when the button element appears after the text input
element, it will appear below it, though right-aligned. If you want them
to appear on the same line visually, you need to put the button element
before the text input element.

You haven't actually made _any_ attempt to set the text input field
width, in HTML or in CSS, in your snipped. The 100% width is set for the
container element, for which it has no effect, since the default
rendering is to make a <divelement as wide as possible.

There does not seem to be any direct CSS way of achieving what you want
(except using table-related properties that are not supported by IE),
but it's trivial in HTML, with one simple piece of CSS:
Two more helpfulness points, bringing the total to three.
<table width="100%">
<tr><td width="100%"><i nput type="text" style="width:10 0%"></td>
<td><input type="button" value="Click here..."></td></tr>
</table>
How dare you provide an example without building it into a fully
functional, cluelessness-free page with a URL! What a hypocrite. For
this I'm awarding two more cluelessness points.
>
However, what would be the point? If the field needs as much space as
possible, why waste space by putting a button on its right? And why not
make it a textarea if it may need a lot of space?
One more helpfulness point. Final tally: 8 cluelessness points, 4
helpfulness points. Final cluelessness/helpfulness (CH) quotient for the
posting: 200%.
Jun 29 '08 #3
On 2008-06-29, Jukka K. Korpela <jk******@cs.tu t.fiwrote:
Scripsit Mike Harrison:
[...]
><div id="container" style="width:10 0%;">
<input type="text" <input type="button" style="float:ri ght;"
value="Click here...">
</div>

"Click here..." is clueless. Just an example, maybe, but it's a _bad_
example, and people actually use such button texts, which are
(literally) clueless, i.e. give no clue of the meaning and effect of the
button.
I read somewhere about a survey of which button/link texts people were
most likely to click on. "Click here!" resulted in the most clicks
because users have an attention span of four seconds, wish to remain
clueless, and tend to just obey direct commands.

Things like "more information", "read more", etc. were clicked on the
least because they made the whole thing seem too much like hard work.

[...]
To begin with, when the button element appears after the text input
element, it will appear below it, though right-aligned. If you want them
to appear on the same line visually, you need to put the button element
before the text input element.
Yes, although this is actually a bug shared by Firefox 2 and IE. It
shouldn't be necessary to put the float first.
You haven't actually made _any_ attempt to set the text input field
width, in HTML or in CSS, in your snipped. The 100% width is set for the
container element, for which it has no effect, since the default
rendering is to make a <divelement as wide as possible.

There does not seem to be any direct CSS way of achieving what you want
(except using table-related properties that are not supported by IE),
but it's trivial in HTML, with one simple piece of CSS:
There is a way, by putting the text input in a different block
formatting context.

..foo
{
display: block;
overflow: hidden; /* to make it a BFC */
}
input[type="text"] { width: 100%; }
input[type="button"] { float: right; }

....

<input type="button" value="Click here">
<span class="foo">
<input type="text">
</span>

Caveat: the spec says browsers can just put .foo below the button,
rather than beside it, if they want.
Jun 29 '08 #4
Scripsit Harlan Messinger:
Final cluelessness/helpfulness (CH) quotient for
the posting: 200%.
No, your posting was completely unhelpful and stupid. You don't have
anything useful to say, do you, but you apparently need to keep your
fingers warm. How about using just Notepad for the exercise next time?

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jun 29 '08 #5
Jukka K. Korpela wrote:
Scripsit Harlan Messinger:
>Final cluelessness/helpfulness (CH) quotient for
the posting: 200%.

No, your posting was completely unhelpful and stupid. You don't have
anything useful to say, do you, but you apparently need to keep your
fingers warm. How about using just Notepad for the exercise next time?
I helped the OP plenty, by reassuring him that your pissy carping wasn't
the gospel around here and that he needn't pay any attention to your
asinine commentary. Meanwhile, you are a master at being unhelpful and
stupid, so why don't you follow your own advice, you unhappy wretch?
Jun 29 '08 #6
Scripsit Ben C:
I read somewhere about a survey of which button/link texts people were
most likely to click on.
I read somewhere about a survey where it was found out that 95.9% of all
surveys produce incorrect results due to unsound methods, but it doesn't
matter really since the results will be either misquoted or
misunderstood, usually both.
"Click here!" resulted in the most clicks
because users have an attention span of four seconds, wish to remain
clueless, and tend to just obey direct commands.
And click on a wrong button.

Wait, there _is_ a CSS-related issue here: CSS, in addition to certain
features of HTML markup, is a way to make the association of texts,
input fields, and buttons so obvious that people see, without thinking,
what a button relates to. This is far more important than e.g.
utilizing all the available space for an input box.
.foo
{
display: block;
overflow: hidden; /* to make it a BFC */
}
input[type="text"] { width: 100%; }
input[type="button"] { float: right; }

...

<input type="button" value="Click here">
<span class="foo">
<input type="text">
</span>
I'm not sure whether I'm convinced that this _should_ work, but
a) it's more tricky than a simple table (with a simple CSS rule)
b) on IE 7, it causes the right border of the input box hit the button;
this looks odd and puzzling
c) of course, it doesn't work IE 6 unless you change the selectors to
class (or id) selectors

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Jun 29 '08 #7
On 2008-06-29, Jukka K. Korpela <jk******@cs.tu t.fiwrote:
[...]
>.foo
{
display: block;
overflow: hidden; /* to make it a BFC */
}
input[type="text"] { width: 100%; }
input[type="button"] { float: right; }

...

<input type="button" value="Click here">
<span class="foo">
<input type="text">
</span>

I'm not sure whether I'm convinced that this _should_ work, but
These are the relevant bits of the spec if you are interested. As I
mentioned, the browser only "may" do this:

CSS 2.1 9.4.1:

In a block formatting context, each box's left outer edge touches the
left edge of the containing block (for right-to-left formatting, right
edges touch). This is true even in the presence of floats (although a
box's line boxes may shrink due to the floats), unless the box
establishes a new block formatting context (in which case the box
itself _may_ become narrower due to the floats).

CSS 2.1 9.5:

The margin box of a table, a block-level replaced element, or an
element in the normal flow that establishes a new block formatting
context [p. 126] (such as an element with 'overflow' other than
'visible') must not overlap any floats in the same block formatting
context as the element itself. If necessary, implementations should
clear the said element by placing it below any preceding floats, but
may place it adjacent to such floats if there is sufficient space.
a) it's more tricky than a simple table (with a simple CSS rule)
b) on IE 7, it causes the right border of the input box hit the button;
this looks odd and puzzling
I suppose a small margin on the input box might solve that problem.
Jun 29 '08 #8
In article <6c************ *@mid.individua l.net>,
Harlan Messinger <hm************ *******@comcast .netwrote:
Jukka K. Korpela wrote:
Scripsit Mike Harrison:
Hi, I have some simple HTML like this:
Please post a URL, not a snippet of code.

One doesn't need a URL of a fully formed page to ask how to do
something. His illustrative snippet is short and clear. I'm awarding you
one cluelessness point of your own.
[...]
Final tally: 8 cluelessness points, 4
helpfulness points. Final cluelessness/helpfulness (CH) quotient for the
posting: 200%.
I was slightly puzzled why you did not award a cluelessness point for
the fault you theorised was due to attention deficit disorder. You are
too soft hearted Harlan. <g>

--
dorayme
Jun 29 '08 #9
dorayme wrote:
In article <6c************ *@mid.individua l.net>,
Harlan Messinger <hm************ *******@comcast .netwrote:
>Jukka K. Korpela wrote:
>>Scripsit Mike Harrison:

Hi, I have some simple HTML like this:
Please post a URL, not a snippet of code.
One doesn't need a URL of a fully formed page to ask how to do
something. His illustrative snippet is short and clear. I'm awarding you
one cluelessness point of your own.

[...]
>Final tally: 8 cluelessness points, 4
helpfulness points. Final cluelessness/helpfulness (CH) quotient for the
posting: 200%.

I was slightly puzzled why you did not award a cluelessness point for
the fault you theorised was due to attention deficit disorder. You are
too soft hearted Harlan. <g>
Yes, sometimes pity gets the best of me.
Jun 30 '08 #10

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

Similar topics

1
3832
by: Scott Navarre | last post by:
Hello, I have noticed that when using JavaScript to create a page, the sizes of the text input form elements come out bigger than the size I am trying to set them to. I don't know if it matters, but I am using IE6... For example: if I create a text input with a size of "1" using straight HTML, and then type into it, I can see 2 characters at a time. But when I use JavaScript's 'document.write()' function to create the same text...
2
4992
by: Kai Grossjohann | last post by:
I would like to put a text input field (in the sense of <input type="text">) and an image next to each other, where I know the size in pixels of the image, and I know the total width in em. I haven't found a way to do this. I tried <span style="width:20em"> <input type="text"> <img width="25px" src="...">
8
23493
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
18
25006
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin, that IE7 does not seem to offer any way to control the font size of a text input element.
9
5884
by: Marky1124 | last post by:
Hi, I am hoping that someone can offer me some advise. I am new to CSS layouts and I've struggled to produce the screen layout that I wanted. Here's my demonstration page:- http://www.holleydesigns.com/pudo/demo3m.html My design goals were:
0
2941
by: Mike Minor | last post by:
I recently downloaded Google tool bar into my IE 6.0. Sometime later, I went back to a webpage that I've been working on and started noticing that the background color on some but not all text input fields were yellow. I've been pulling out my hair over why some were yellow and some were white, checking css settings, looking for errant code, etc.... I finally decided to start poking around outside of the html code I'm working on and...
4
2240
by: Andrew Poulos | last post by:
I have a form that looks something like the following: <form"> <div id="pg0"> <!-- more HTML here --> <input type="text" name="f0_0" > </div> <div id="pg1" style="display:none;"> <!-- more HTML here -->
0
1831
by: pazazuzu | last post by:
Hi everyone, I currently have an assignment which I am almost done with but am having problems trying to figure out how to integrate a string function search. I have a text box called $targetstring. My program allows users to input items such as groceries into one text box (item_value) and add an amount to the groceries purchased (amount_value). The program will add the amounts and give a total and will validate the amount_value box for...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10327
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.