CSS div within div Transition not working - css

Good morning, I have a Div within a Div, the child div is hidden, but displays when the mother div is hovered. I need this display to be transitioned, but when I try this with Display or Visibility, its not working. I've created a fiddle here with sample code:
https://jsfiddle.net/eggb4zra/
.vocabTitle
{
text-align:left;
background:linear-gradient(#ffffcc, #ffffcc, white, lightblue);
padding:3px;
padding-bottom;2px;
border:2px solid black;
border-radius:15%;
cursor:pointer;
transition: all 2s;
}
.highlightClass
{
background-color:pink;
}
.hiddenMeaning
{
visibility:hidden;
display:none;
}
.vocabTitle:hover .hiddenMeaning
{
visibility:visible;
display:block;
}
You can see the display works on hover, but not transitioned. Any help appreciated.

Transition for display: none to display: block will not work in CSS since none value removes the element as if it is not there in the page.
Try transition of height* from 0 to say 20px. Set overflow: hidden to the div to be hidden initially.
*Since you need to use dynamic height, you can make use of max-height instead of height
Updated JSfiddle
.vocabTitle {
text-align: left;
background: linear-gradient(#ffffcc, #ffffcc, white, lightblue);
padding: 3px;
padding-bottom;
2px;
border: 2px solid black;
border-radius: 15%;
cursor: pointer;
transition: all 2s;
}
.highlightClass {
background-color: pink;
}
.hiddenMeaning {
transition: all 2s;
max-height: 0;
overflow: hidden;
}
.vocabTitle:hover .hiddenMeaning {
max-height: 100px;
}
<!-- Left bar -->
<div class="kanjiVocab">
<p>Kanji and Vocabulary listed below:</p>
<div class='vocabTitle'>風邪 (かぜ ふうじゃ )
<div class='hiddenMeaning'>common cold cold influenza flu ague</div>
</div>
<br>
<div class='vocabTitle'>気味 (きみ きび )
<div class='hiddenMeaning'>sensation feeling tendency propensity</div>
</div>
<br>
<div class='vocabTitle'>熱 (ねつ )
<div class='hiddenMeaning'>heat fever temperature zeal passion enthusiasm mania craze rage</div>
</div>
<br>
<div class='vocabTitle'>季節(きせつ)
<div class='hiddenMeaning'>Season</div>
</div>
<br>
<div class='vocabTitle'>風邪 (かぜ ふうじゃ )
<div class='hiddenMeaning'>common cold cold influenza flu ague</div>
</div>
<br>
<div class='vocabTitle'>引き (ひき )
<div class='hiddenMeaning'>pull patronage influence tug discount</div>
</div>
<br>
<div class='vocabTitle'>で (で )
<div class='hiddenMeaning'>indicates location of action at in indicates time of action indicates means of action cause of effect by and then so indicates continuing action indicates certainty, emphasis, etc.</div>
</div>
<br>
<div class='vocabTitle'>ん (ん )
<div class='hiddenMeaning'>yes yeah uh huh negative verb ending used in informal speech (abbr. of negative verb ending "nu") abbr. of particle "no" abbr. of particle "ni" (used especially when it precedes the verb "naru")</div>
</div>
<br>
<div class='vocabTitle'>を (を )
<div class='hiddenMeaning'>indicates direct object of action indicates subject of causative expression indicates an area traversed indicates time (period) over which action takes place indicates point of departure or separation of action indicates object of desire, like, hate,
etc.</div>
</div>
<br>
</div>
<!-- End of left bar -->

Related

non-classified element interrupts targeted styling of child of classified elements

I'm trying to style first and last child, inside span with a specific class.
It doesn't matter if I use > or not in my CSS,
This code won't work unless I remove the first and the last DIV, even though they are unrelated to the class I'm trying to target.
Why?
CSS:
.parent-span .cta-wrapper {background:gray;}
.parent-span:last-child > .cta-wrapper {background:red; }
.parent-span:first-child > .cta-wrapper {background:green}
HTML:
<div>xxxxxxxxx</div>
<span class="parent-span">
<div class="cta-wrapper">
<div>1</div>
</div>
</span>
<span class="parent-span">
<div class="cta-wrapper">
<div>2</div>
</div>
</span>
<span class="parent-span">
<div class="cta-wrapper">
<div>3</div>
</div>
</span>
<div>xxxxxxxxx</div>
Use last-of-type and first-of-type instead of last-child and first-child
The last-child / first-child address and count ALL siblings of the parent element: divs, spans, p etc.
The last-of-type / first-of-type selectors address only the one TYPE (the tag, not the class), i.e. the divs OR the spans OR the p tags etc.
.parent-span .cta-wrapper {
background: gray;
}
.parent-span:last-of-type>.cta-wrapper {
background: red;
}
.parent-span:first-of-type>.cta-wrapper {
background: green
}
<div>xxxxxxxxx</div>
<span class="parent-span">
<div class="cta-wrapper">
<div>1</div>
</div>
</span>
<span class="parent-span">
<div class="cta-wrapper">
<div>2</div>
</div>
</span>
<span class="parent-span">
<div class="cta-wrapper">
<div>3</div>
</div>
</span>
<div>xxxxxxxxx</div>
nth CSS Selectors🟉
When using nth CSS selectors, we must take certain things into consideration:
Hint #1 - The ancestor element that all of the target elements have in common.
Hint #2 - Each of the target elements' tagNames and their ancestors as well.
Hint #3 - The nth point of entry which isn't always the target elements. It could possibly be more than one level depending if the target element and/or ancestor elements have sibling elements or not and how they are positioned.
Hierarchy
The layout is a 5 level hierarchy.
ROOT ---- tagName: <html>
LEVEL 0 - tagName: <head>, <body> - Role: <<<COMMON ANCESTOR>>>
LEVEL 1 - tagName: <div>, <span> -- Role: <<<POINT OF ENTRY>>>
LEVEL 2 - tagName: <div> -------------- Role: <<<TARGET ELEMENT>>>
LEVEL 3 - tagName: <div>
Two nth's - nth-child and nth-of-type
nth-child:
If you use nth-child, ignore hint #2,
So at the point of entry the common ancestor (i.e. <body>) has 5 children, not 3 children.
The line-up is: <div>, <span>, <span>, <span>, <div>
So instead of first-child it should be nth-child(2)
Instead of last-child, it's nth-child(4)
nth-of-type:
If you use nth-of-type, Hint #2 is key to understanding how to use nth-of-type.
At the point of entry the common ancestor has 2 <div>s and 3 <span>s.
Now we can specify a <span> as first, last, etc. because nth-of-type differentiates between element tagNames.
[common ancestor]................:body
{direct descendant(a.k.a. child)}:>
[point of entry].................: span:first-of-type
[target element].................: div
body>span:first-of-type div
Of course the selector above can have variations, but the important part is the point of entry span:first-of-type.
Demo
Click any span and it will revert from display:block to display:inline which is what was posted in OP
Hover over any element to see its Level in the hierarchy, its tagName, and what its role is.
There is a version of nth-child styles commented out included as well.*
// For demonstration purposes
Array.from(document.querySelectorAll('span')).forEach(function(spn, idx) {
spn.addEventListener('click', function(e) {
spn.classList.toggle('inline');
}, false);
});
:root::before {
content: 'ROOT';
}
html {
height: 111vh;
width: 90vw;
background: rgba(255, 200, 50, 0.2);
font: 600 15px/1 Consolas;
cursor: crosshair;
overflow-y: scroll;
text-align: center;
color: black;
}
body {
height: 101%;
width: 50vw;
padding: 0 10vw;
margin: 2vh auto;
outline: 0.5rem solid rgba(250, 150, 150, 0.9);
background: rgba(50, 255, 0, 0.4);
font-size: 0.8rem;
}
div {
max-height: 15vh;
max-width: 50vw;
padding: 10px;
outline: 2px dashed darkblue;
background: rgba(255, 200, 50, 0.5);
}
span {
/* OP: display:inline */
display: block;
min-height: 10%;
max-width: 50vw;
padding: 0 20px;
margin: 8px auto;
outline: 3px solid blue;
background: rgba(255, 0, 100, 0.7);
}
.inline {
display: inline;
}
/*::..BEGIN DISABLED OP..::
.parent-span .cta-wrapper {background:gray;}
.parent-span:last-child > .cta-wrapper {background:red; }
.parent-span:first-child > .cta-wrapper {background:green}
}
::..END DISABLED OP..::*/
/*::..BEGIN nth-type-of..::*/
body>span>div {
background: gray;
}
body>span:first-of-type>div {
background: red;
}
body>span:last-of-type>div {
background: green;
}
/*::..END nth-of-type..::*/
/*::..BEGIN nth-child..::
body>span>div {
background: gray;
}
body>span:nth-child(2)>div {
background: red;
}
body>span:nth-child(4)>div {
background: green;
}
::..END nth-child..::*/
<html title='ROOT-HTML'>
<head title='L0-HEAD'>
</head>
<body title='L0-BODY [COMMON ANCESTOR]'>L0
<div title='L1-DIV'>[XXXX] L1 [XXXX]</div>
<span class="parent-span" title='L1-SPAN [POINT OF ENTRY]'>L1
<div class="cta-wrapper" title='L2-DIV [TARGET ELEMENT]'>L2
<div title='L3-DIV'>L3 [1]</div>
</div>
</span>
<span class="parent-span" title='L1-SPAN [POINT OF ENTRY]'>L1
<div class="cta-wrapper" title='L2-DIV [TARGET ELEMENT]'>L2
<div title='L3-DIV'>L3 [2]</div>
</div>
</span>
<span class="parent-span" title='L1-SPAN [POINT OF ENTRY]'>L1
<div class="cta-wrapper" title='L2-DIV [TARGET ELEMENT]'>L2
<div title='L3-DIV'>L3 [3]</div>
</div>
</span>
<div title='L1-DIV'>[XXXX] L1 [XXXX]</div>
</body>
</html>
🟉The terms: common ancestor™, point of entry™, role™, and hierarchy™ are not standard terms, they are of my own creation because these rules are never explained very well AFAIK by anyone (myself included).
In order for first-child and last-child pseudos to work your html content needs to be inside a list or some other series of items. Your spans are singular and so there's no first and last item.
See the unordered list I created and the styling to select first and last list item there.
In order for you to do this, put your spans in a div with the parent class, then select that parent div and then a first-child/last-child for a repeating element inside.
.parent-span .cta-wrapper {background:gray;}
.parent-span:last-child > .cta-wrapper {background:red; }
.parent-span:first-child > .cta-wrapper {background:green}
ul {
list-style: none;
margin: 2em 0 0 0;
padding: 0;
}
ul.parent-span li:first-child
{
background:green;
}
ul.parent-span li:last-child
{
background:red;
}
<div>xxxxxxxxx</div>
<span class="parent-span">
<div class="cta-wrapper">
<div>1</div>
</div>
</span>
<span class="parent-span">
<div class="cta-wrapper">
<div>2</div>
</div>
</span>
<span class="parent-span">
<div class="cta-wrapper">
<div>3</div>
</div>
</span>
<ul class="parent-span">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<div>xxxxxxxxx</div>

select second active slide in slickslider through css-selector

I am using slick slider and showing 3 slides, I would like to add specific styling on the center slide. by using nth-of-type but it seems to fail when I add .slick-active:nth-of-type(2) any ideas?
for example:
<div class="slickslider">
<div class="slick-slide"></div>
<div class="slick-slide"></div>
<div class="slick-slide"></div>
<div class="slick-slide slick-current slick-active"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide slick-active"></div>
<div class="slick-slide"></div>
<div class="slick-slide"></div>
</div>
.slick-slide{
background: blue;
width: 20px;
height: 20px;
margin-bottom: 1px;
}
.slick-active{
background: green;
width: 20px;
height: 20px;
}
.slick-active:nth-of-type(2){
background: pink;
}
https://jsfiddle.net/pixelatorz/73scpych/2/
You can do it this way by playing process of elimination:
.slickslider .slick-active + .slick-active:nth-child(odd){
background: pink !important;
}
See demo
Basically, eliminate the first one with the + and next, eliminate the last one by choosing the odd child. Or first child would've worked too
EDIT
If you think there will be more than 3 active slides in the future and you want to make this more dependable, I suggest you wrap the active slides in a <span> and class it active-slides or something similar. Then. you will be able to select through them with nth-child without using .slickslider as a parent.
Is a stupid solution, but works:
.slick-slide:nth-of-type(6){
background: pink;
}

How the use the results of a CSS CALC() to update the left property value

I am trying to use, and then change, the left property value of my left-hand sidebar as though it were a memory variable unsuccessfully.
My basic algorithm is
left = (left * (-1) - 250)
Initial value of left is 0.
step #1: If left (value) is 0; then left should become -250.
step #2: If left (new value) is -250; left should then become 0.
step #3: go to step #1
Try this in a spreadsheet where left is the value of the preceding row. Your result rows should look like this:
-250
0
-250
I am effectively trying to toggle the left value from 0 to -250 then back to 0.
So that my left hand sidebar is either "on" or "off" canvas as determined by the left: value.
I have tried many variations of calc, including
#leftr: 0; is set at the beginning of of my CSS sheet.
#negtv: -1; also set at the beginning of my CSS sheet.
....
#leftr: -webkit-calc(~"((#leftr * #negtv) - 250)"); /* slide-in/out 0 or -250 */
left: #leftr;
I hope this is clearer than mud and that you guys can help me?
Thanks in advance
That is not possible with pure CSS, AFAIK.
Consider to use JavaScript for that. Here's example:
Script
$('.sidebar-toggle').click(function() {
var sidebar = $('.items');
sidebar.css('margin-left', 0);
if (!sidebar.hasClass('hidden'))
sidebar.addClass('hidden');
else
sidebar.removeClass('hidden');
});
$('.sidebar-slide').click(function() {
var sidebar = $('.items');
var hidden = sidebar.hasClass('hidden');
if (hidden) {
sidebar.css('margin-left', -sidebar.width()*2);
sidebar.removeClass('hidden');
sidebar.animate({'margin-left': 0});
} else {
sidebar.css('margin-left', 0);
sidebar.removeClass('hidden');
sidebar.animate({'margin-left': -sidebar.width()*2}, function() {
sidebar.addClass('hidden');
});
}
});
HTML/CSS
<style>
.nav {
}
.nav a {
cursor: pointer;
color: navy;
font-weight: bold;
}
.items {
position: absolute;
width: 100px;
border: 1px solid black;
}
.items.hidden {
display: none;
}
</style>
<div class="nav">
Sidebar:
<a class="sidebar-toggle">Toggle</a>
| <a class="sidebar-slide">Slide</a>
</div>
<br />
<div class="items">
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
<div class="item">item</div>
</div>
You can try it at jsFiddle.
If you want a sidebar that shows up when the user clicks something, without JavaScript, you can use the hidden checkbox trick.
.sidebar {
padding:8px;
position:absolute;
left:-250px; top:0;
width:234px; height:100%;
height:calc(100% - 16px); /* sorry */
background:#CCF;
transition:left 1s;
}
#showsidebar {display:none}
label[for='showsidebar'] { /* make it look like a link */
color:blue;
text-decoration:underline;
cursor:pointer;
}
#showsidebar:checked ~ .sidebar {
left:0;
}
<input type="checkbox" id="showsidebar">
<label for="showsidebar">show sidebar</label>
<section class="sidebar">
<label for="showsidebar">hide sidebar</label>
<h1>The sidebar!</h1>
<p>(contents of sidebar)</p>
</section>
<h1>The main site</h1>
<p>Blabla. Something Latin.</p>

Border is missing

I can't figure out why the border isn't showing up. I have a main wrapper that encapsulates all the elements; I'm just making the background of each element a transparent white, and then adding a transparent white border to the wrapper.
http://violetoeuvre.com/
/* Wrapper - Main *********/
.main_wrapper{
display:block;
background: rgba(255,0,0,.5);
width:1000px;
height: 2000px;
margin-left:18%;
margin-top:7%;
border:10px;
border-color: rgba(255,255,255,.5);
}
html
<div class="main_wrapper">
<!-- Logo _____________________________________________________-->
<div class="logo">
<a href="index.html"><img alt="emma carmichael" height="150px"
src="images/Home/emma-logo.png"></a>
</div>
<!---Navigation Menu ______________________________________________-->
<div id="main_menu" class="wrapper_nav_box">
<div class="nav_box">
WRITING
</div>
<div class="nav_box">
BLOG
</div>
<div class="nav_box">
CONTACT
</div>
</div>
Any ideas?
As #Lotus said:
You forgot to include the border-style
As an altenative to use the shorthand as Lotus suggested, you could do like this:
.main_wrapper
{
/*other stuff*/
border-width: 10px;
border-style: solid;
border-color: rgba(255,255,255,.5);
}
Note: I add this to extend on Lotus's answer, and to help to answer #Claire's comment "i know i should use shorthand, but why wouldn't the other way work?"

Why are my div boxes ignoring my css code?

Firstly, I would like to say that I have tested if my link to my .css works, the background is made into a black color.
This is a ASP.NET Mvc test application which I am making, and I am having difficulty positioning some of my elements which are nested in div boxes. I have come to the conclusion that my div boxes nested within the topmostheader box is ignoring my .css code.
Here is my entire css file, called custom1.css
#topmostheader
{
background: none repeat scroll 0% 0% rgb(0, 0, 0);
height: 90px;
text-align: center;
}
#topmostheader.inner
{
width: 1280px;
margin: 0 auto;
text-align: left;
background-color: Red;
}
#topmostheader.app-name
{
font-size: 14px;
float: left;
line-height: 90px;
color: rgb(119,119,119);
margin: 0px 20px 0px 0px;
}
#topmostheader.xxx-logo
{
margin: 0px;
height: 90px;
float: right;
}
and here is my div box layout.
<div id="topmostheader">
<div class="inner" >
<div class="app-name">
Lunch Application
</div>
<div class="xxx-logo">
<img src="/content/xxx/logo.png" alt="xxx logo"/>
</div>
</div>
</div>
The desired result is not produced: the app-name, inner and acceleration logo divboxes are all dead-center in the screen, where the app-name must be in the left side, and the logo in the right.
I have tested the following code (Which produced the desired result, in an undesired manner - I may reuse this code multiple times which are in the .css file)
<div id="topmostheader">
<div class="inner" >
<div class="app-name" style="float:left">
Lunch Application
</div>
<div class="xxx-logo" style="float:right">
<img src="/content/xxx/logo.png" alt="xxx logo"/>
</div>
</div>
</div>
What am I doing wrong? Why are my div boxes not "floating" when I use the .css file?
To target the correct divs you need a space between the id and class name in your CSS rules: (e.g. change #topmostheader.app-name to #topmostheader .app-name)
You’re missing a space between your ID selectors and your class selectors.
#topmostheader.inner means “select the element with an id of topmostheader and a class of inner”.
You want #topmostheader .inner, which means “select elements with a class of inner that are descendants of the element with an id of topmostheader“
you need to put a space between the id #topmostheader and the class e.g. .acceleration-logo otherwise the browser assumes you are applying style to div with id #topmostheader and class .acceleration-logo not a child of class .acceleration-logo with parent of #topmostheader

Resources