targeting different div styles with target method - html

Hello I am using the target method to manipulate different div styles, for the first "link_one" everything is working, while I have only one link, the question is how to make it work for "link_two" ? So link_two will do the second part of the css ? What is more important here is that each link is maniluplating 2 different classes in which link one and two one of the class is the same.
link_one
<div id="sections">
<div id="link_one">info</div>
<div id="link_two">info</div>
</div>
/* link one code */
#sections:target #link_one{
height:90px;
background:#333;
transition:all 1s ease;
}
#sections:target .rslides {
height:0px;
transition:all 1s ease;
}
/* link two code */
#sections:target #link_two{
height:90px;
background:#333;
transition:all 1s ease;
}
#sections:target .rslides {
height:0px;
transition:all 1s ease;
}

One way to apply the target selector would be:
for this HTML
link_one
<br>
link_two
<div id="sections1"></div>
<div id="sections2"></div>
<div id="link_one" class="link">info</div>
<div id="link_two" class="link">info</div>
Set this CSS
.link {
height: 20px;
transition:all 1s ease;
}
#sections1:target ~ #link_one{
height:90px;
background:#333;
}
#sections2:target ~ #link_two{
height:90px;
background:#333;
}
fiddle

Related

Sidebar width could not adjust

I'm trying to do a sidebar for my html page. But i could not adjust the width of the sidebar. Also the menu icon when click should be closing/open the sidebar but it does not work.
Im a new learner , please help.
My code at here!
#sidebar {
background:#151719;
height:1000px;
width:20%; <!--- Cannot adjust width --->
position:absolute;
left:-248px; <!--- this will let the sidebar disapper --->
transition:all .3 ease-in-out;
-webkit-transition:all .3 ease-in-out;
-moz-transition:all .3 ease-in-out;
-ms-transition:all .3 ease-in-out;
-o-transition:all .3 ease-in-out;
}
You are close, but comment separators should be /*..*/, not <!---..--->. CSS is not HTML. Those comments prevent the CSS from being parsed correctly.
Then there is a #sidebar {width: 100%; halfway down, which overrides the width:248%; on the top.
And finally, the selector for moving the sidebar on selecting the checkbox should be #menuToggle:checked ~ #sidebar. Yours did nothing.
If you correct those errors, the page works flawlessly.
*{padding:0px;
margin:0px;
font-family:sans-serif;}
#sidebar{
background:#151719;
height:1000px;
width:248px; /* Cannot adjust width */
position:absolute;
left:-248px; /* this will let the sidebar disapper */
transition:all .3 ease-in-out;
-webkit-transition:all .3 ease-in-out;
-moz-transition:all .3 ease-in-out;
-ms-transition:all .3 ease-in-out;
-o-transition:all .3 ease-in-out;
}
#sidebar .menu li{
list-style-type:none;}
#sidebar .menu a{
text-decoration:none;
color:rgba(230,230,230,0.9);
display:block;
padding:15px 0;
border-bottom:1px solid rgba(100,100,100,0.45);}
#header{
width:100%;
height:5%;
margin:auto;
border-bottom:1px solid #EEE;}
#header .brand{
float:left;
line-height:50px;
color:#151719;
font-size:30px;
font-weight:bold;
padding-left:20px;}
#sidebar{
/* width:100%; */ /* removed because this would override the 248px above */
text-align:center;}
#sidebar .menu li:last-child a{border-bottom:none;}
#sidebar a:hover{
background:grey;
color:black;}
.menu-icon{
margin:2.5px 5px 0px 0px;
padding:10px 15px;
border-radius:5px;
background:#151719;
color:rgba(230,230,230,0.9);
cursor:pointer;
float:right;}
#menuToggle:checked ~ #sidebar {
position:absolute;
left:0;} /* Not sure is it correct or not, by clicking the checkbox, the sidebar should be displayed nicely, back to original */
<input type="checkbox" id="menuToggle" style="display:none;">
<label for="menuToggle" class="menu-icon">☰</label>
<div id="header">
<div class="brand">Cinema</div>
</div>
<div id="sidebar">
<ul class="menu">
<li>Dashboard</li>
<li>Help Center</li>
<li>Summary</li>
<li>Customer Interface</li>
</ul>
</div>
you can set width like this :
width: 20vw;
left: 0; // left: -20vw;
Your styles are applied to the #menuToggle item. Therefore the sidebar never hears about this change.
#menuToggle:checked {
position:absolute;
left:0;
}
Also because both elements do not have HTML relations, a CSS workaround might be risky. It's important to mention the selector #menuItem ~ #sidebar which will select #sidebars that precede #menuItem.
#menuToggle:checked ~ #sidebar {
position:absolute;
left:0;
}
Although it is definitely more prone to break in the future when the website has more content.
I suggest you have an event listener on the checkbox to toggle a class on the sidebar element. This can be done like so:
document.getElementById('menuItem').addEventListener('change', function(e) {
let sidebar = document.getElementById('sidebar');
this.checked ?
sidebar.classList.add('active') :
sidebat.classList.remove('active');
});

