Active color with CSS3 & HTML - html

I'm suffering to active color on my template, I have used this template http://codepen.io/suez/pen/XJGOyL
How can I active menu, like when I clicked another menu not active. how to do this?
This is my code:
//HTML
<div class="demo__content">
<h2 class="demo__heading">What do you need help with?</h2>
<div class="demo__elems">
<div class="demo__elem demo__elem-1">With advertising online</div>
<div class="demo__elem demo__elem-2">With a website</div>
<div class="demo__elem demo__elem-3">I need help with both</div>
<span class="demo__hover demo__hover-1"></span>
<span class="demo__hover demo__hover-2"></span>
<span class="demo__hover demo__hover-3"></span>
<div class="demo__highlighter">
<div class="demo__elems">
<div class="demo__elem">With advertising online</div>
<div class="demo__elem">With a website</div>
<div class="demo__elem">I need help with both</div>
</div>
</div>
</div>
//CSS
.demo__hover-2 {
top: 7rem;
}
.demo__hover-2:hover ~ .demo__highlighter {
-webkit-transform: translateY(7rem);
transform: translateY(7rem);
}
.demo__hover-2:hover ~ .demo__highlighter .demo__elems {
-webkit-transform: translateY(-7rem);
transform: translateY(-7rem);
}
.demo__hover-3 {
top: 14rem;
}
.demo__hover-3:hover ~ .demo__highlighter {
-webkit-transform: translateY(14rem);
transform: translateY(14rem);
}
.demo__hover-3:hover ~ .demo__highlighter .demo__elems {
-webkit-transform: translateY(-14rem);
transform: translateY(-14rem);
}
.demo__elem a:active, a:hover, a:focus {
text-decoration: none;
outline: none;
}

If you are able to use jQuery in you code you can do it by adding "active" class to selected element of your menu.
For instance
$(".demo__elem").click(function() {
$(".demo__elem").removeClass("active"); // remove active from all
$(this).addClass("active"); // add active to this
});
and you "active" css should be styled as well.

If you're wanting to click a link, go to that page, and have that link retain the active state once you're on that page, you'll need to do one of three things.
Using HTML and CSS only, every page can be built completely and individually. This is called a static website. The menu will live on each page, and the link for the page you're on will need a unique ID (usually class="active") in order to set it apart as the active link. Using CSS, you can style to appear how you want.
You can use javascript to dynamically detect the page you're on, usually by reading your URL, and apply the active state to the appropriate link.
You can use a server side codding language such as PHP, ASP, RUBY, etc., and set your menus to dynamically detect which page you're on based on internal/server side code and apply the active state to the menu. This is a very clean, and once you get the hang of the language you choose, it's a very easy and effective method. This is the most popular choice by developers and is called a dynamic website.
In each case, you'll still use CSS the exact same way to style the active link.

Related

Highlight clicked/tapped element in Ionic Framework

I'm working with Ionic Framework. How could I show background-color change or similar when an item is tapped on mobile? All the states (active, focus etc) below are not displaying if you just tap the item, but will show if you hold down your finger. This is not wanted behaviour as it doesn't really indicate to the user that he/she has tapped an element and something should happen (ie. view should change/is about to change).
CSS:
.item-thumbnail-right {
background-color: #FFFFFF;
}
.item-thumbnail-right:active,
.item-thumbnail-right:focus,
.item-thumbnail-right.active {
background-color: #CCCCCC;
}
HTML:
<div class="item item-thumbnail-right">
<div class="img-wrapper">
<div class="img" src="img.jpg"></div>
</div>
<h2 class="title">Title</h2>
<p>Text lorem ipsum...</p>
</div>
Should I use Ionics on-tap directive to add a class and show the different background-color accordingly? I should then probably also remove the class at some point if it stays in the view cache.
It seems like I had the active class wrong. Ionic adds a class activated in the item clicked/tapped so what I was trying works, but the class needs to be activated like this:
.item-thumbnail-right {
background-color: #FFFFFF;
}
.item-thumbnail-right.activated {
background-color: #CCCCCC;
}

Using CSS to Highlight Current Page

I want to highlight current page by using CSS, but somehow it doesn't work. Please take a look at my code below.
HTML
<body id="home">
<div id="mainNav">
<a href="/Dashboard/Index" id="navIndex">
<div class="circle text-uppercase">
<div class="icon23X27"><img src="~/Content/icons/dashBoard.png" width="23px" height="27px" align="middle" /></div><span class="textStyle">Dashboard</span>
</div>
</a>
<a href="/samples/register/" id="navRegister">
<div class="circle text-uppercase">
<div class="icon23X27"><img src="~/Content/icons/samples.png" width="23px" height="27px" align="middle" /></div><span class="textStyle">Sample Registration</span>
</div> </a>
<a href="/samples/search/">
.........
</div>
CSS
body#/samples/register a#navRegister .textStyle {
background-color:red !important
}
The syntax is wrong. Use this way:
body a#navRegister[href="/samples/register"] .textStyle {
background-color:red !important
}
Yours is a worst example of having div inside <a>, which is similar to having a bottle inside some water, not water inside bottle, which is right one.
Take your body ID, in this case #home and combine it with the id on the home nave element, in this case #navIndex:
#home #navIndex .textStyle {
background-color: red;
}
Then you can add a selector for each of your pages to catch the current page in the nav with css alone:
#home #navIndex .textStyle,
#register #navRegister .textStyle {
background-color: red;
}
Drop the !important it's only necessary in a couple of edge cases in css and should be avoided (I appreciate one of those edge cases is just trying to definitely make a selector show some visible effect, which may well be what you're doing with the posted css).
You'd also benefit from using classes instead of ids as css selectors.
Caveat:
It's probably better to render this in the html server side as the server can use the request URL to decide which nav item is current. That way you can just add a selected-nav-text class to your current nav span and your css becomes:
.selected-nav-text {
background-color: red;
}
This is simpler, you can write logic once server side to calculate the current nav and css once to highlight it, then when you change your nav the functionality will come instantly.

