Getting Firefox to stretch an input properly - css

This is a simplified version of something I'm trying to do. Works in every browser other than FF:
http://jsfiddle.net/hDFnW/10/
Basically, I'm trying to get an input to apply width:auto; when position:absolute;left:200px;right:0px is set.
It works on anything other than an input... I'm rather confused right now.
How can I accomplish this in Firefox, or better yet, across all browsers?

You can wrap the input with a div and then it works.
CSS
div {
display : block;
position : absolute;
left : 100px;
right : 0px;
top : 3px;
}
input {
width : 100%;
border : 1px solid #000;
background : #FFF;
}
jsFiddle using other examples.
jsFiddle all working.
Example
You can get a similar effect (albeit not the same however) using floats.

Very simple fix...no wrapping required. IE, Chrome, FF - all good.
http://jsfiddle.net/LGn9A/1/
don't mix the pixels w/ percentages :-) (in this case)
ul {
width : 95%; /* here */
font : 12px/1.4 tahoma; /* global aethetics */
....
}
li { ... }
input, span {
display : block;
position : absolute;
left : 20%; /* here */
right : 0px;
width : 80%; /* and here */
}
FF-- will cooperate using white-space:nowrap; works in IE, and Chrome as well.
<li>Title
<span style="border:0px">
<input style="width:100%;left:0px;white-space:nowrap;">
</span>
</li>
http://jsfiddle.net/hDFnW/16/

I came up with two solutions:
http://jsfiddle.net/w6fGY/ - fixed width for <span> and <input>
http://jsfiddle.net/B4MKu/ - all <input>s wrapped in <span> and width:100%.
I hope it's of use.

A simple solution to this problem is to use position:relative on input and assign its left position and width value using percentage and not px. That's because parent ul width is specified in percentage and not px. Otherwise the solution would be easy if a fixed width was given to the ul element
<ul>
<li>Title<input></li>
<li>Title<input></li>
</ul>
ul {
width : 95%;
border : 1px solid #000;
font-family : tahoma;
padding : 5px;
position:relative;
}
li {
background-color : #EEE;
margin : 2px;
padding : 3px;
}
input {
position:relative;
left:20%;
width:75%; /* I used 75% to give an extra 5% room for paddings and margins specified by parent elements ex: li ul) */
}
Check working example at http://jsfiddle.net/t5CvC/1/

It seems -moz-calc would work, but only in FF4.
As you said you don't want wrapper spans or divs.
There's a slightly hacky way in this jsfiddle
Summary:
Change the box-sizing model to contain borders and padding, then add the 100px as left padding so the input text value moves over but the width stays at 100%; - then clip the input to chop off the extra left bit and show the title text again. Only problem is, there's no left border, I tried to add a fake one with a pseudo element.. needless to say the fake border doesn't work in IE8 and none of it works in IE7
Update
updated code to use a background image which now gives a border effect in IE too ==> jsfiddle

Related

Custom webkit scrollbar position

I have a custom webkit scrollbar like this:
::-webkit-scrollbar{
background: transparent;
width: 10px;
}
::-webkit-scrollbar-thumb{
background: #999 !important;
}
So it renders a grey custom scrollbar instead of the standard one. However, it is stuck to the right side of the page. I know I can change this by adding a margin, padding or border to my body but I am using fullscreen (on backgrounds) images. So when I try this all the images are affected by this too, which I do not want. So I tried to position the scrollbar but this does not work (as it is not an element but a user agent property...
So I'm looking for a way (without using another plugin) to customize the toolbar so that it is offset from the side.
Or, if possible that I can make the scrollbar offset in a div.
Secondly, I'm looking for a way that I can make the "track" of the scrollbar transparet. So only a handle.
Thanks in advance!
If you are still looking for for the answer (or somebody else is, like I was) - here is a definitive article about webkit scrollbars.
Answering Your first question - I'd suggest that you put all your scrollable content in a div with 100% height and 90% width - the 10% left on the right would be your offset. Like that:
.superDiv{
height:100%;
width:90%;
position:fixed;
}
body{ overflow: hidden }
The second question - you're looking for
::-webkit-scrollbar-track-piece {
background:transparent;
}
But as Apple people are pushing for no-scrollbar web browsing, only the properties set by CSS are visible, so you don't have to change the track-piece.
Clever solution I found recently was to put the border on the right hand side of the screen / div that contains scrollbar:
<div class="yourdiv">
border-right: 5px solid #(background_color);
</div>
An easy way to control the position of a custom scrollbar is to set the scrolling element (body?) using definitive positioning. You'll also need to set html to overflow:auto;
To make the thumb transparent, use a RGBa value for declaring the color. In this case I used 0,0,0,0.4 (red,green,blue,alpha). RGBa is not supported in every browser, Chris Coyier has a good table of who supports it here: http://css-tricks.com/rgba-browser-support/
If all you want to show is the thumb than also consider hiding the other elements of the scrollbar: resizer, scrollbar-button, and scrollbar-corner.
html {
overflow: auto;
}
body {
position: absolute;
top: 20px;
left: 20px;
bottom: 5px;
right: 20px;
overflow: scroll;
}
::-webkit-scrollbar{
background: transparent;
width: 10px;
}
::-webkit-scrollbar-thumb{
background: rgba(0,0,0,0.4); /*-- black at 40% opacity --*/
}
::-webkit-resizer,
::-webkit-scrollbar-button,
::-webkit-scrollbar-corner { display: none; }
Check out the working demo at http://jsfiddle.net/Buttonpresser/G53JQ/

CSS: how do I fix my hyperlink alignment issue?

I have two links: shopper and store. Both of these links are in there own separate left and right floats. The Store link is supposed to be in a right float, but it snaps out of its div when adding a border style to the left float. How do I get it back into place? Please have a look at http://jsfiddle.net/JuCKU/ for an example.
I completely forgot to update jfiddle with the new code. http://jsfiddle.net/JuCKU/3/
firefox is having the alignment issue while google chrome seems to render the layout correctly.
Drop the width from 50% to 49%. Since you have a border, it takes up space and by giving each div a width of 50%, the total is a bit too wide and the second div pop down a bit. Or get rid of the border.
jsFiddle Example
Change
#shopper, #store
{
width: 50%;
text-align: center;
}
To:
#shopper, #store
{
width: 49%;
text-align: center;
}
It's a rounding issue. It's not a rounding issue, 50% + 50% + 1px border is more than 100%. Making the width slightly less than 50% is a quick fix.
Change this:
#shopper, #store
{
width: 50%;
text-align: center;
}
for this:
#shopper, #store
{
width: 49.9999%;
text-align: center;
}
http://jsfiddle.net/JuCKU/4/
simple give margin-right:-1px in your shopper div
#shopper
{
float: left;
border-right: 1px solid #ccc;
margin-right:-1px;
}
Check this http://jsfiddle.net/JuCKU/6/
OR
you can use css3 box-sizing property for this but it's work till IE8 & above.
Check this http://jsfiddle.net/JuCKU/7/
Adding the border increases the overall size of the boxes to 50%+1px, so together their combined width is greater than 100% and something's gotta give.
You can use the CSS3 property box-sizing:border-box to incorporate the border into the total 50% width, or more specifically -moz-box-sizing in Firefox, -webkit-box-sizing in Chrome/Safari and simply box-sizing in Opera. Unfortunately IE doesn't yet support this.
So add this to your code.
#shopper, #store {
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
More info - http://www.css3.info/preview/box-sizing/
As mentioned by others the bulletproof solution across all browsers is to reduce the width of your boxes to fractionally less than 50%.
Give the divs some widths
see http://jsfiddle.net/JuCKU/1/

IE7 scrollbars when position:relative item WAS out-of-screen

IE7 seems to show scrollbars when an item that has position: relative on it USED to cause a scroll-bar (e.g. it would if you took position: relative off).
<div class="box">
<div class="inner box"></div>
</div>
.box {
position : absolute;
top : 5px;
left : 100px;
right : 5px;
height : 100px;
border : 1px solid #000;
}
.inner {
right : auto;
position : relative;
width : 110%;
left : -90px;
}
Demo: http://jsfiddle.net/VE9ne/1/
Wondering if anyone has seen this and knows how to fix it?
Use negative margins instead of negative left
...
left:0;
margin-left:-90px;
Add
html, body
{
overflow: hidden;
}
That's what relative positioning does, it leaves an empty space at the object's original position if you offset it. I guess IE7 is not as smart as other browsers so it will show scrollbars whereas others seem to realize there's nothing but empty space to show.
Here's what w3.org has to say about it:
[...] Offsetting a box (B1) in this
way has no effect on the box (B2) that
follows: B2 is given a position as if
B1 were not offset and B2 is not
re-positioned after B1's offset is
applied. [...]
Source: http://www.w3.org/TR/CSS21/visuren.html#relative-positioning
Using margins and floats instead of relative positioning could solve your problem

Can background image extend beyond div's borders?

Can background image extend beyond div's borders? Does overflow: visible apply to this?
No, a background can't go beyond the edge of an element.
The overflow style controls how the element reacts when the content is larger than the specified size of the element.
However, a floating element inside the div can extent outside the div, and that element could have a background. The usefulness of that is limited, though, as IE7 and earlier has a bug that causes the div to grow instead of letting the floating element show outside it.
Following up on kijin's advice, I'd like to share my solution for image offsets:
/**
* Only effective cross-browser method to offset image out of bounds of container AFAIK,
* is to set as background image on div and apply matching margin/padding offsets:
*/
#logo {
margin:-50px auto 0 auto;
padding:50px 0 0 0;
width:200px;
height:200px;
background:url(../images/logo.png) no-repeat;
}
I used this example on a simple div element <div id="logo"></div> to position my logo with a -50px vertical offset. (Note that the combined margin/padding settings ensure you don't run into collapsing margin issues.)
not possible to set a background image 'outside' it's element,
BUT YOU CAN DO what you want with using 'PSEUDO' element and make that whatever size you want and position it wherever you want.
see here :
i have set the arrow outside the span
here is the code
HTML :
<div class="tooltip">
<input class="cf_inputbox required" maxlength="150" size="30" title id="text_13" name="name" type="text"><span class="msg">dasdasda</span>
</div>
strong text
.tooltip{position:relative; float:left;}
.tooltip .msg {font-size:12px;
background-color:#fff9ea;
border:2px #e1ca82 solid;
border-radius:5px;
background-position:left;
position:absolute;
padding:4px 5px 4px 10px;
top:0%; left:104%;
z-index:9000; position:absolute; max-width:250px;clear:both;
min-width:150px;}
.tooltip .msg:before {
background:url(tool_tip.png);
background-repeat:no-repeat;
content: " ";
display: block;
height: 20px;
position: absolute;
left:-10px; top:1px;
width: 20px;
z-index: -1;
}
see here example: http://jsfiddle.net/568Zy/11/
No, the background won't extend beyond the borders. But you can stretch the border as far as you want using padding and some clever tweaking of negative margins & position.
I understand this is really really late, and I am not even sure if this is best practice but I found a little way to do this with my footer. My last section had a background image that I wanted to overflow into the footer and I fixed it with a few lines of CSS. Also added a little padding the section with the background image.
footer{
background-color: transparent!important;
top: -50px;
margin-bottom: -50px;
}
I tried using negative values for background-position but it didn't work (in firefox at least). There's not really any reason for it to. Just set the background image on one of the elements higher up in the hierarchy.
After a little bit of research: No and No :)

Div height solution missing in ie6

i'm using a empty div to display a line by setting height 3px. it works fine in all browsers but in ie6 the height div displayed with 20px height. It remains same even for height:0px . But changes in other properties reflects but not height and there is no duplicate css entry and inherited value from other div. Can any one help please
<div id="line"></div>
CSS:
#line {
border: none;
background-color: #134c7c;
height: 3px;
margin-bottom: 20px;
}
Internet Explorer has the odd idea that the content of every element should be at least one character high. You can get around this by using the overflow attribute, that way the content can remain a character high, but it doesn't affect the height of the element itself:
.line { height: 3px; overflow: hidden; }
Try:
line-height:0
Just a wild guess.
Inspect whether there is any space inside the element. If yes then set the
font-size: 1px;
property of the element.
try with space in the div or
Just guess

Resources