Transition effect in height of a div

My current situation:
http://jsfiddle.net/VOXRAZR/2a6r4/2/
My current problem:
Height of the div doesn't have transition effect and the outer div's height increases on hover (i dont want that!)
HTML
<div id="black_bar"></div>
<div id="top_nav">
<div class="menu" id="home">HOME</div>
<div class="menu">LIST OF CAR MANUFACTURERS</div>
<div class="menu">WHY USE CARZPEDIA?</div>
<div class="menu">ABOUT US</div>
<div class="menu">CONTACT US</div>
</div>
CSS
body{
margin:0;
}
#top_nav{
background-color:#000;
height:auto;
}
#top_nav a{
text-decoration:none;
color:#FFF;
font-family:Arial, Helvetica, sans-serif;
}
.menu{
display:inline-block;
padding:1em;
font-size:1em;
}
.menu:hover{
background-color:#09F;
border-bottom-left-radius:2em;
border-bottom-right-radius:2em;
height:3em;
-webkit-transition:all 500ms ease;
-moz-transition:all 500ms ease;
-ms-transition:all 500ms ease;
-o-transition:all 500ms ease;
transition:all 500ms ease;
}
#home{
color:#09F;
}
#home:hover{
color:#FFF;
}
Simply set a fixed height for the top bar (this is #top_nav in your CSS), and (optionally) set overflow:hidden; on it too (or the content will pop out when you hover over it. don't know if this is intentional)
See this fiddle with overflow hidden
Or this one with overflow visible

Slide out label with css3 transitions

I have the following codepen, this is a basic positioned label with the number and marker text:
<span href="#" class="part-marker">
1<span> marker text</span>
</span>
How can I get it to slide out on hover using css3 transitions? I've tried using this with no success??
See below a simplified version- the crux here being that you cant make a transition on properties that don't scale, so where you have the element going from display:none t inline-block it simply goes from hidden to shown as there are no intermediary points. What you can do instead is use a combination of max-width and overflow as outlined below.
Demo Fiddle
HTML
<div> <a href='#'>1</a>
<span>Label</span>
</div>
CSS
a {
display:inline-block;
background:blue;
color:white;
padding:0 5px;
}
div {
position:relative;
}
div span {
position:absolute;
display:inline-block;
max-width:0;
overflow:hidden;
transition:all 1s ease-in;
}
a:hover+span {
max-width:100%;
}
Take a look at this code:
HTML
<a href="#" class="marker-label" text="marker text">
1
</a>
CSS
.marker-label {
display:block;
background:blue;
color:white;
padding:4px 8px;
font-size:1em;
line-height:1;
position:relative;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
width:10px;
}
.marker-label:hover {
width:80px;
}
.marker-label:after {
content:attr(text);
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
position:absolute;
left:-100px;
}
.marker-label:hover:after {
left:20px;
}
And here is a FIDDLE
You can use a negative text-indent too : http://codepen.io/anon/pen/xalDc/
span {
text-indent:-150px;
overflow:hidden;
display:inline-block;/* triggers layout */
transition: all 1s ease-in-out;
/* position:absolute ; not needed since a is already so */
}
&:hover {
span {
text-indent:0;
}
}

Sibling Selector (tilde) Issue

I'm trying to modify named elements in my design. I've simplified the situation as you can see in this fiddle:
http://jsfiddle.net/6THpF/
Simply, when I try to modify one named element from the other, it works, but when I try to do the same modification from the opposite direction (other element) it does not work.
Here is the sample code:
body{
background-color:lightgrey;
}
#div_one, #div_two{
background-color:darkred;
display:block;
width:300px;
text-align:center;
padding:30px;
margin:10px;
color:white;
-webkit-transition: 0.3s ease;
-moz-transition: 0.3s ease;
-ms-transition: 0.3s ease;
-o-transition: 0.3s ease;
transition: 0.3s ease;
}
#div_one:hover ~ #div_two{
background-color:red;
}
#div_two:hover ~ #div_one{
background-color:red;
}
From MDN:
The ~ combinator separates two selectors and matches the second
element only if it is preceded by the first, and both share a common
parent.
So since div_one is not preceded by div_two the second rule won't work. In other words, there is no "previous sibling" selector.
Try this.I answered:
HTML:
<div id="div_one">This is div 1</div>
<div id="div_two">This is div 2</div>
CSS:
body{
background-color:lightgrey;
}
#div_one, #div_two{
background-color:darkred;
display:block;
width:300px;
text-align:center;
padding:30px;
margin:10px;
color:white;
-webkit-transition: 0.3s ease;
-moz-transition: 0.3s ease;
-ms-transition: 0.3s ease;
-o-transition: 0.3s ease;
transition: 0.3s ease;
}
JAVASCRIPT:
$(document).ready(function(){
$("#div_one").mouseover(function(){
$("#div_two").css("backgroundColor","blue");
});
$("#div_one").mouseout(function(){
$("#div_two").css("backgroundColor","darkred");
});
$("#div_two").mouseover(function(){
$("#div_one").css("backgroundColor","blue");
});
$("#div_two").mouseout(function(){
$("#div_one").css("backgroundColor","darkred");
});
});
remember that use and embed the jquery.js core to your web page.
I am not solving the sibling selector issue (that I think that can not be solved), but the effect intended.
You need to group both divs in one:
<div>
<div id="div_one">This is div 1</div>
<div id="div_two">This is div 2</div>
</div>
and now target the hover state of the group div:
div:hover #div_two{
background-color:red;
}
div:hover #div_one{
background-color:red;
}
of course the later can be written better, (or shorter) I just wanted to change as little as possible in your example
This has some drawbacks that you may be will need to address.
If you want the divs to have space between them (and this space not responsive to the hover), then I think that you will need to change them to absolute positioning.
see the fiddle
edited
I missed the requirement about not hovering the hovered div. Change css to
div:hover #div_two:not(:hover){
background-color:red;
}
div:hover #div_one:not(:hover){
background-color:red;
}
Now I think it's what you wanted edited fiddle

