博客园主题修改中用到的css属性

时间:2022-05-04
本文章向大家介绍博客园主题修改中用到的css属性,主要内容包括样式覆盖、响应式、浮动元素、透明的输入框、动画、图标库、组件之间的间距设定、设置div圆角、设置字体大小、设置立体感的边框、设置公告的虚线分割、设置引用块左侧颜色、将分类的竖排打乱、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

样式覆盖

id选择器大于class选择器。

对于原主题中想要覆盖的id选择器,使用!import覆盖。

对于原主题中想要取消的css属性,使用inherit.

响应式

当屏幕宽度不同时,隐藏部分元素。

@media (max-width:1360px) {
    #div_digg {
        bottom: 70px;
        left: 0;
        margin-left: 0;
    }
}
@media screen and (max-width:600px) {
    input#nav_search:focus {
        width: 85px !important;
    }
    input#nav_search { 
        transition: all 0.3s ease-in-out;
        border-bottom: 1px solid #fff;
        width: 40px;
    }
    .hiddenForMobile {
        display: none !important;
    }

}

浮动元素

position设置为fixed, 为了让组件可以浮动在其他组件之上,设置z-index.

fuck me on github

element.style {
    top: 0;
    right: 0;
    border: 0;
    z-index: 100;
    position: fixed;
}

透明的输入框

设置backgroundtransparent可以将输入框透明;

border设为0可以隐藏边框,然后追加bottom样式,注意顺序,后面声明的样式会覆盖前面。

input#nav_search {
    background: transparent;
    transition: all .6s ease-in-out;
    border: 0;
    border-bottom: 1px solid #fff;
    color: #fff;
    width: 5pc;
}

动画

css3中同一个元素属性发生变化后可以声明一个变化过程,即transition. transition: all .6s ease-in-out;表示0.6s内完成动画。

图标库

引入http://fontawesome.io . 比如search的图标为 fa fa-search

组件之间的间距设定

使用padding和margin来设置间距而不是声明width和hight后调整中心。

设置div圆角

#post_detail .postTitle {
    border-top-right-radius: 10px;
    border-top-left-radius: 10px;
}

设置字体大小

#post_detail .postTitle {
    font-size: 30px;
    font-weight: 400;
}

设置立体感的边框

#post_detail {
    box-shadow: 0 8px 17px 0 rgba(0,0,0,.2), 0 6px 20px 0 rgba(0,0,0,.19);
}

设置公告的虚线分割

.my-profile {
    border-bottom: 1px dashed #333;
    padding-bottom: 25px;
    margin-bottom: 25px;
}

设置引用块左侧颜色

#cnblogs_post_body ul.post-copyright {
    border-left: 3px solid #ff1700;
    background-color: #f9f9f9;
}

将分类的竖排打乱

.catListPostCategory li {
    display: inline-block;
}