Disable overflow scrolling on webkit-based browsers - css

I'm using ::after to create shadow to decorate a element (say A).
In order to do this, I set the overflow: hidden for A to hide undesired part of the shadow.
It looks perfect, but there is a problem after I added a input box to A. If I click in the input and drag, the A layer will scroll, and the rest part of shadow will show up.
Here is the demo and the simplified code:
<div style="width: 200px; height: 30px; overflow: hidden; border: 1px black dotted;">
<div style="height: 30px; border-bottom: red 10px solid;">
<input style="width: 200px" placeholder="click and drag me downward" />
</div>
</div>
I'm looking for a pure CSS solution to fix this problem. Thanks ahead.

This isn't an ideal solution, but I don't think a pure CSS solution exists to this problem (unfortunately), it makes me wonder whether this has been logged as a bug with the Chrome team.
jQuery should be as follows:
$('input').on('mousedown', function(e){
$(e.target).focus();
e.preventDefault();
});
(I know I shouldn't assume you're using jQuery, if needed I can provide you a pure JS solution, it'll just be more complicated).
Fiddle: http://jsfiddle.net/jzb5a/
EDIT: Apparently this is a known bug (https://bugs.webkit.org/show_bug.cgi?id=114384) it's dissapointing that four months on there still hasn't been a fix though.

Finally come to an solution, which is not that perfect but fixed the problem anyway.
As the background overflows, and the input on the same layer would cause the problem. So just move the input to another layer which doesn't overflow. demo
<div style="position: relative; width: 200px; height: 30px; border: 1px black dotted;">
<div style="position: absolute; left: 0; top: 0; right: 0; bottom: 0; z-index: -1; overflow: hidden;">
<div style="height: 30px; border-bottom: red 10px solid;"></div>
</div>
<input style="width: 160px" placeholder="click and drag me downward" />
</div>

Related

Printing background-color in Firefox and IE

I am with some problems to print background-color in Firefox and IE. For Google Chrome I found the follow hack and it works well, but for Firefox and IE I can't find anything.
//Hack for Google Chrome
-webkit-print-color-adjust:exact;
I am glad if someone can help me with this.
For Firefox on the Print dialog there is an Advanced or Show Details button, if you click that , under Appearance there are two checkboxes. One for Print Background Colors and Print Background Images.
* {
-webkit-print-color-adjust: exact;
printer-colors: exact;
color-adjust: exact;}
Browsers: Chrome, Safari, FireFox
More: https://wiki.csswg.org/ideas/print-backgrounds
If you are OK with having your element being a fixed height/width, you can set its size, put a 1px coloured image into it (of whatever colour you want the background to be) and make it fill the space. Then you can absolutely position your content on top.
<div style="position: relative; width: 100px; height: 100px;">
<img src="/images/blue.png" style="width: 100px; height: 100px;">
<div style="position: absolute; top: 0px; left: 0px;">
Hello world
</div>
</div>
Or you could do the same thing with a border instead of an image:
<div style="position: relative; width: 100px; height: 100px;">
<div style="width: 0; height: 0; border: 50px solid black;">
<div style="position: absolute; top: 0px; left: 0px;">
Hello world
</div>
</div>
(Original idea from here: https://defuse.ca/force-print-background.htm)
For Firefox
color-adjust:exact;
will work same as -webkit-print-color-adjust:exact;
Seems impossible, as Spark says, but you can sometime use wide borders as workaround (e.g. div with 0 height and 100px border).

CSS borders interfering with absolute positioning

[edit: clarified that box-sizing: border-box doesn't seem applicable, since I'm using absolute positioning]
The following code illustrates my problem. I'm using absolute positioning, because I found this even trickier with flow-based layout, but I'm open to suggestions. What I want is borders around arbitrary elements, without the borders affecting the positioning of the nodes. (The borders may clip or be overwritten by the content, but that doesn't matter.)
In particular, the borders of a parent must be able to overlap with the borders of its children, which is not the default behaviour. The CSS box-sizing attribute can be set to border-box to achieve the effect I want, but only (I believe) with inline elements. It has no effect on elements with absolute positioning (as I understand things).
So, my approach has been to use a negative margin to offset the positions of the children by the width of the border. This does indeed seem to cancel out the effect of the border's presence, but unfortunately not in a way which is consistent across scaling factors. At large scales, things look ok. At the default browser zoom in Chrome, the element positioning goes a bit off (they appear too high); if I go smaller, then the element position goes off in the other direction.
But if I remove the borders entirely, the layout seems to scale ok.
So my question is: is there a reliable (scalable) way to have borders on HTML elements with no impact on the positioning of the elements?
[In the example, I've used different colours for some of the borders. I would like to see only black, but at some zooms I can see red and green borders, showing that the element's position is being affected by the presence of the border.]
thanks
Roly
.bordered {
position: absolute;
height: 18px;
border: 2px solid;
margin: -2px;
}
<span class="bordered" style="width: 55px; left: 30px;">
<span class="bordered" style="width: 8px; left: 0;">
(
</span>
<span class="bordered" style="border-color: green; width: 47px; left: 8px;">
<span class="bordered" style="border-color: red; width: 39px; left: 0;">
<span class="bordered" style="width: 8px; left: 0;">
5
</span>
<span class="bordered" style="width: 31px; left: 8px;">
<span class="bordered" style="width: 23px; left: 8px;">
Nil
</span>
</span>
</span>
<span class="bordered" style="width: 8px; left: 39px;">
)
</span>
</span>
</span>
Try out CSS2 outline property:
.bordered {
outline:2px solid blue;
}
Outline does not affect element position.
You can also use CSS3 outline-offset as seen here: http://www.css3.info/preview/outline/
I also discovered that using a border of zero width (so that it doesn't affect layout), and then adding a box-shadow to emulate a visible border, seems to work well.
Six years later...
The other answers didn't work for my situation since the box I was styling already had a box-shadow. I needed a border on just one side like border-left and a border-radius, but without the border affecting the position or width of the element. The solution I came up with was to apply the border on an inner element of the absolutely positioned element.
.outer {
position: absolute;
width: 200px;
height: 100px;
border-radius: 5px;
background-color: #c8c8c8;
}
.inner {
height: 100%;
min-height: 100%;
min-width: 100%;
width: 100%;
border-left: solid 5px #097fee;
border-radius: 5px;
}
<div class="outer">
<div class="inner">
Some content
</div>
</div>

How can I expand this <input> tag?

This is a simplified version of my question earlier today since I didn't get a satisfactory reply.
I have a HTML and CSS code as in this Fiddle: http://jsfiddle.net/wNGHz/
How can I make the <input> resize automatically when its parent frame is resized?
Notes:
I prefer to use only CSS rather than JavaScript.
The <input> should have 100px distance from left and right edges of the parent.
#thirtydot semantically I want to have a simpler HTML. I can wrap
<input> with <div> but it's just weird to add one more element for the
sole purpose of styling another one. I was wondering if anyone has a
better solution.
Unfortunately, there is no better way. It has to do with the fact that input is a replaced element, which means it behaves differently to non-replaced elements such as div.
One difference is that position: absolute; left: 0; right: 0 won't work in the same way on an input as it does on div (except in WebKit).
The best workaround is to wrap the input in a div:
http://jsfiddle.net/thirtydot/wNGHz/6/
<div class="inputContainer">
<input type="text" value="test" />
</div>
.inputContainer {
position: absolute;
left: 50px;
right: 50px;
}
input {
width: 100%;
background-color: red;
color: white;
border: none;
}
When you have input { width: 100%; }, it's usually a good idea to also add box-sizing: border-box, to make any padding and border on the input be counted inside the width: 100%: http://jsfiddle.net/thirtydot/wNGHz/7/
The only pure CSS way I know of is by adding a width in %: http://jsfiddle.net/PeeHaa/wNGHz/1/
You can do this better way.
<div class="inputContainer">
<input type="text" value="test" />
</div>
input {
width: 100%;
margin:0 100px;
}

Div width: auto and IE

I'm using the jQuery qTip to show individual users and their votes when an average rating is mousedover.
qTip calls a PHP file which grabs all the users and votes for the item from the MySQL database and builds a 3 column table, which appears as the tooltip.
In Firefox, the tooltip displays properly.
In IE7 (haven't tested on IE8 yet), the tooltip is the proper height, but the width is only 2 or 3 characters - not the entire table.
If I set the width of the div to a fixed number, say width: 300px; I can coax IE into displaying it properly.
However, the length of my users' names varies considerably, and I'd rather not nail down the div to its maximum possible width and then have a crapload of whitespace when you look at an item voted on only by "Joe".
Using width: auto; has no effect in IE7.
Are there alternatives?
Sorry if I've overlooked a similar question. I searched for a bit before posting but didn't find anything suitable.
EDIT TO ADD CODE:
<div
style="-moz-border-radius: 0pt 0pt 0pt 0pt;
position: absolute;
width: 358px;
display: none;
top: 384.617px;
left: 463.5px;
z-index: 6000;"
class="qtip qtip-defaults" qtip="0">
<div style="position: relative;
overflow: hidden;
text-align: left;"
class="qtip-wrapper">
<div style="overflow: hidden;
background: none repeat scroll 0% 0% white;
border: 1px solid rgb(211, 211, 211);"
class="qtip-contentWrapper">
<div class="qtip-content qtip-content"
style="background: none repeat scroll 0% 0% white;
color: rgb(17, 17, 17);
overflow: hidden;
text-align: left;
padding: 5px 9px;">
<div id="WhoResults">
<table>
<tbody>
<tr>
<td>guy1</td>
<td>guy2</td>
<td>guy3</td>
</tr>
<tr>
<td>guy4</td>
<td>guy5</td>
<td>guy6</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
I have applied no CSS styling. That's all been handled by qTip. I tried to format it as best I could. Thanks for any help you can provide.
Try using min-width:300px instead of width
It turned out to be a bug in the way qTip was calculating the proper tooltip width for IE. I overrode that line in the qTip code and posted a note to the developer's forum.

Positioning Columns With Absolute Positioning Instead of Floats

I have read several articles regarding templates for web site content. They all seem to recommend that the columns should be placed on your site via floats. Example:
<div id="container" style="width: 1000px;">
<div id="main_content" style="border: solid 1px Black; width: 798px; /* width = 800px -2px for border */ float: left; height: 400px;" ></div>
<div id="links_menu" style="border: solid 1px Black; width: 198px; float: right; height: 600px;"></div>
</div>
However, I always manage to mangle my content whenever I use floats. I spend more time trying to determine where to put my <div syle="clear:both;" />'s than I do actually designing the look and feel of the site. Also, whenever I place one of our third party ComponentArt controls inside a floated container, it manages to get mangled and require me to specify heights and widths, which aren't determined until run time.
Furthermore, I have found that when I use absolute positioning, things seem to work out better for me. Example:
<div style="width: 1000px; height: 600px; position: relative;">
<div style="border: solid 1px Black; width: 798px; position: absolute; top: 0; left: 0; height: 400px;"></div>
<div style="border: solid 1px Black; width: 198px; position: absolute; top: 0; right: 0; height: 600px;"></div>
</div>
Anyway, I am still relatively new to Stylesheets and HTML, so I would like to throw this out there to you all to see what you think about this alternative for content placement. Do you see any negatives to this approach? I've tried in most browsers and they all seem to render correctly, but I don't know what the future holds... Or maybe, someone can recommend a better way to float my containers so that the inner content is not floated as well. I'm definitely open to suggestions, and appreciate any feedback that you can provide.
Thanks in advance for your help!CJAM
A big problem with absolutely-positioned containers is placing content on the page below them when you don't know their heights ahead of time. In your example you have defined the heights of your absolutely-positioned elements, so this shouldn't be a problem for you. If it works for you, use it.
There's really no right and wrong to achieve something with css. It's more about effectiveness/flexibility.
Using absolute-position for column layout decreases that. Inserting, removing a column will require you to recalculate all the positioning. What if there are multiple instance of the same-styled column? We can't reuse the styling 100% since it's absolutely positioned.
There's lots of approach to column layouts. Check out some #
listapart,
positioniseverything

Resources