点击左侧导航链接, 会在右侧显示对应页面。(transform: translate(-50%, -50%))

本文介绍了两种方法实现导航栏的浮动布局和鼠标悬停时的样式变化,包括使用表格+div和div+span结构,分别展示了如何创建一个居中且背景颜色可变的国内新闻导航元素。

1.点击左侧导航链接, 会在右侧显示对应页面, 仅要求实现样子
提示: 浮动 边框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .div1 {
            width: 130px;
            height: 300px;
            float: left;
            border: 1px solid;
            text-align: center;

            padding-top: 35px;
            margin-right: 20px;
        }

        .div1 a {
            text-decoration: none;
        }

        .div1 hr {
            width: 90px;
        }

        .div2 {
            width: 1000px;
            height: 600px;

            float: left;
        }

        .div2 iframe {
            width: 1000px;
            height: 600px;
        }
    </style>
</head>
<body>
<div class="div1">
    <div>
        <a href="E:\wangdao\code\src\com\zuoye\前端阶段\day3_20210218\导航页面1.html" target="test">首页</a>
    </div>
    <hr>
    <div><a href="http://www.baidu.com" target="test">百度</a>
    </div>
    <hr>
    <div>
        <a href="http://www.taobao.com" target="test">淘宝</a>
    </div>
    <hr>
    <div>
        <a href="https://www.jd.com" target="test">京东</a>
    </div>
    <hr>
</div>
<div class="div2">
    <iframe src="" name="test"></iframe>
</div>

</body>
</html>

在这里插入图片描述
2.实现导航页面
鼠标移动到"国内新闻"上时, 所移动到的这个国内新闻背景色会变成红色, 并且上下变宽(左右不变宽), 具体效果如图4, 仅要求实现此所述功能:
在这里插入图片描述
在这里插入图片描述
方法一:(表格+div)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .div0{
            /*申明使用绝对位置*/
            position: absolute;
            /*距离顶部的百分比*/
            top: 8%;
            /*距离左边的百分比*/
            left:50%;
            /*translate()函数是css3的新特性.在不知道自身宽高的情况下,可以利用它来进行水平垂直居中.。
当使用:top: 50%;left: 50%;, 是以左上角为原点,故不处于中心位置
 translate(-50%,-50%) 作用是,往上(x轴),左(y轴)移动自身长宽的 50%,以使其居于中心位置*/
            transform: translate(-50%,-50%);
            /*与负margin-left和margin-top实现居中不同的是,margin-left必须知道自身的宽高,
            而translate可以在不知道宽高的情况下进行居中,
            tranlate()函数中的百分比是相对于自身宽高的百分比,所以能进行居中。*/
        }
        .div1{
            width: 700px;

            background-color: black;
        }
        .div1 table tr td{
            color: whitesmoke;
            width: 100px;
            text-align: center;
        }
        .div1 table tr td:hover{
            background-color: #ff371a;
            border: 10px solid red;
        }

        .div2{
            width: 700px;
            background-color: yellow;
            height: 100px;
        }
    </style>
</head>
<body>
<div class="div0">
    <div class="div1">
        <table>
            <tr>
                <td>首页</td>
                <td>国内新闻</td>
                <td>国内新闻</td>
                <td>国内新闻</td>
                <td>国内新闻</td>
                <td>国内新闻</td>
                <td>国内新闻</td>
            </tr>

        </table>
    </div>

    <div class="div2">
    </div>

</div>

</body>
</html>

在这里插入图片描述
方法二:(div+span)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .div0 {
            width: 800px;
            height: 120px;
            /*申明使用绝对位置*/
            position: absolute;
            /*距离顶部的百分比*/
            top: 50%;
            /*距离左边的百分比*/
            left: 50%;
            /*translate()函数是css3的新特性.在不知道自身宽高的情况下,可以利用它来进行水平垂直居中.。
当使用:top: 50%;left: 50%;, 是以左上角为原点,故不处于中心位置
 translate(-50%,-50%) 作用是,往上(x轴),左(y轴)移动自身长宽的 50%,以使其居于中心位置*/
            transform: translate(-50%, -50%);
            /*与负margin-left和margin-top实现居中不同的是,margin-left必须知道自身的宽高,
            而translate可以在不知道宽高的情况下进行居中,
            tranlate()函数中的百分比是相对于自身宽高的百分比,所以能进行居中。*/
        }

        .div1{
            background-color: black;
            width: 100%;
            height: 25%;
        }
        .div1 div{
            float: right;
            height: 100%;
            width: 14.2%;
            text-align: center;
        }

        .div1 span {
            color: whitesmoke;
        }

        .div1 span:hover {
            width: 100%;
            height: 100%;
            background-color: #ff371a;
            border: 10px solid red;
        }

        .div2 {
            width: 100%;
            background-color: yellow;
            height: 100px;
        }
    </style>
