The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> 2 CSS questions, simple?
CharlesEF
post Oct 11 2020, 08:29 PM
Post #1


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Hi All,

For years I've had to style < input > and < select > elements width differently. I had always 'assumed' the problem was with the custom fieldset and legend CSS supplied to me by Mozilla, because of a fieldset printing bug. I find that bug appears to be fixed now so I want to do away with the custom Mozilla CSS. So, I created a test page without the custom CSS but the problem still exists. Attached is the test page and image. When width is set to 100% the right end of the 2 elements don't match. Or, should they? The 2nd question is: why did I need a CSS rule to adjust the position of the help image? I needed it because the help image was placed outside the button.

Hope someone can help explain this to me.

Attached File  CSS_Test.html ( 5.58k ) Number of downloads: 225
Attached Image


Thanks for any and all help,

Charles
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
pandy
post Oct 12 2020, 01:32 PM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



Yeah, this is super strange. I never got to the bottom of it. The cause is browser styling though, borders and padding. That's not so strange, but it gets worse. Look at this.

CODE

div            { width: 500px; background: red; padding: 50px }
input, select  { width: 100% }

#same input, #same select
               { padding: 0;
                 border: none }

#nicetry input, #nicetry select
               { border: 3px solid black;
                 padding: 5px }

#nice input, #nice select
               { border: 3px solid black;
                 padding: 5px;
                 box-sizing: content-box  }


HTML
<div>
<input type="text" value="AAAAAAA">

<br><br>

<select>
<option value="0">&nbsp;</option>
<option value="orange">Orange</option>
<option value="blue">Blue</option>
</select>

<br><br>

<input type="text" value="BBBBBBBB">
</div>


<div id="same">
<input type="text" value="AAAAAAA">

<br><br>

<select>
<option value="0">&nbsp;</option>
<option value="orange">Orange</option>
<option value="blue">Blue</option>
</select>

<br><br>

<input type="text" value="BBBBBBBB">
</div>


<div id="nicetry">
<input type="text" value="AAAAAAA">

<br><br>

<select>
<option value="0">&nbsp;</option>
<option value="orange">Orange</option>
<option value="blue">Blue</option>
</select>

<br><br>

<input type="text" value="BBBBBBBB">
</div>


<div id="nice">
<input type="text" value="AAAAAAA">

<br><br>

<select>
<option value="0">&nbsp;</option>
<option value="orange">Orange</option>
<option value="blue">Blue</option>
</select>

<br><br>

<input type="text" value="BBBBBBBB">
</div>



First set, no styling and the SELECT is shorter than the text inputs.

Second set, borders and padding removed. Wham! All fields have the same width.

Third set, we add the same border and padding to all fields - and the discrepancy is back. Why is that? unsure.gif

Fourth set. Same as third set with the addition of 'box-sizing: content-box' and all is well.


I can't understand why it doesn't work with just the same borders and padding, why box-sizing is needed. Maybe it has something to do with the styling of OPTION. I just lost it at that point.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Oct 12 2020, 02:57 PM
Post #3


.
********

Group: WDG Moderators
Posts: 9,661
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Oct 12 2020, 08:32 PM) *

I can't understand why it doesn't work with just the same borders and padding, why box-sizing is needed.

It seems text INPUT and SELECT use different default values for "box-sizing":

CODE
<script type="text/javascript">
function x()
{
    var i=document.getElementById('i');
    var s=document.getElementById('s');
    alert('Input: '+window.getComputedStyle(i, null).getPropertyValue("box-sizing")+'\nSelect: '+window.getComputedStyle(s, null).getPropertyValue("box-sizing"));

}
</script>

<input type="button" value="Display 'border-box' browser default values" onclick="x();">

<br><br>

<input type="text" value="AAAAAAA" id="i">

<br><br>

<select id="s">
<option value="0">&nbsp;</option>
<option value="orange">Orange</option>
<option value="blue">Blue</option>
</select>
User is online!PM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Oct 12 2020, 03:07 PM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,733
Joined: 9-August 06
Member No.: 6



In what browser? I get the same value (border-box) for both in gecko, gonna goanna and Edge when I run your script.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 04:07 PM