【CSS】相对位置小练习

要求:

成果:

代码:

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>相对位置小练习</title>
    <link rel="stylesheet" href="./css/style.css">
</head>
<body>
    <div class="Q1">
        <a href="http://www.baidu.com" target="_blank" class="W1">百度</a>
        <a href="http://www.google.com" target="_blank" class="W2">谷歌</a>
        <a href="http://www.bing.com" target="_blank" class="W3">必应</a>
        <a href="http://www.taobao.com" target="_blank" class="W4">淘宝</a>
        <a href="http://www.jd.com" target="_blank" class="W5">京东</a>
    </div>
</body>
</html>
css 复制代码
/*做一个最外层的框架*/
.Q1{
    width: 310px;
    height: 310px;
    border: #ff5000 3px solid;
}
/*给所有a类创建伪类,使鼠标移动到指定位置变色*/
.Q1 a:hover{
    background: blue;
}
/*调整超链接字体颜色,并且把下划线去掉*/
.Q1 a{
    width: 100px;
    height: 100px;
    color: white;
    text-decoration: none;
    background: deeppink;
}
/*下面是对五个具体的超链接进行变换*/
.W1{
    display: inline-block;
    margin: 5px 0 0 5px;
}
.W2{
    display: inline-block;
    margin: 5px 5px 0 0;
    /*相对位置进行变换*/
    position: relative;
    right: -95px;
}
.W3{
    display: block;
    margin: 5px 0 0 0;
    position: relative;
    right: -105px;
    top: -5px
}
.W4{
    display: inline-block;
    margin: 0 0 5px 5px;
    position: relative;
    top: -5px
}
.W5{
    display: inline-block;
    margin: 0 5px 5px 0;
    position: relative;
    top: -5px;
    right: -95px;
}
相关推荐
star learning white2 分钟前
xm C语言12
服务器·c语言·前端
tabzzz3 分钟前
大道至简:万字漫谈前端性能监控
前端·javascript·性能优化
0思必得010 分钟前
[Web自动化] CSS基础概念和介绍
前端·css·python·自动化·html·web自动化
小胖霞12 分钟前
全栈系列(15)github Actions自动化部署前端vue
前端·node.js·github
未来魔导13 分钟前
基于 Gin 框架的 大型 Web 项目推荐架构目录结
前端·架构·gin
foundbug99936 分钟前
Modbus协议C语言实现(易于移植版本)
java·c语言·前端
Luna-player36 分钟前
在前端中list.map的用法
前端·数据结构·list
用户479492835691540 分钟前
面试官问 React Fiber,这一篇文章就够了
前端·javascript·react.js
小徐_23331 小时前
Gemini 3做粒子交互特效很出圈?拿 TRAE SOLO 来实现一波!
前端·ai编程·trae
LYFlied1 小时前
【一句话概述】Webpack、Vite、Rollup 核心区别
前端·webpack·node.js·rollup·vite·打包·一句话概述