CSS Transitions - not working after changing size of element

Background
I'm customising a tumblr theme (Source: hasaportfolio), and I am trying to change the size of one particular element.
This element, on :hover, is meant to transition opacity - "fade in". What is happening, however, is that once I change the pixel sizes the transitions refuse to work, and the newly appearing content does not appear at all.
HTML Code
The HTML code this is being applied to is as follows. I've commented it as well as I can.
<div class="post video featured"> <!-- wrapper, no css attached -->
<div class="box-featured">
<iframe src="http://player.vimeo.com/video/30284533" width="750" height="430" frameborder="0"></iframe>
<div class="box-caption-text-featured"> <!-- this div and content is "hidden" (0% opacity) until :hover -->
<h1>Paint</h1>
<p>I hate yogurt. It's just stuff with bits in.</p>
<p>You know how I sometimes have really brilliant ideas? You've swallowed a planet!</p>
</div><!-- box-caption-text-featured -->
# <!-- this a is the "trigger" for the transition. Normally it would link to the post permalink -->
</div><!-- box-featured -->
</div><!-- post -->
I also have another copy of this code, the only difference is that it is without the -featured at the end of each class definition. This is so I can see if the code works at its 'original' size (which it does).
CSS Code
The original code for running these boxes follows:
.box { float:left; width:250px; height:130px; overflow:hidden; margin:5px; position:relative; background-color:#F7F5F5; vertical-align:middle; padding:-5px 0 0 0; }
.box-caption, { width:220px; height:130px; overflow:hidden; position:absolute; left:0px; top:0px; z-index:99; background-color:transparent; filter:alpha(opacity-0); opacity:0; display:inline-block; padding:0px 15px; text-indent:-2000px; }
.box-caption-text { color:#fff; width:220px; height:130px; overflow:hidden; position:absolute; left:0px; top:0px; z-index:95; font-size:12px; line-height:16px; background-color:transparent; filter:alpha(opacity=0); padding:0px 15px; opacity:0; display:inline-block; -webkit-transition: opacity .25s ease-in-out; -moz-transition: opacity .25s ease-in-out; -o-transition: opacity .25s ease-in-out; transition: opacity .25s ease-in-out; }
.box:hover .box-caption { display:inline-block; background-color:transparent; }
.box:hover .box-caption-text { opacity:.85; filter:alpha(opacity=85); background-color:#ff9711; }
My changed code is as follows. The only things I have changed are the width and height pixel values.
.box-featured { float:left; width:750px; height:430px; overflow:hidden; margin:5px; position:relative; background-color:#F7F5F5; vertical-align:middle; padding:-5px 0 0 0; }
.box-caption-featured { width:750px; height:430px; overflow:hidden; position:absolute; left:0px; top:0px; z-index:99; background-color:#f00; filter:alpha(opacity-0); opacity:0; display:inline-block; padding:0px 15px; text-indent:-2000px; }
.box-caption-text-featured { color:#fff; width:750px; height:430px; overflow:hidden; position:absolute; left:0px; top:0px; z-index:95; font-size:12px; line-height:16px; background-color:transparent; filter:alpha(opacity=0); padding:0px 15px; opacity:0; display:inline-block; -webkit-transition: opacity .25s ease-in-out; -moz-transition: opacity .25s ease-in-out; -o-transition: opacity .25s ease-in-out; transition: opacity .25s ease-in-out; }
.box:hover .box-caption-featured { display:inline-block; background-color:transparent; }
.box:hover .box-caption-text-featured { opacity:.85; filter:alpha(opacity=85); background-color:#ff9711; }
Have I just missed something dumb, or is there an issue in this code that prevents what I'm trying to do?
Example Page
There's an example of what I'm taking about over here.
What i'm thinking at this point is that you need to change it to:
.box-featured:hover