I am have a table where I would like to be able to click on the table header row and that will collapse the rest of the table leaving only the header row (and expand back out). With a good deal of struggle I was able to get the table to actually change it's height on click, but haven't been able to get the animation to trigger. Here is the css that I have so far:
table {
height: 100%;
display: block;
overflow: hidden;
}
.collapsed {
animation-name: collapse;
animation-duration: 2s;
}
#keyframes collapse {
from { height: 100%; }
to { height: 40px; }
}
/* This is the javascript that is trigger on click */
this.refs.ruleslisttable.classList.toggle("ruleSetInfo__rule-list-table--collapsed");
The code above doesn't even trigger the new height when I toggle the class on the table, but has been my attempt at getting the animation in there.
You don't really need to do it with keyframe animation.
You could do it just by adding a transition rule to the table element, like this:
table {
height: 100%;
display: block;
overflow: hidden;
transition: height 2s ease-in;
}
.collapsed {
height: 40px;
}
What this does, is tell the browser to transition the height of the table from 100% to 40px and vice cersa over a duration of 2s with an ease-in function
For more info you can read the entry about the transition property at MDN
Cheers
UPDATE:
In your current setup I suppose the parent of the table element does not have a strictly defined height.
The way the percentage based height works is like this: The element gets the 100% of its parent height.
However when you do not specify a height for the parent, be it in px, em, rem, vh or what have you, the child with height: 100% is like having height: auto. Reference
And here is the actual problem: You cannot transition from auto to any other value, like %, px etc.
You can only transition from one defined value (!== auto) to any other defined value. e.g. from px to rem, etc
And this is why your transition is not working.
See this fiddle
I made. Play with the #cont element's height and see what happens.
So, in short: You will either have to give a strict height to your table, or, if you want to keep it percentage based, give a strict height to its parent element.
Related
This is probably pretty simple, but I can't seem to figure it out or find an answer.
I have an html element <div class="box">
This element has a set rule in its original style sheet :
.box {
width: 40%;
}
I'm using a Custom CSS sheet that overwrites the original stylesheet without touching it.
I need to change this rule to :
.box {
max-width: 40%;
}
So basically how do I add this new rule, but cancel the old one ??
Could it be something like ? :
.box {
width: 0;
max-width: 40%;
}
??
You can reset to the automatic (default) width. A width with the value of auto tells the browser to calculate the width based on the other properties constraining the element.
.box {
width: auto;
max-width: 40%;
}
To reset the width to what it would be by default, set the value to auto. So, your overwriting CSS rules would be:
width: auto;
max-width: 40%;
If you set the width to 0, then your box wouldn't even display. Max width is just what it sounds like - the widest the element can be, but it can also be any width less than that. So, setting a maximum width of 40px but a width of 0px will cause the element to have a width of 0px.
Normally the CSS rules work as the name says in cascade mode so you can do another .box in a different file and then link that file to the document, but remember in order to the rule to apply the new document must be the one to be linked to.
Also you can try in the same CSS document something like this:
.box {
max-width: 40% /*Change this value to the one you want*/
}
I've got (hopefully) a simple CSS problem, that I cannot get working.
If you go to http://new.therepairshack.com and take a look at the top search bar.
When you hover over it, it resizes to content width.
The CSS for this is here:
.header .search-wrapper .form-search .input-text {
background:rgba(0,0,0,0);
color:#000;
border-radius:0px;
border-bottom:1px solid #444;
}
.header .search-wrapper:hover,
.header .search-wrapper:hover .form-search,
.header .search-wrapper:hover form,
.header .search-wrapper:hover .input-text {
width:100%;
font-size:45px;
height:100px;
}
.header .search-wrapper,
.header .search-wrapper form,
.header .search-wrapper .form-search,
.header .search-wrapper .input-text {
transition: all 1.0s ease;
-webkit-transition: all 1.0s ease;
display:block;
}
Right now we're working on getting this functionality working in Chrome and Firefox. When I view it in chrome the background div instantly jumps to a larger height to fit the resized search bar, but when it resizes back down after you've left hover it does it smoothly.
My question: Is there any way to make the jumping go away? It's driving me nuts. I have added a transition to all of the elements that are moving when the search bar is being resized and that isn't working.
Also, what is the best way to get this working properly in other browsers? Thanks!!!
Let me know if you need anymore information!
It can't transition from an undefined starting point.
You must either
Specify an initial height on your .search-wrapper
http://jsfiddle.net/5h69j6uq/
Or, if your content must be dynamically sized, set the updated height by using the min-height: 100px property rather than the height: 100px property. min-height has a default value of 0 and will thus transition from that defined default value to 100px
http://jsfiddle.net/8t1beeLo/
You will have to manually set the height on the .header-top-container class and adjust it accordingly for the hover state.
CSS by standard will only apply animations to elements that are defined in rules to have them applied. And furthermore transitions will only be applied when there is a starting and end result, so inferred values such as height and width will not be animateable. Noticed I didn't say inherited values, as those technically have a starting value and therefore are animateable.
So for your CSS, you'll want something to this effect:
.header-top-container {
transition: height 1.0s ease;
-webkit-transition: height 1.0s ease;
height: 50px; /* change to whatever your height should be */
}
.header-top-container:hover {
height: 100px; /* the new height of the background */
}
Given the following structure, I need level2 have a min-height without changing the structure. Further, I am not able to move the overflow: hidden to a different class (the example is simplified, it would affect a lot of other things). It works with px, but not with %. All other css properties can be changed.
I am aware of vh, which works exactly like it should. But I would love a solution with CSS2.
Fiddle
HTML:
<div id="level1">
<div id="level2">
<div id="heighter"></div>
</div>
</div>
body and html: height 100%
level 1: min-height 100%, overflow hidden
level 2: min-height 100%
heighter: height 200px
Edit: More informations about the overflow:hidden
I am using this for a offcanvas navigation. This is a place where I can't use max-width (right?). If I replace the overflow with the max-width, the layout gets recalculated and after that I am able to scroll the level2 on the x-axis (left and right). Same problem as here (click on Push-Menu-Left and then you are able to scroll the x-axis). What I am trying right now is preventing the x-axis scrolling and being able to use the min-height: 100% corretly.
In order to calculate min-height, div#level2 needs to refer to the height definition of its parent. In your code, div#level1 does not have a specified height. You an specify one like so:
#level1 {
height:100%;
overflow: hidden; /* This has to be here */
background-color: red;
}
WORKING EXAMPLE
EDIT:
Explicitly setting height on div#level1 (rather than setting min-height), you no longer need the overflow:hidden definition. Removing that allows the page to scroll when div#heighter expands beyond the browser's height.
(You mentioned that you need the overflow:hidden for other reasons. If possible, please edit your question to describe those reasons a bit more.)
#level1 {
height:100%;
background-color: red;
}
#level2 {
min-height: 100%;
background-color: lightseagreen;
}
#heighter {
height: 2000px;
width: 100px;
background-color: white;
border: 5px dashed black;
}
WORKING EXAMPLE
http://jsfiddle.net/b8uj75e5/3/
#level2 {
min-height: 1000px; /* Working */
min-height: 100%; /* Not working */
background-color: lightseagreen;
display: block;
position: absolute;
width: 100%;
}
IT LIVES.
I just messed around until it worked.
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.
I've got a question concerning webkit marquee. I've got 2 elements of a variable width. (The 2 elements are the same width), and both elements need to be a marquee.
However when the content has overflow (is larger then the element) I need a marquee, if not the text should remain as it is (no scrolling).
I've created a JSFiddle as an example:
http://jsfiddle.net/Vxwed/:
The long and short both need to be marquee'd through CSS3, while the long should scroll and the short one doesn't.
<p class="long">Hi my name is John Doe</p>
<p class="short">Yeah!</p>
Remember, the contents of the elements are variable (filled with javascript), so I cant do actual hardcoding on the elements marquee-behaviour.
Any CSS experts here able to help me? I've been researching this a lot but there is little information about this subject, since it's relatively new.
The only solution that I'm able to think of right now is using jQuery to measure the width of the elements, and then calculate if they need extra spacing. If they need apply marquee, else don't. But that doesn't seem very clean to me, I'd rather do this in HTML/CSS only if possible.
This probably doesn’t do exactly what you want but it was a good problem to look at: http://jsfiddle.net/4hgd8ac1/
It uses CSS animations to animate the transform: translateX percentage as this is based off the width of the element itself. This means we can scroll an element it’s full width left. By then giving the marquee a minimum width we can standardise the shorter text lengths. Then we use calc(100% + 100px) move the item 100% left except the width of the carousel (100px).
It doesn’t quite have the traditional marquee feel with the text scrolling fully but using the animation keyframes it is possible to pause at the end of the text to give the user time to read.
p {
height: 30px;
width: 100px;
background-color: #CCC;
white-space: nowrap;
}
.marquee {
overflow: hidden;
position: relative;
}
.marquee__content {
padding: 5px 0;
margin-right: 100px;
position: absolute;
height: 20px;
animation: scroller 3s linear infinite;
min-width: 100px; /* This needs to match the width of the parent */
}
#keyframes scroller {
0% {
transform: translateX(0%);
}
/* ‘pauses’ the scroller at the start for 20% of the time, adjust to edit timing */
20% {
transform: translateX(0%);
}
/* ‘pauses’ the scroller at the end for 20% of the time */
80% {
/* Translate will use the width of the element so 100% scrolls it’s full length. add the width of the marquee to stop smaller items scrolling */
transform: translateX(calc(-100% + 100px));
}
100% {
transform: translateX(calc(-100% + 100px));
}
}
<p class="marquee"><span class="marquee__content">Hi my name is John Doe</span></p>
<p class="marquee"><span class="marquee__content">Yeah!</span></p>