1. How to make the navigation bar look like the left side of http://chuangzaoshi.com/code?
2. Can it be fully realized using css? How to implement pure css? How to implement js?
Thanks!
ps: Thanks to the two masters for their answers. I didn’t make it clear. My questions are as follows:
左侧导航点击设计等大的标签会自动收起原来的,弹出现在的ul,同时右侧的内容又跟着变化。
I don’t know how to implement this, so I hope you can enlighten me.
Which effect are you referring to? :hover Reverse, nothing too complicated.
You have already given the example yourself, just open its code and compare it.
If you don’t understand a specific style or effect, you can ask for more details.
It’s too broad to directly ask how to implement the whole thing. It’s just like the example.
Have you given the implementation example? The css and js have been shown to you, so you can refer to them directly.
Based on your newly added question
You can see that every time you click on a large label, it actually jumps to another page. The ul under all large labels are closed by default.
Then according to the current page, you will find that the current large label will have an active class name, and the ul you want to open will follow it, so it is simple:
css method is
.active + ul { display:block; }
jquery method is
$('.active').next('ul').css('display','block');
Other methods are similar. They all obtain the active activity tag and indicate the small tag list under it to display.
According to the example you gave, since it is not written in css, but inserted into the style attribute, it should be implemented using js.
Do you want the discoloration effect when you move the mouse over it?
If you use CSS to implement it, use a list on the left side, then change the style, use the
:hover
pseudo class to match the style of moving the mouse overFor example
If implemented with JS, it is necessary to monitor the mouse entry event of the corresponding element
onmouseenter
, set the styles of all items in the list to regular styles except the current item, and also listen to the mouse leave event of the elementonmouseleave
, when the mouse leaves, the style set when the mouse passes over needs to be restored to the regular style.Update
It is recommended that you describe the details of the problem clearly the first time you ask a question next time, otherwise the respondent's time will be wasted.
In response to the question you asked later,
The HTML layout on the left is probably like this
Then, move the mouse over the whitened one, as mentioned above.
If you click, add a CSS class to the clicked
<li>
, such as.active
, and then add the previous:hover
, the CSS is similar to this:Of course, since the current label and the mouseover style in this example are the same, you can combine
ul li:hover
andul li.active
to writeIn this way, you won’t be able to switch tabs. The HTML layout on the right side looks like this:
By default, CSS is used to display the first child
p
in#main
and hide the others. It is recommended to add the.active
class to p. The.active
class will be displayed, otherwise it will be hidden.Then, write JS events, but the native one is more painful to write. It is recommended to use jQuery to operate. Here are two examples of writing methods
Native:
If you use the jQuery library, it will be much simpler, as follows:
Conclusion
This explains so much, but I want to tell you a very devastating news. That is, the example website you gave may not do this at all. This website may have 4 pages and then jump to each other through links, and the label of the current page on each page is always lit. (I didn’t look at the source code carefully, but I didn’t know whether it was routing based on the different URL addresses, so I just said “possibly”).