highlight a div linked to the current page - html

I'd like the buttons (moon, planets, etc...) staying red when we are on the current page.
Link to my site: http://www.chooseyourtelescope.com/moon-telescope/
Here, the "moon" button should be red.
Here is the code:
HTML
<div class="top-logos"><img src="" alt="LUNE"></div>
<div class="top-logos"><img src="" alt="PLANETES"></div>
<div class="top-logos"><img src="" alt="CIEL PROFOND"></div>
<div class="top-logos"><img src="" alt="SOLEIL"></div>
<div class="top-logos"><img src="" alt="TELESCOPE POLYVALENT"></div>
CSS
.top-logos {
width:20%;
top:108px;
padding:5px;
position: relative;
text-align:center;
float: left;
background:#0e0e18
}
.top-logos:hover {
background:#dd0000;
}
.top-logos:active {
background:#dd0000;
}
I don't know anything about Javascript but I can use it if you tell me what to do. Also I've JQuery installed.

You already have the class current-logo on the appropriate element. Just style that:
.current-logo div.top-logos {
background-color: #dd0000;
}

It looks like you already have this set up on your site with the .current-logo class on the anchor tags.
In your CSS file, all you need to do is
.current-logo div {
background-color: #dd0000;
}
You need to make sure that the .current-logo class changes based on what page you are on.
It looks like you're using Wordpress so the best way to do it would be to use the built-in menu functionality. You need a register your menu in functions.php and it will automatically update based on the pages you have for your site. You can read about that here.
Per your comment about it being in a file called base.php, you could do something like this in base.php:
<a href=".../moon-telescope/" <?php if (is_page('moon-telescope')): echo 'class="current-logo"'; endif; ?> >
<div></div>
</a>
<a href=".../planets/" <?php if (is_page('planets')): echo 'class="current-logo"'; endif; ?> >
<div></div>
</a>
Change to match your pages.

Related

How will i create a link in my menu that point to that same page

How will i create a link in my menu that point to that same page . like what happend in this site http://nightswatch.afrcreative.com/ the about us is still in the same page not another page
This is acheived using anchor tags.
Refer here
You need to use anchor tags like so:
.tall {
height: 600px;
background: cyan;
}
.about {
height: 500px;
}
<div class="tall">
About
</div>
<div class="about">
<a name="about" />
<h1>About</h1>
</div>
You can then get fancy and intercept this with js to smoothly animate or use the scroll-behavior css property.

Where to set a tag on banner with a text container [duplicate]

