【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;
}
相关推荐
Bigfish_coding5 小时前
前端转agent-第一周【python】-05 Ollama+Qwen3实战:会话记忆实战
前端
x***r1515 小时前
.NET 10 SDK 安装教程(dotnet-sdk-10.0.100-win-x64详细步骤)
java·服务器·前端
新新技术迷5 小时前
给 Agent 做"工具调用过程可视化",让用户看见它在干嘛
前端
feixing_fx6 小时前
选择器的威力——深入理解优先级计算与层叠规则
开发语言·前端·css·前端框架·html
代码小库6 小时前
【2026前端转 AI 全栈指南】第 1 章:前言 · 后端架构 · 章节导览
前端·人工智能·架构
晓13136 小时前
【Cocos Creator 3.x】篇——第四章 子系统
前端·javascript·游戏引擎
li-xun6 小时前
我的在线工具箱继续升级:新增 Token 计算器、AI 提示词生成器和开发者格式化工具
javascript·django·html5
ikoala6 小时前
Codex 怎么买、怎么充值?先把这两套计费搞清楚
前端·javascript·后端
wuhen_n6 小时前
RAG 优化实战:检索精准度提升全方案
前端·langchain·ai编程
Mike_jia6 小时前
DataEase:人人可用的开源BI神器,企业数据决策民主化实战指南
前端