I have a button which will get a box-shadow on hover. It also has a transition. My problem is, it doesn't always display the same result, sometimes the box-shadow will be offset by a few px and not be equal on all sides as shown on the image:
Below is my code and here is JSFiddle demo.
div{
width:100px;
height:25px;
transition:.2s;
background:lightgrey;
border-radius:25px;
}
div:hover{
box-shadow:0px 0px 10px green;
}
<div></div>
As you can see if you remove the transition the box-shadow is deisplayed properly.
div{
width:100px;
height:25px;
background:lightgrey;
border-radius:25px;
}
div:hover{
box-shadow:0px 0px 10px green;
}
<div></div>
What is even more interesting to me is that JSFiddle demo, would display different outputs after deleting and pasting back some code while keeping it without changes overally, or by running the same code again, or reducing the transition time. It's hard for me to explain how to reproduce this but you might see it yourself if you play with a bit.
My question is how to keep it consistent, and most importantly how to keep the box-shadow equal while keeping the transition.
#edit
Video of issue
Also I've made a video of how I see the differences since some people reported not to see any problem. Is it at all possible it's somehow fault of my screen? (Hopefully the issue is visible on the video or maybe I'm just going crazy)
#edit2
It seems like it is a browser issue. Originally I encountered the issue on latest Chrome version, couldn't reporoduce the problem on latest Firefox. After discovering that thanks to comments I've added webkit prefixes to transition and box-shadow but it didn't solve the problem.
As you said, it seems to be a bug but to overcome this you can do it differently using a pseudo element where you apply the box-shadow but you animate another property (scale, opacity, width/height, etc)
div.box{
width:100px;
height:25px;
margin:10px;
background:lightgrey;
border-radius:25px;
position:relative;
}
div.box::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
box-shadow:0 0 10px green;
border-radius:inherit;
transition:.2s;
transform:scale(0.8);
}
div.box:hover::before{
transform:scale(1);
}
<div class="box"></div>
Related
I've been searching but haven't found an answer for the specific problem I'm having.
I wanted to use sliding captions for the images on my art blog. The challenge was that I needed the container to adapt to variable image heights so I didn't have to go in and set it manually every time I post something new. What I have so far is really close to working but...
The div is 5 pixels bigger than the image, regardless of the image's height. I made the div background red so it's easy to see the overlap, but I just can't figure out where those 5 pixels are coming from.
I'm really new at this and changed all the css values I could think of and searched for other examples but I still couldn't get the overlap to go away. Any help would be awesome. I'm so close (I think) but I don't know what else to try. Here's most of the css with a jsfiddle link below:
/* variable container adapts to image size (plus 5 unwanted pixels) */
/* I made the background red so you can see where it's too big */
div#imgContainer {
min-width: 20px;
min-height: 20px;
display:inline-block;
background:red;
}
.postContainer {
position:relative;
overflow:hidden;
background: red;
}
.postContainer .postTextbox {
width:100%;
height:50px;
position:absolute;
bottom:0;
left:0;
margin-bottom:-15%;
margin-left:auto;
margin-right:auto;
opacity: 0;
border:0px;
background: black;
}
.postContainer:hover .postTextbox {
margin-bottom:0;
opacity: 1;
}
.postTextbox {
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
}
http://jsfiddle.net/nun243j1/
Thanks again in advance!
It may be because of white-space between elements. Apply image {display: block;} for images to remove this problem.
I am using borders on some content. However, I am finding an unwanted 1px outline the same color as the background color is being added around the border when the parent is transformed (at least with scale and rotate). This occurs on pseudo-elements of the children as well
.container {
transform:rotate(-45deg);
}
.child {
border:3px solid white; background:green;
}
jsFiddle to work with
I have tested on the newest Chrome and IE, the problem is on both
How can I get rid of this outline without using box-shadow or removing the transform?
Add a translateZ(1px)
.container {
position:absolute;
top:50%; left:50%;
-webkit-transform:translateZ(1px) rotate(-45deg);
transform:rotate(-45deg);
}
(not really sure why does this work ...)
fiddle
Seems that IE needs more fixing...
.container {
position:absolute;
top:50%; left:50%;
-webkit-transform:translateZ(1px) rotate(-45deg);
transform:perspective(999px) translateZ(1px) rotate(-45deg);
}
fiddle2
Not a great fix, but adding backface-visibility: hidden; which determines if the element should be visible or not when it's faced away from the screen, commonly used when you "flip" and element, seems to fix it, at least in Chrome. I haven't got the possibility to test in IE though.
The reason I tried it is because this "hack" has solved simliar issues that I've had before. But I'm not really sure why it works ...
jsFiddle
In chrome you should be able to use -webkit-backface-visibility: hidden; to fix this. I'm not too sure about IE, I don't have anything to test that on right now.
http://jsfiddle.net/ayFbD/4/
On my website I have a header with buttons made from background-images and a jQuery hover event. The problem is, in Chrome and Chrome only (in my tests), when mousing over the button the hover image is slightly cut off by about a pixel. I've tested it some and realized it only appears when there is a scroll bar (for consistency's sake, I've added overflow-y: scroll to all of my pages). The problem is fixed if I subtract half a pixel from the width, but it also messes with the margins. The background images are an identical size, 102x42px.
Here is my CSS and a link to my website:
.menubutton
{
margin:0px auto;
margin-top:-10px;
background:url('../img/buttons/menureg.png');
width:102px;
height:32px;
display:block;
color:#6F6F6F;
font-size:16px;
text-shadow: 0px 0px 1px rgba(0,0,0,0.2);
padding-top:10px;
text-decoration:none;
}
.menubutton:hover
{
background:url('../img/buttons/menuhover.png');
color:#E0E0E0;
text-shadow: 0px 0px 1px rgba(0,0,0,0.75);
}
I confirm the bug and like randy I think this is a problem with chrome and not your code.
It seems the problem appear and disappear because of the width if the page, if I resize my window the problem appear and disappear.
After some trials and error it seems the problem come partially from the size td element that encapsulate your menubutton. After trying some things around I thing I found a workaround. Since you know both the size of the td element and the menubutton, you don't need an automatic margin. So:
.menubutton
{
margin:0px 24px;
margin-top:-10px;
background:url('../img/buttons/menureg.png');
width:102px;
height:32px;
display:block;
color:#6F6F6F;
font-size:16px;
text-shadow: 0px 0px 1px rgba(0,0,0,0.2);
padding-top:10px;
text-decoration:none;
}
Can you test on your side to see if it resolves the issue?
I see your problem, but it look like a chrome bug though, not a code bug. two out of four elements have correct hover backgrounds, so its a bit strange. You can try to set the width of the element again in the hover, or make the element 1px wider and set background-repeat:none; to display the extra pixel. Bad solution though..
I have the following code which works fine in ie8 but not in Chrome. I want the border to show and it is not:
.sitewidth{
width:1000px;
min-height:100%;
height:auto;
margin:0 auto 0 auto;
border-left: 1px #EE6A00 solid;
border-right:1px #EE6A00 solid;
overflow:visible !important;
}
It may be that it's not showing high enough in Chrome without a height?
What's in the html code? Sometime it will require a <br clear="all" /> before the end of the closing div so that the whole div shows on screen.
I'm not too sure min-height will have any affect if it's followed by height:auto; ?
At the first, please define a background-color for your box to be sure it can be shown fine. Then, I suggest you remove other features at the first and solve your problem.
Do it with something like this:
.box {
background-color:silver;
width:1000px;
height:100px;
border:1px #000 solid;
}
If this can work fine, you can modify it with other properties.
In my case it happened because I used 0.5px instead of 1px. There is no such thing as half a pixel.
I need to achieve subject, and really got stuck. To better describe, I've put up a picture of what I need to get:
At first I've tried to do it with divs, but it looks completely different in Firefox due to width attribute. Although my primary concern is IE8 non-standard mode (that's requirement), I wanted it to look more or less decent in Firefox.
Then I tried to do it with two-column table, and it works well in IE and somewhat well in Firefox, but for some reason if the right column content gets wider than screen, table does not accomodate and my content is cropped horizontally by the table, no scrollbar is shown.
Also, looked at the earlier posts on Stackoverflow, with fixed container, but it doesn't seem to work in IE8 non-standard mode.
Would be glad to hear any ideas on how this could be done.
May be you can do like this:
.left{
float:left;
position:absolute;
width:200px;
background:red;
border:2px solid #000;
top:200px;
bottom:0;
left:0;
}
.right{
overflow:hidden;
background:green;
position:absolute;
top:200px;
bottom:0;
left:204px;
right:0;
border:10px solid #000;
}
html, body{
min-height:100%;
height:100%;
}
.header{
width:100%;
height:200px;
background:yellow;
}
Check this http://jsfiddle.net/QHTeS/
This should help - a very basic example.
http://jsfiddle.net/pRAgY/
Remember to adjust the width of the right container when you know the width, as the 6px border (totalling 24px) goes over the 100% width avalible.