I am building a website and ran into another problem with my code.
I have tooltips for a huge number of images so that when you hover over them you see information in the tooltip ( which is also an image)
My Problem is that when I hover the first few images they display the tooltip different then the rest of them.
My code looks like this:
.playertooltipimg{
width: 400px;
height: auto;
}
.playertooltipimg {
z-index: 100000;
}
a.tooltips {
position: relative;
display: inline;
}
a.tooltips span {
position: absolute;
visibility: hidden;
opacity: 0;
border: 5px solid white;
left:-80.15em;
transition: all 1s ease-in-out;
}
a:hover.tooltips span {
position: absolute;
left:-51.15em;
top: -0.2em;
visibility: visible;
opacity: 1;
transition: all 1s ease-in-out;
z-index: 999;
}
I think it's hard to understand what I mean which is why i created this jfiddle:
BUT you have to adjust the size of the window so that the 2 white boxes can be next to each other (in a row)
http://jsfiddle.net/ZkQLV/
I know it's a lot of code, I can't figure out why it is doing this, since every other images except the first few display the tooltip correctly
Your problem is caused by the use of inline and relative styles for the a (which is the container of the preview item). inline style makes the absolute positioning of the inner span a little strange, you can see that all the items on the second row seem to work OK, it happens only to the items on the first row (except the last item). However if you set display:inline-block for the a elements, you'll see that hovering on all the items won't work now, the popped-up tooltip has always the same offset (on the left side) from the a element (which you hover on). That's because you set position:relative for the a elements. So all the offsets (left and top) of the spans (which you set to some fixed values relative to font-size with em unit) will be compared against the hovered a element's position. To fix this issue, you have to choose the same element for all the items against which the offsets are set. The most suitable item is exactly the div #playersbig which contains all the items. To choose that div as the containing block of the inner span elements (in each item), you have to set its position to relative (which you've already done) but you have to remove the position:relative applied on the a elements.
Another note is that you should use right property to position your tooltip (span element), in the hidden state the right is about 200% (because your 2 divs #championsbig and #playersbig have the same width) while in the shown state, the right should be about 100%. The exact values of right depend on the padding/space width between your 2 divs #championsbig and #playersbig, looks like it's about 4px in your case). You can also use calc function to set the exact value but it's not supported by some old versions of browsers (especially the so-called IE), so I just use 201% and 101% respectively in the demo (because the width is 400px). If the width is fixed at 400px, you can also calculate the exact values for right yourself such as 804px and 404px instead of 201% and 101%.
CSS:
a.tooltips {
/* use this to have the expected absolute positioning
instead of the unexpected behavior when using inline style */
display: inline-block;
}
a.tooltips span {
position: absolute;
visibility: hidden;
opacity: 0;
border: 5px solid white;
top:0;
/* use right instead of left, this will hide the tooltip initially */
right:201%;
transition: all 1s ease-in-out;
}
a:hover.tooltips span {
position: absolute;
/* this will show the tooltip on hovering */
right:101%;
visibility: visible;
opacity: 1;
transition: all 1s ease-in-out;
z-index: 999;
}
Demo.
Related
I am creating the following side menu with animation: click
We can see an unwanted horizontal scrollbar, which should not be according to developer.mozilla.org,
absolute
The element is removed from the normal document flow, and no space is
created for the element in the page layout.
In the example above, the list of menu appears when you click on the checkbox and it has the class .m-list. .m-list has absolute positioning and relative positioning is set for its nearest parent(.m-block). I'm going to copy and paste these two classes
.m-block {
width: 100%;
background: gray;
padding: 0;
display: flex;
flex-direction: row-reverse;
position: relative;
}
.m-list {
position: absolute;
top: 100%;
background: silver;
right: 0;
width: auto;
list-style-type: none;
transform: translateX(0%);
transition: transform 0.25s ease-out;
}
Q1: Why does the horizontal scrollbar appear?
Q2: What is the most correct solution to prevent the appearance of a horizontal scrollbar?
I know 4 ways to solve this problem, but due to various reasons I do not want to use them:
If I change the absolute position to a fixed one, it does not generate a horizontal scrollbar, but the rule line with top: 100%; takes on a different meaning. In the original case, top: 100%; provides an offset from the blue stripe along its height.
Using JS is not available in this project
Using overflow-x: hidden on the top level of document will disable the scrollbar, which may be needed for content.
Moving the menu from the right side to the left will not result in a horizontal bar, however, this is an undesirable solution.
.m-list {
...
left: 0;
transform: translateX(0%);
}
#m-toggle:checked ~ .m-list {
...
transform: translateX(-100%);
}
I tried applying overflow-x: hidden; to <body>. and I was able to scroll down and hide the menu
I am trying to move a div from top left corner to bottom right corner using only CSS (this is required for my assignment). Also, I need to see the transition happening (the div sliding to the bottom). I tried using transform:translate() but i can't get my div to go to the bottom corner! Here is what I've done until now: http://codepen.io/ascii-hero/pen/JXEXVB
Tldr;
Solution 1: Using Left/Right/Top/Bottom positioning
In order for your div to move, you will need to set a parent element to relative, and the div to absolute positioning. Note, since the html element is the 'top most' element of the html tree, it is automatically assumed this relative position.
div {
background: red;
height: 50px;
width: 50px;
position: absolute;
top: 0;
left: 0;
}
html:hover div {
top: auto;
left: auto;
bottom: 0;
right: 0;
}
<div></div>
Solution 2: Transforms
Using transforms is great, as you can also add transitions for a smooth effect. Just note you'll need to add just a slight alteration to solution 1.
div {
background: red;
height: 50px;
width: 50px;
position: absolute;
top: 0;
left: 0;
transition: all 0.4s;
}
html:hover div {
top: 100%;
left: 100%;
transform: translate(-100%, -100%);
}
<div></div>
Explanation of Solution 2
To allow for transforms, the DOM needs to know the start point, the end point, and the duration explicitly. So hence, the start is set to
top:0; left:0;
To represent the top and left vales.
The 'duration' can be set using the transition property. Here I have set this to 0.4s(econds), but this can be altered to any suitable value.
Lastly, and most crucially, you need to set a definitive end point to your transform. Here you will notice the
top:100%;left:100%;
However, as I am sure you are aware in doing that it will put the very top left corner at this position, (100%,100%) so to speak. It is hence the reason for the inclusion for the translate to 'move the box back onto the screen'. The translate property takes two values, the X and Y disposition. By using a % as the unit, it will move a % of the size of either the width or height of the box, depending on the axis you are moving it. In other words, using
transform:translate(-100%, -100%);
will move the box 100% (of itself) to the left, and 100% (of its height) up, hence it can be seen in the bottom right of the page.
try this
#block:hover {
left: 100%;
top: 100%;
-webkit-transition-property: left, top, background, -webkit-transform;
-webkit-transition-duration: 2s, 2s, 1s, 1s;
transform:translate(-100%, -100%);
}
I'm on mobile so I hav t tested it but it /should/ work
So you want to move the div to bottom right corner. In your code you are doing
#block {
background: cornflowerblue;
width: 100px;
height: 100px;
left: 0;
top: 0;
}
so instead of top to be 0, you want bottom to be 0, and instead of left you want right.
Using bootstrap and trying to do a little simple css animation on hover, expanding the element to highlight it.
.text-block {
background-color: white;
min-height: 400px;
text-align: center;
transition: .1s;
margin: 1em;
}
.text-block:hover {
margin: 0em;
transition: .1s;
z-index: 99;
}
This almost looks right, as the element appears to be expanded since the margin is animated away, but it moves up the page so it appears only 3 sides of the element grow.
Is it possible to set the height on hover to the non-hover height+2em to make it appear to grow 1em in all directions within CSS?
Change margin to padding. Margin adds blank space outside of your element. Padding should give you the effect you want :D
I have a form and I want to display help text. The text might be a bit longer at times. I want to set a fixed width to the div containing the help text and make it grow by height. Then, to align the middle of the help text to the relative input. I'm flexible with the structure of the HTML.
This is a fiddle with the form and the help text.
CSS
.form-parameter {
display : block;
}
.form-parameter label , .form-parameter input {
width : 150px;
display : inline-block;
}
.form-parameter-helptext {
width : 150px;
visibility: hidden;
opacity: 0;
-webkit-transition: opacity 0.1s linear;
}
.form-parameter:hover .form-parameter-helptext {
visibility : visible;
opacity: 1;
}
All I found so far is how to align a div relative to a parent but not a sibling.
I set the width of form-parametr to 530px and add position:relative to it,and for your help div I add position:abolute;right:0;top:0;width:200px
as far as I know you cannot align the middle of the help text to the relative input with only html and css but I think this is what you want beside the aligning help text : DEMO
and for the record you need to set display:block to this div when you want your width to work,and you want help to be invisible,you've used visibility : hidden this way you just hidden that div but as you can see there is a white space that hold place for your help text,if you want to remove that white space ,you should usedisplay:none instead
Try this:
.form-parameter-helptext {
visibility: hidden;
color: #333;
background-color: #EEE;
border: 2px solid lightblue;
font-size: 13px;
padding: 5px;
margin-right: 10px;
opacity: 0;
-webkit-transition: opacity 0.1s linear;
/* This is what I added */
width:100px; // add the width
position:absolute; // set the position to absolute
}
I didn't test it on any browser or webpage but the fiddle works fine.
When the image grows in hover to 350px it pushes everything around.
This code is working except that when I hover and the picture grows it pushes the menu or what ever is around downwards.
How can I stop this?
#displaycar img
{
height: 200px;
}
#displaycar img:hover
{
height: 350px;
}
BTW I'm using twitter bootstrap and I have tried position: absolute;.
Is there any way to still increase size when hover but don't push nothing don't move nothing.
Set the height of #displaycar (the presumed parent div) to 200px and add overflow: visible;
#displaycar {
height: 200px;
overflow: visible;
}
I would use z-index on the elements. keep the values equal on the initial layout, but make it a stronger (bring to front) value when hovering
#displaycar img:hover
{
z-index:[stronger value];
height: 350px;
position :[relative, absolute, fixed];
}
note: to use z-index, you have to use one of the position values
Z-index gives priority to overlapping elements (bring to front / bring to back)
here is a bit more info on the subject
It's possible, but to avoid affecting surrounding content the element itself has to be removed from the flow of the document; this is easiest to achieve using position: absolute, though unfortunately this requires using a wrapping element, with position: relative (or any other non-static position value). The wrapping element has to have a width and height defined, which could be done automatically (with JavaScript, or PHP (amongst many other options)).
For example, the HTML:
<span>
<img src="http://placekitten.com/400/400/" />
</span>
<p><!-- generic dummy content, excised for brevity --></p>
And the CSS:
span {
display: inline-block;
position: relative;
width: 150px;
height: 150px;
}
span img {
position: absolute;
top: 0;
left: 0;
height: 150px;
width: 150px;
/* Vendor-prefixes removed, for brevity */
transition: all 1s linear;
}
span:hover img {
width: 400px;
height: 400px;
/* Vendor-prefixes removed, for brevity */
transition: all 1s linear;
}
JS Fiddle demo.