简体   繁体   English

CSS3目标选择器问题

[英]CSS3 Target Selector Issue

I am teaching myself JS/HTML5/CSS3 by studying, combining and modifying 3 code examples by 3 different authors. 我通过学习,组合和修改3位不同作者的3个代码示例来自学JS / HTML5 / CSS3。 My working Pen (which include references to the original authors) can be found here 我的工作笔(包括对原始作者的引用)可以在这里找到

http://codepen.io/Widgeteria/pen/jqpyYb http://codepen.io/Widgeteria/pen/jqpyYb

My question is how do I make the time element invisible in the narrow blue vertical Task Clock partition or section (after starting the stop watch by clicking on the start button) when you click to either the Dropzone or Notes partitions. 我的问题是,当您单击Dropzone或Notes分区时,如何使时间元素在狭窄的蓝色垂直Task Clock分区或分区(单击开始按钮启动秒表后)中不可见。

I am tried various ways (including embedded CSS rules) but cannot make the faint clock numerals disappear from the vertical section box after I click on another section. 我尝试了多种方法(包括嵌入式CSS规则),但是单击另一部分后,无法使微弱的时钟数字从垂直部分框中消失。

Here is how the clock is set up: 时钟的设置方法如下:

<h1><time>00:00:00</time></h1>
<button id="start">start</button>
<button id="stop">stop</button>
<button id="clear">clear</button>

I am trying to make the <time> tag invisible, when the target: shifts to a section other than Task Clock, and visible again when I click back. 当目标:移至“任务时钟”以外的部分时,我试图使<time>标记不可见,并在单击时再次显示。

The second problem I am having is trying to modify the JS so that the clock does not keep running if I click on the Start button twice. 我遇到的第二个问题是尝试修改JS,以便如果单击两次“开始”按钮,时钟将无法继续运行。

Any ideas on how to solve either problem would be much appreciated. 任何关于如何解决这两个问题的想法将不胜感激。

For the CSS part, you should change this 对于CSS部分,您应该对此进行更改

:target time {
  visibility: hidden;
}

and this 和这个

,time {
  visibility: visible;
}

to this: 对此:

:target #time {
  visibility: hidden;
}

and this 和这个

#time {
  visibility: visible;
}

Also, add an id="time" on the <h1> tag containing the <time> tag. 另外,在包含<time>标记的<h1>标记上添加id="time"
The problem was the :target thing. 问题是:target东西。 It works only with ids , not with tags per-se. 仅适用于id ,不适用于本身的标签。

For the Javascript part, you could modifiy the timer function to: 对于Javascript部分,您可以将timer函数修改为:

function timer() {
 if(t)
   clearTimeout(t);
 t = setTimeout(add, 1000);
}

This clears the timeout if it already runs, so you won't lose refferences to already initiated timeouts and you also won't have parallel timeouts running. 如果超时已经运行,它将清除超时,因此您不会丢失对已经启动的超时的引用,也不会并行运行超时。

Have a good one. 祝你有个好的一天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM