Home > Web Front-end > HTML Tutorial > CSS3 practical development: Pure CSS to implement image filtering, classification and display effects_html/css_WEB-ITnose

CSS3 practical development: Pure CSS to implement image filtering, classification and display effects_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:58:26
Original
1166 people have browsed it

Hello netizens, today I will lead you to develop a pure CSS image classification display URL navigation. You may be a little confused just by looking at the title. According to past practice, I will first demonstrate the actual operation effect for you:

From the above operation effect, it is not difficult to find that when I click on a menu, the navigation area will highlight the icons of this category accordingly, while other icons will dim .

Many people may say that this is so simple. You can quickly achieve the same effect by directly using front-end frameworks such as javascript or jQuery and some CSS. If you are one of these people, I also hope you will stop and read this tutorial. Because in today's tutorial, I will use another way of thinking to think about the problem. I will lead you to completely break away from js and how to achieve switching effects and image classification, aiming to teach you an idea.

Okay, no more nonsense, let’s start today’s practical development tutorial.

First, we define the html page. The code is as follows (for the convenience of demonstration, I directly imported the styles.css file. At this time, the file does not have any style content):

<!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <link rel="stylesheet" href="styles.css">        <title>CSS3实战开发:图片过滤分类特效</title>    </head>    <body>        <div class="container">        <div class="hot_navs">            <div class="hot_title">                <input id="selector-type-all" type="radio" name="title_set" class="selector-type-all" checked="checked" />                <label for="selector-type-all" class="label-type-all">全部类别</label>                                <input id="selector-type-1" type="radio" name="title_set" class="selector-type-1" />                <label for="selector-type-1" class="label-type-1">电子商务</label>                                <input id="selector-type-2" type="radio" name="title_set" class="selector-type-2" />                <label for="selector-type-2" class="label-type-2">旅游</label>                                <input id="selector-type-3" type="radio" name="title_set" class="selector-type-3" />                <label for="selector-type-3" class="label-type-3">社交</label>                                <input id="selector-type-4" type="radio" name="title_set" class="selector-type-4" />                <label for="selector-type-4" class="label-type-4">视频</label>                                <input id="selector-type-5" type="radio" name="title_set" class="selector-type-5" />                <label for="selector-type-5" class="label-type-5">新闻</label>                                <input id="selector-type-6" type="radio" name="title_set" class="selector-type-6" />                <label for="selector-type-6" class="label-type-6">信息门户</label>                                <input id="selector-type-7" type="radio" name="title_set" class="selector-type-7" />                <label for="selector-type-7" class="label-type-7">票务</label>                <div class="splitline"></div>                <a class="item-type-1" href="http://www.itdriver.cn">                    <img src="imgs/101.png"  />                </a>                <a class="item-type-1" href="http://www.itdriver.cn">                    <img src="imgs/102.png"  />                </a>                <a class="item-type-7" href="http://www.itdriver.cn">                        <i></i>                    <img src="imgs/103.png"  />                </a>                <a class="item-type-6" href="http://www.itdriver.cn">                        <img src="imgs/104.png"  />                </a>                <a class="item-type-5" href="http://www.itdriver.cn">                        <img src="imgs/105.png"  />                </a>                <a class="item-type-4" href="http://www.itdriver.cn">                    <img src="imgs/106.png"  />                </a>                <a class="item-type-3" href="http://www.itdriver.cn">                        <i></i>                    <img src="imgs/107.png"  />                </a>                <a class="item-type-4" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/108.png"  />                </a>                <a class="item-type-3" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/109.png"  />                </a>                <a class="item-type-3" href="http://www.itdriver.cn">                        <i></i>                    <img src="imgs/110.png"  />                </a>                <a class="item-type-6" href="http://www.itdriver.cn">                        <i></i>                    <img src="imgs/111.png"  />                </a>                <a class="item-type-6" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/112.png"  />                </a>                <a class="item-type-6" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/113.png"  />                </a>                <a class="item-type-6" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/114.png"  />                </a>                <a class="item-type-1" href="http://www.itdriver.cn">                        <i></i>                    <img src="imgs/115.png"  />                </a>                <a class="item-type-5" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/116.png"  />                </a>                <a class="item-type-6" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/117.png"  />                </a>                <a class="item-type-2" href="http://www.itdriver.cn">                    <i></i>                        <img src="imgs/118.png"  />                </a>            </div>        </div>    </div>        </body></html>
Copy after login

You will find from the above html code that my navigation menu uses label or radio tags. Why should I define them? Because I want to know which menu I currently clicked, because with CSS alone, we It seems that there is no way to know who is currently clicked, so when I click on the Label, a certain radio will be automatically selected.

At this point, let’s run the page to see how it works without adding any styles:

First, let’s adjust the size of the navigation area and add The border and style code are as follows:

*{ /*设置页面基本属性*/    margin:0;    padding:0;    font-size:14px;}.container{ /*调整外围容器布局*/    margin:200px auto;    width:1024px;}.hot_navs{ /*设置分类导航样式*/    border:1px solid #CCCCCC;    padding:.5em;    width:725px;}
Copy after login

The page effect at this time is as follows:

The size of the area has been determined, now we need to Set styles for the navigation menu, hide the radio buttons, and set the dividing line between the menu and the chart:

/*分割线*/.hot_navs .splitline { margin-bottom:4px;height:1px;border-top:1px dotted #999999; }.hot_navs a{ /*设置导航item的基本样式*/    text-decoration:none;    display:inline-block;    height:70px;    line-height:70px;    position:relative;    background:#FFE500;        -webkit-transition:all 0.6s; /*当item属性发生变化时,执行过度动画*/    -moz-transition:all 0.6s;    -o-transition:all 0.6s;    transition:all 0.6s;}.hot_navs input{display:none;}.hot_navs .label-type-all,.hot_navs .label-type-1,.hot_navs .label-type-2,.hot_navs .label-type-3,.hot_navs .label-type-4,.hot_navs .label-type-5,.hot_navs .label-type-6,.hot_navs .label-type-7 { /*设置区域头部导航菜单的基本样式*/    display:inline-block;    margin-top:10px;    padding:10px 10px;    cursor:pointer;}
Copy after login

The effect is as follows:

Careful netizens will find that I added the transition attribute to the above CSS style. This attribute mainly means that when any attribute of the menu changes, a transition animation is executed.

Next, we add the selected style to the navigation button, and also set the icon opacity of this category to 1 when a menu is selected, and the opacity of other categories to 0.2. The style code is as follows:

.hot_navs input.selector-type-all:checked ~ .label-type-all,.hot_navs input.selector-type-1:checked ~ .label-type-1,.hot_navs input.selector-type-2:checked ~ .label-type-2,.hot_navs input.selector-type-3:checked ~ .label-type-3,.hot_navs input.selector-type-4:checked ~ .label-type-4,.hot_navs input.selector-type-5:checked ~ .label-type-5,.hot_navs input.selector-type-6:checked ~ .label-type-6,.hot_navs input.selector-type-7:checked ~ .label-type-7 { /*设置选择某一菜单时,当前菜单的基本样式*/    font-weight:bold;    border-bottom:2px solid #FF9900;}.hot_navs input.selector-type-all:checked ~ a,.hot_navs input.selector-type-1:checked ~ a.item-type-1,.hot_navs input.selector-type-2:checked ~ a.item-type-2,.hot_navs input.selector-type-3:checked ~ a.item-type-3,.hot_navs input.selector-type-4:checked ~ a.item-type-4,.hot_navs input.selector-type-5:checked ~ a.item-type-5,.hot_navs input.selector-type-6:checked ~ a.item-type-6,.hot_navs input.selector-type-7:checked ~ a.item-type-7 {    opacity: 1;/*当选择某一类别菜单时,设置当前类别item的不透明度*/}.hot_navs input.selector-type-1:checked ~ a:not(.item-type-1),.hot_navs input.selector-type-2:checked ~ a:not(.item-type-2),.hot_navs input.selector-type-3:checked ~ a:not(.item-type-3),.hot_navs input.selector-type-4:checked ~ a:not(.item-type-4),.hot_navs input.selector-type-5:checked ~ a:not(.item-type-5),.hot_navs input.selector-type-6:checked ~ a:not(.item-type-6),.hot_navs input.selector-type-7:checked ~ a:not(.item-type-7) {    opacity: 0.2;/*当选择某一类别菜单时,设置其余类别item的不透明度*/}
Copy after login

At this point, all the style codes for the special effects on this page have been written. I really hope everyone can be inspired, and I also hope you like my tutorial.

Thank you everyone, see you in the next practical development case.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template