【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;
}
相关推荐
Fairy要carry几秒前
项目01-手搓Agent之loop
前端·javascript·python
亲亲小宝宝鸭5 分钟前
Ctrl ACV工程师的提效之路:删掉项目中的冗余
前端
kyriewen8 分钟前
DOM树与节点操作:用JS给网页“动手术”
前端·javascript·面试
米饭同学i12 分钟前
基于腾讯云COS的小程序素材上传功能实现
前端·javascript·react.js
cxxcode12 分钟前
前端性能指标接入 Prometheus 技术方案
前端
辣椒炒代码13 分钟前
🚀 AI Agent 入门实战:基于 LangChain + MCP 构建智能导游助手
前端
ruanCat17 分钟前
前端工程化工具链从零配置:simple-git-hooks + lint-staged + commitlint
前端·git·代码规范
光影少年19 分钟前
如何开发一个CLI工具?
javascript·测试工具·前端框架·node.js
哈__29 分钟前
ReactNative项目OpenHarmony三方库集成实战:react-native-fingerprint-scanner
javascript·react native·react.js
晴栀ay33 分钟前
Generator + RxJS 重构 LLM 流式输出的“丝滑”架构
javascript·后端·llm