This may seem pretty basic, are you allowed to put a link inside of a link? See attached image below:
I'm trying to have the whole grey bar clickable to go somewhere, but if the user clicks the wheel or the move arrow, they are other links. See my current code:
<a href="#" class="sp_mngt_bar">
<h1><?php echo $v; ?></h1>
</a>
Is this a good practice? Am I doing it wrong? How would you do this?
Thanks for the help!
Straight from the W3C for HTML4:
12.2.2 Nested links are illegal
Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements.
Since the DTD defines the LINK element to be empty, LINK elements may not be nested either.
HTML 5
And for HTML5 it is a little different.
You cannot have Interactive Content inside an A element. Interactive Content includes anchor tags.
To simply answer the question: No.
That being said, here's a pure html/css workaround:
https://codepen.io/pwkip/pen/oGMZjb
.block {
position:relative;
}
.block .overlay {
position:absolute;
left:0; top:0; bottom:0; right:0;
}
.block .inner {
position:relative;
pointer-events: none;
z-index: 1;
}
.block .inner a {
pointer-events: all;
}
<div class="block">
<a class="overlay" href="#overlay-link"></a>
<div class="inner">
This entire box is a hyperlink. (Kind of)<br><br><br><br>
I'm a W3C compliant hyperlink inside that box
</div>
</div>
Wrap your nested link inside an object tag :
<a href="#" class="sp_mngt_bar">
<h1><?php echo $v; ?></h1>
<object></object>
<object></object>
</a>
Although I totally agree with the selected answer and yes, you shouldn't have Interactive Content inside an A element, sometimes you may need a workaround to this.
Here's an example where you need to put an interactive element inside an A tag. That little close button on the top right.
Here's the HTML for this. (It's not the actual build, I made it a bit simpler)
<a href="#">
<span class="hide">X</span> <!-- THIS IS THE SMALL 'X' WHICH HIDES THE WHOLE BOX -->
<img src="images/camera.svg" width="50" alt="Camera" />
<em>
Upload a profile picture
<small>
Here's the deal. Make your profile look awesome and even get 25 karma for it. We're not kidding.
</small>
</em>
<strong>
+ 25 K
</strong>
</a>
So, basically we want to hide this box when the user clicks on the 'X'. Otherwise, just it should work like a simple A tag. Here's the jQuery which did the trick.
$('.hide').click(function(e) {
e.preventDefault();
e.stopPropagation(); // THIS IS THE KEY PART
// DO WHATEVER YOU WANT, I FADED OUT THE BOX FOR EXAMPLE
$(this).parent().fadeOut(300);
});
I hope this helps someone with the same problem. ;)
I would restyle it so that it is more like this format:
<div class="sp_mngt_bar">
<h1><a href="#"<?php echo $v; ?></a></h1>
</a>
Nested links are illegal. To achieve the same behavior as with nested links you can do the following:
Use #mikevoermans HTML format as shown below and bind click event
<div class="sp_mngt_bar">
<h1><a href="#"<?php echo $v; ?></a></h1>
</div>
Your click event should look like this:
$(".sp_mngt_bar").bind("click", function(e) {
var target = $(e.target);
if(target.has('.t_icons_settings') { //Do something for settings }
else if(target.has('.t_icons_move') { //Do something for move }
else { //Do something for sp_mngt_bar
});
While technically not an answer to the question, another workaround is to bind the click event to a span or div:
<a href="outer-link">
Outer Link
<span class='inner-link'>Inner Link</span>
</a>
$('.inner-link').click(function (e) {
// Prevent the click-through to the underlying anchor
e.stopPropagation();
// Go to a link
window.location.href = 'page.html';
// Or call a javascript method
doSomething();
return false;
});
One solution is to position a link absolutely inside of the parent link container:
<div style="position: relative">
<a href="#">
<h1><a href="#"<?php echo $v; ?></a></h1>
<div id="placeholder" style="height: 24px">
</a>
<div style="position: absolute; bottom: 0">
</div>
</div>
#Jules answer, just shorter:
.parent {
position:relative;
}
.overlay-link {
position:absolute;
inset: 0;
}
html:
<div class="parent">
<a class="overlay-link" href="..."/>
<div class="child">
</div>
</div>

Show elements on hover with CSS

I want to show 2 elements (one div, inside it one buttom) when I hover an image. I got some problems: It didn't works!
My HTML code:
<div class="discord-container">
<center>
<img src="https://i.imgur.com/7K3OLPH.png", class="discord-image", width="75"/>
<div class="discord-poupup" id="poupup-element">
<button onClick="discord.logout()" class="logout-button" id="poupup-element">LOGOUT</button>
</div>
</center>
</div>
On CSS:
.discord-image {
border: solid #7289DA;
border-radius: 100px;
}
img.discord-image:hover + div#poupup-element:hover {
display:block;
}
#poupup-element{
display: none;
}
The 'discord-poupup' class on div just change background colors and positions, it don't touch on display.
Well, I want to show everything with id 'poupup-element' when I hover the image with class 'discord-image' (and preferably keep it showing while the mouse cursor is hoving it AND its already active). I tried lots of things, but nothing works :c Can someone help-me?
(I'm also using Shiny (from R lang). If there is an easier way to do what I want please tell-me)
Like others already mentioned, 'id' should be unique. You could try giving your div and button a class called "poupup-element".
Also, you have commas in your img tag that should not be there.
HTML
<div class="discord-container">
<center>
<img src="https://i.imgur.com/7K3OLPH.png" class="discord-image" width="75"/>
<div class="discord-poupup poupup-element">
<button onClick="discord.logout()" class="logout-button poupup-element">LOGOUT</button>
</div>
</center>
</div>
.discord-image {
border: solid #7289DA;
border-radius: 100px;
}
.poupup-element{
display: none;
}
img.discord-image:hover .poupup-element {
display:block;
}
I guess there was an issue with your HTML. You should not have two same ID's. Also you should not put commas in your HTML tags.
here's the solution
css:
#poupup-element{
display:none;
}
.discord-image:hover + #poupup-element{
display:block;
}
Edit:
html
<div class="discord-container">
<center>
<img src="https://i.imgur.com/7K3OLPH.png" class="discord-image" width="75" />
<div class="discord-poupup" id="poupup-element">
<button onClick="discord.logout()" class="logout-button" >LOGOUT</button>
</div>
</center>
</div>

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

Are you allowed to nest a link inside of a link?

This may seem pretty basic, are you allowed to put a link inside of a link? See attached image below:
I'm trying to have the whole grey bar clickable to go somewhere, but if the user clicks the wheel or the move arrow, they are other links. See my current code:
<a href="#" class="sp_mngt_bar">
<h1><?php echo $v; ?></h1>
</a>
Is this a good practice? Am I doing it wrong? How would you do this?
Thanks for the help!
Straight from the W3C for HTML4:
12.2.2 Nested links are illegal
Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements.
Since the DTD defines the LINK element to be empty, LINK elements may not be nested either.
HTML 5
And for HTML5 it is a little different.
You cannot have Interactive Content inside an A element. Interactive Content includes anchor tags.
To simply answer the question: No.
That being said, here's a pure html/css workaround:
https://codepen.io/pwkip/pen/oGMZjb
.block {
position:relative;
}
.block .overlay {
position:absolute;
left:0; top:0; bottom:0; right:0;
}
.block .inner {
position:relative;
pointer-events: none;
z-index: 1;
}
.block .inner a {
pointer-events: all;
}
<div class="block">
<a class="overlay" href="#overlay-link"></a>
<div class="inner">
This entire box is a hyperlink. (Kind of)<br><br><br><br>
I'm a W3C compliant hyperlink inside that box
</div>
</div>
Wrap your nested link inside an object tag :
<a href="#" class="sp_mngt_bar">
<h1><?php echo $v; ?></h1>
<object></object>
<object></object>
</a>
Although I totally agree with the selected answer and yes, you shouldn't have Interactive Content inside an A element, sometimes you may need a workaround to this.
Here's an example where you need to put an interactive element inside an A tag. That little close button on the top right.
Here's the HTML for this. (It's not the actual build, I made it a bit simpler)
<a href="#">
<span class="hide">X</span> <!-- THIS IS THE SMALL 'X' WHICH HIDES THE WHOLE BOX -->
<img src="images/camera.svg" width="50" alt="Camera" />
<em>
Upload a profile picture
<small>
Here's the deal. Make your profile look awesome and even get 25 karma for it. We're not kidding.
</small>
</em>
<strong>
+ 25 K
</strong>
</a>
So, basically we want to hide this box when the user clicks on the 'X'. Otherwise, just it should work like a simple A tag. Here's the jQuery which did the trick.
$('.hide').click(function(e) {
e.preventDefault();
e.stopPropagation(); // THIS IS THE KEY PART
// DO WHATEVER YOU WANT, I FADED OUT THE BOX FOR EXAMPLE
$(this).parent().fadeOut(300);
});
I hope this helps someone with the same problem. ;)
I would restyle it so that it is more like this format:
<div class="sp_mngt_bar">
<h1><a href="#"<?php echo $v; ?></a></h1>
</a>
Nested links are illegal. To achieve the same behavior as with nested links you can do the following:
Use #mikevoermans HTML format as shown below and bind click event
<div class="sp_mngt_bar">
<h1><a href="#"<?php echo $v; ?></a></h1>
</div>
Your click event should look like this:
$(".sp_mngt_bar").bind("click", function(e) {
var target = $(e.target);
if(target.has('.t_icons_settings') { //Do something for settings }
else if(target.has('.t_icons_move') { //Do something for move }
else { //Do something for sp_mngt_bar
});
While technically not an answer to the question, another workaround is to bind the click event to a span or div:
<a href="outer-link">
Outer Link
<span class='inner-link'>Inner Link</span>
</a>
$('.inner-link').click(function (e) {
// Prevent the click-through to the underlying anchor
e.stopPropagation();
// Go to a link
window.location.href = 'page.html';
// Or call a javascript method
doSomething();
return false;
});
One solution is to position a link absolutely inside of the parent link container:
<div style="position: relative">
<a href="#">
<h1><a href="#"<?php echo $v; ?></a></h1>
<div id="placeholder" style="height: 24px">
</a>
<div style="position: absolute; bottom: 0">
</div>
</div>
#Jules answer, just shorter:
.parent {
position:relative;
}
.overlay-link {
position:absolute;
inset: 0;
}
html:
<div class="parent">
<a class="overlay-link" href="..."/>
<div class="child">
</div>
</div>