How to keep :active css style after click a button

Once the button is clicked I want it to stay with the active style instead of going back to normal style. Can this be done with CSS please? Im using blurb button from DIVI Theme (WordPress). Please help me!
code:
#blurb-hover.et_pb_blurb .et_pb_blurb_content
.et_pb_main_blurb_image .et-pb-icon:hover {
color: red !important; }
#blurb-hover.et_pb_blurb .et_pb_blurb_content
.et_pb_main_blurb_image .et-pb-icon:selected {
background-color: #ff4b46;
color: #fff; }
#blurb-hover.et_pb_blurb .et_pb_blurb_content
.et_pb_main_blurb_image .et-pb-icon:active {
color: white !important;
background-color: red;
width: 140px;
height: 100px; }
CSS
:active denotes the interaction state (so for a button will be applied during press), :focus may be a better choice here. However, the styling will be lost once another element gains focus.
The final potential alternative using CSS would be to use :target, assuming the items being clicked are setting routes (e.g. anchors) within the page- however this can be interrupted if you are using routing (e.g. Angular), however this doesnt seem the case here.
.active:active {
color: red;
}
.focus:focus {
color: red;
}
:target {
color: red;
}
<button class='active'>Active</button>
<button class='focus'>Focus</button>
<a href='#target1' id='target1' class='target'>Target 1</a>
<a href='#target2' id='target2' class='target'>Target 2</a>
<a href='#target3' id='target3' class='target'>Target 3</a>
Javascript / jQuery
As such, there is no way in CSS to absolutely toggle a styled state- if none of the above work for you, you will either need to combine with a change in your HTML (e.g. based on a checkbox) or programatically apply/remove a class using e.g. jQuery
$('button').on('click', function(){
$('button').removeClass('selected');
$(this).addClass('selected');
});
button.selected{
color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Item</button><button>Item</button><button>Item</button>
We're going to to be using a hidden checkbox.
This example includes one "on click - off click 'hover / active' state"
--
To make content itself clickable:
HTML
<input type="checkbox" id="activate-div">
<label for="activate-div">
<div class="my-div">
//MY DIV CONTENT
</div>
</label>
CSS
#activate-div{display:none}
.my-div{background-color:#FFF}
#activate-div:checked ~ label
.my-div{background-color:#000}
To make button change content:
HTML
<input type="checkbox" id="activate-div">
<div class="my-div">
//MY DIV CONTENT
</div>
<label for="activate-div">
//MY BUTTON STUFF
</label>
CSS
#activate-div{display:none}
.my-div{background-color:#FFF}
#activate-div:checked +
.my-div{background-color:#000}
Hope it helps!!
In the Divi Theme Documentation, it says that the theme comes with access to 'ePanel' which also has an 'Integration' section.
You should be able to add this code:
<script>
$( ".et-pb-icon" ).click(function() {
$( this ).toggleClass( "active" );
});
</script>
into the the box that says 'Add code to the head of your blog' under the 'Integration' tab, which should get the jQuery working.
Then, you should be able to style your class to what ever you need.

addclass on hover not working

I want to hover on an element (an imagemap area, actually but I made it a simple div for this example) and create an animation on a different div element. Since they're not child or sibilings I had to use java and addclass but it's not working. It looks like the trigger element is not recognized and if I hover it nothing happens
<div class="testHover">
<p>Hover me to change color</p>
</div>
<div id="timeLine">
<div id="primaGuerraMondiale">
<h2>Content</h2>
</div>
</div>
css
#primaGuerraMondiale {
background: green;
}
.animated {
color:white;
}
javascript
$('.testHover').hover(function() {
$('#primaGuerraMondiale').addClass('animated');
}, function() {
$('#primaGuerraMondiale').removeClass('animated');
});
Here is the fiddle https://jsfiddle.net/elisapessa/yzLe803n/
You need jQuery 1.9.1 and above to make it work. The code is right.
In the left hand panel in the jsfiddle, there is a section called "Add Resources". Click this, then add the URL into the field and click the + button. This will add your resource (JS or CSS) to the page. After that you click on run and check it:

CSS applying styles selectively

I am trying to create a editor page that allows you to preview HTML files.
The problem is however that the editors styles are being inherited by the previewed HTML file e.g.:
<div class="header">
<div class="top">
Editing HTML page - page1.html
</div>
</div>
<div class="preview">
<div class="header">
<div class="top">
Page 1.html
</div>
</div>
</div>
I know that a work around would be to use an IFRAME, however I would prefer not to do this as I will be allowing drag and drop capabilities.
A CSS solution would be great, I did have the idea of using jquery to add a class to every item in the 'preview' area and using the following CSS for the editor page:
.header:not(.preview) {
background-color:#000;
}
.top:not(.preview) {
color: #fff;
}
This however seems a bit of a hacky solution and it would be great if there was a neater solution!
If you ultimately need to use not, you should invert your selectors:
:not(.preview) > .header { background-color:#000; }
:not(.preview) > .header .top { color: #fff; }
But it's better to design selectors in some other way