</head>
<body>
<div class="div0">
    <div class="div1">
        <div>
            <span>
            国内新闻
        </span>
        </div><div>
            <span>
            国内新闻
        </span>
        </div><div>
            <span>
            国内新闻
        </span>
        </div><div>
            <span>
            国内新闻
        </span>
        </div><div>
            <span>
            国内新闻
        </span>
        </div><div>
            <span>
            国内新闻
        </span>
        </div><div>
            <span>
            国内新闻
        </span>
        </div>
    </div>

    <div class="div2">

    </div>

</div>

</body>
</html>

在这里插入图片描述

<template> <div class="content-box"> <!-- 左侧---> <div class="card filter left-list"> <el-button type="primary" class="add-btn" @click="openDrawerType(&#39;新增数据字典&#39;,[])">新增字典</el-button> <el-input v-model="filterText" class="filterTextInput" placeholder="请输入" clearable /> <div class="list-box"> <template v-if="treeData.length"> <div :class="[&#39;item&#39;, { active: activeTypeItem.id === item.id }]" v-for="item in filteredTreeData" :key="item.id" @click="handleItemClick(item)"> <div>{{ item.name }}</div> <div class="right-opearte"> <span @click.stop="openDrawerType(&#39;编辑数据字典&#39;,item)" v-if="hasBtnPermission( &#39;system:dataDictionary:btn-editrype&#39; ) "><i class="el-icon-edit"></i>编辑</span> <span @click.stop="handleDelType(item)" v-if="hasBtnPermission( &#39;system:dataDictionary:btn-deleteType&#39; ) "><i class="el-icon-delete"></i>删除</span> </div> </div> </template> </div> </div> <!-- 右侧-数据列 --> <div class="descriptions-box"> <div class="box-tip card" v-if="Object.keys(activeTypeItem).length"> <div class="detail"> <div class="item block"><span class="item-name">编码:</span><span>{{activeTypeItem.code}}</span></div> <div class="item block"><span class="item-name">名称:</span><span>{{activeTypeItem.name}}</span></div> <div class="item regex" :style="{ width: windowWidth+&#39;px&#39; }"><span class="item-name">备注:</span><span :title="activeTypeItem.remark">{{activeTypeItem.remark}}</span></div> <div class="item btn"> <el-button type="primary" class="add-btn" @click="openDrawer(&#39;新增字段值&#39;, [])">新增字段</el-button> </div> </div> </div> <div style="height:100%" v-if="Object.keys(activeTypeItem).length"> <ProTable ref="proTable" :columns="columns" :request-api="dummyRequest" :init-param="initParam" :data-callback="dataCallback" > <!-- <ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam" :data-callback="dataCallback"> --> <template #operation="scope"> <el-button type="primary" link @click="openDrawer(&#39;编辑字段值&#39;, scope.row)">编辑</el-button> <el-button v-if="scope.row.status == &#39;enabled&#39;" type="primary" style="color:#FF0000" link @click="changeStatus(scope.row)">禁用</el-button> <el-button v-if="scope.row.status == &#39;disabled&#39;" type="primary" style="color:#49C625" link @click="changeStatus(scope.row)">启用</el-button> <el-button type="primary" link @click="deleteAccount(scope.row)">删除</el-button> </template> </ProTable> </div> <div class="card empty" v-else> <el-empty description="请先选择字典类型"></el-empty> </div> </div> <!-- 新增字典类型 --> <addType ref="dialogAddType"/> <!-- 新增编辑字段 --> <addDataDictionary ref="dialogAddDataDictionary"/> </div> </template> <script setup lang="ts" name="dataDictionary"> import { ref, watch, reactive, inject, onMounted, onUnmounted } from "vue"; import { ElTree, FormInstance, FormRules, ElMessage, } from "element-plus"; import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface"; import { Supplier } from "@/api/interface"; import ProTable from "@/components/ProTable/index.vue"; import addDataDictionary from "@/views/system/dataDictionary/addDataDictionary.vue"; import addType from "@/views/system/dataDictionary/addType.vue"; import { setValueList, addDictionaryType, setValueClildList, addDictionaryValue, } from &#39;@/api/modules/public&#39;; import { getUserDepartment, getStaffList, getPositionList, } from "@/api/modules/user"; import { da, ro } from "element-plus/es/locale"; const hasBtnPermission: any = inject(&#39;hasBtnPermission&#39;); const windowWidth = ref<number>(0); const treeData = ref<any[]>([]); const tableAllData = ref<{ [key: string]: any }[]>([]); const activeTypeItem = ref<Record<string, any>>({}); const filteredTreeData = ref<any[]>([]); const filterText = ref(""); const defaultProps = { children: "children", label: "label" }; // const dummyRequest = async (params: any) => { // return { list: [] }; // 返回一个空列表,避免 ProTable 报错 // }; watch( () => filterText.value, (val) => { if (!val) { filteredTreeData.value = treeData.value; } else { const keyword = val.toLowerCase(); filteredTreeData.value = treeData.value.filter(item => item.name?.toLowerCase().includes(keyword) ); } }, { immediate: true } ); // 获取窗口宽度 const updateWindowWidth = () => { windowWidth.value = window.innerWidth - 700; }; onMounted(async () => { getTreeList() updateWindowWidth(); // 初始化 window.addEventListener("resize", updateWindowWidth); }) // 组件卸载时移除监听 onUnmounted(() => { window.removeEventListener("resize", updateWindowWidth); }); // 左侧树 const getTreeList = async () => { const { data } = await setValueList(); treeData.value = data || []; filteredTreeData.value = data || [] // 编辑数据后,右侧数据更新 if(Object.keys(activeTypeItem.value).length > 0) { treeData.value.forEach(item => { if(item.id === activeTypeItem.value.id) { activeTypeItem.value = item } }) } return { list: data || [] }; } const handleItemClick = async (data: any) => { activeTypeItem.value = data; const list = await getTableList(); // 获取非分页数据 console.log(&#39;list&#39;,list) // proTable.value?.setData(list); // 手动设置数据 // proTable.value?.refreshData(); // 调用 ProTable 自带的刷新方法 }; const getTableList = async () => { const formData = { dictCode: activeTypeItem.value.code }; const response = await setValueClildList(formData); const data = response.data || []; console.log(&#39;data1111&#39;,data) // 假设接口返回的是 { list: [...] } // 如果是分页数据,提取 list 即可 const flatData = data ? data : []; tableAllData.value = flatData // 如果需要树形结构可转换 return flatData; // 返回非分页数据 }; const dataCallback = (data: any) => { console.log(&#39;data&#39;,data) return tableAllData.value; // 直接使用 tableAllData 中的数据 } const handleDelType = () => {} // ProTable 实例 const initParam = reactive({}); // 表格配置项 const proTable = ref<ProTableInstance>(); const columns = reactive<ColumnProps<Supplier.pageList>[]>([ { prop: "itemLabel", label: "名称" }, // { prop: "itemValue", label: "编码" }, // { prop: "remark", label: "备注" }, // { prop: "sort", label: "排序" }, // { // prop: "isDeleted", // label: "状态", // render: scope => { // console.log(&#39;2222&#39;,scope) // return scope.row.isDeleted ? "禁用" : "启用"; // } // }, // { prop: "operation", label: "操作", fixed: "right", width: 330 } ]) // 搜索过滤 const filterNode = (value: string, node: any) => { if (!value) return true; return node.data.label.includes(value); }; // 新增字典类型 const dialogAddType = ref<InstanceType<typeof addType> | null>(null); const openDrawerType = (title: string,row:any) => { const params = { title:title, api: addDictionaryType, row:row, getTableListData:getTreeList } dialogAddType.value?.acceptParams(params); } // 新增 const dialogAddDataDictionary = ref<InstanceType<typeof addDataDictionary> | null>(null); const openDrawer = (title: string, row: any) => { const item = activeTypeItem.value const params = { title:title, row:{...row,item}, isView:false, api: addDictionaryValue, getTableList:getTableList } dialogAddDataDictionary.value?.acceptParams(params); } // 修改状态 const changeStatus = async (row: Supplier.pageList) => { } // 删除 const deleteAccount = async (row: Supplier.pageList) => { } </script> <style scoped lang="scss"> @use "@/styles/treeIndex.scss"; .left-list{ .list-box { height: calc(100% - 95px); overflow: auto; margin-top: 10px; } .item { cursor: pointer; display: flex; justify-content: space-between; padding: 5px 10px; border-radius: 4px; font-size: 14px; color: #606266; &.active { background: #e6f5f3 !important; } &:hover { background: rgb(245, 247, 250); } span { cursor: pointer; margin-left: 10px; i { margin-right: 3px; } &:first-of-type { color: #009688; } &:last-of-type { color: #f56c6c; } } } } .descriptions-box{ .box-tip{ overflow: hidden; } .empty{ width: 100%; height: 100%; .el-empty{ transform: translate(0, 50%); } } .detail{ .item{ margin: 0; color: #303133; font-size: 15px; margin-bottom: 10px; &.block{ width: 50%; display: inline-block; } &.btn{ padding-bottom: 10px; text-align: end; } &.regex{ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .item-name{ color: #727272; } } } } </style> columns列表为什么没展示数据
07-31
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值