如何单独定义 a鼠标经过默认背景颜色_如何制作简洁大气的网站首页

6aa5a98557b923ec36b26191f095ab2b.png
知乎视频​www.zhihu.com

1.初始化页面样式

不同的元素有不同的初始样式,如ul元素有list-style默认样式,body元素有默认的margin。当使用CSS样式还原网页设计图时,这些默认样式会影响网页样式的准确性。因此,在制作网页之前,首先要清空元素的默认样式,这种行为一般称为CSS初始化设置。常用的CSS初始化设置如下。

body,ul,ol,li,p,h1,h2,h3,h4,h5,h6,form,fieldset,table,td,img,div
{margin:0;padding:0;border:0;} 
ul,ol{list-style-type:none;} 
input,img,select{vertical-align:middle;} 
a{text-decoration:none;} 
a:link{color:#009;} 
a:visited{color:#800080;} 
a:hover,a:active,a:focus{color:#c00;text-decoration:underline;}

一般来讲,需要将常用的CSS初始化设置写成一个reset.css文件,在每次页面开始的位置引用这个文件即可。当页面引用多个CSS文件时,要将reset.css文件放在第一位,这是为了让页面自身的CSS样式覆盖初始化样式。并在head中引入该文件

<link rel='stylesheet' href='./reset.css'/>

2.写入内容

html代码如下

<body>
    <div class="container">
        <ul>
            <li>Introduce</li>
            <li>Contact</li>
            <li>Activity</li>
        </ul>
        <div class='content'>
            <p>Designing through the night to bring wise ideas to light.</p>
            <p>With your vision,my design savvy ,and a hefty amount of coffee,we can create a digital experience that is creative,beautiful an memorable.</p>
            <button>SOUNDS GOOD?LET'S CHAT</button>
        </div>
    </div>
    
</body>

bd1cebe9bc204eb25fb6d34285b339e4.png
图1 写入内容

3.盒模型布局

导航栏横排,设置字体样式,间距等

 li{
            display: inline-block;//横排
            width: 120px;
            height: 28px;
            text-align: center;//文字居中
            font-size: 18px;
            margin: 30px 20px;//菜单项间距
        }
 .content{
            margin: 210px auto;//段类居中
            width: 800px;
            text-align: center;//文字居中
        }

11bfcc385eec065e1a53ce58cdbd9749.png
图2 设置导航横排,文字段落居中

4.设置背景,字体,按钮样式

.container{
        background-color: #2d3a4b; 
}
.content p:nth-child(1){ //段类文字样式
       font-size: 50px;
       color: #ffffff;
            
}
.content p:nth-child(2){
            color:#aab0b6;
            font-size: 20px;
            line-height: 24px;
            margin-top: 30px;
 }
  button{
            margin: 50px auto;
            width: 400px;
            height: 54px;
            background-color: #f2c94c;
            font-size: 20px;
            color: #abb0b7;
            border: none;
}

a5d2b5cf2deb9000d863b80c0aad8309.png
图3 静态样式已完成

5.添加动态样式

  • 当鼠标悬浮到导航栏时,添加一个激活样式,并给一个动态效果
li:hover{
          border-top: 12px solid #f2c94c;
          color: white;
          transform:scale3d(1.2,1.2,1.2)//缩放效果
}

这时鼠标移上去时,因为上边框增高,会导致整个导航栏下移导致用户体验不好,所以在li中事先定义一个同等高度的边框,且颜色透明来避免导航栏下移,并修改边框与文字的间距,为了让动画更流畅,可以使用过渡效果

 li{
            display: inline-block;
            width: 120px;
            height: 28px;
            text-align: center;
            font-size: 18px;
            color: #abb0b7;
            margin: auto 20px;
            border-top: 12px solid transparent;//定义透明边框,避免悬浮时挤动文字
            padding-top: 30px; //边框与文字的间距
            transition: .5s;//过渡
        }

efe55680574221e514f57bd0402ea6a6.png
图4 导航栏鼠标悬浮效果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值