1.HTML代码

  • ZZES

  • MENU TITLE 1
  • MENU TITLE 2
  • MENU TITLE 3
  • MENU TITLE 4
  • MENU TITLE 5
  • MENU TITLE 6
  • MENU TITLE 7

Main Content

2.CSS代码

* {

margin: 0;

padding: 0;

}

body {

max-width: 1920px;

}

#btn {

position: absolute;

top: 22%;

left: 298px;

height: 75px;

border: 0;

border-left: 1px solid rgb(23, 32, 43, 0.2);

background: #AA3344;

color: #fff;

cursor: pointer;

}

.box {

float: left;

position: relative;

left: 0;

height: 1000px;

width: 300px;

margin-left: 0;

display: block;

background-color: #a34;

-moz-transition: margin-left 2s;

transition: margin-left 2s;

}

aside ul li {

height: 40px;

line-height: 40px;

border-top: 1px solid #fff;

border-bottom: 1px solid #fff;

list-style-type: none;

text-align: center;

}

aside ul li a {

width: 100%;

height: 100%;

text-decoration-line: none;

color: #fff;

display: block;

}

aside ul li a:hover {

background: #d3d;

}

section {

width: 100%;

height: 100%;

background: #d4d4d4;

height: 1000px;

}

section h1 {

text-align: center;

border-bottom: 1px solid #fff;

}

3.JavaScript代码

var box = document.getElementById("test")

var btn = document.getElementById("btn")

btn.onclick = function() {

if (box.offsetLeft == 0) {

box.style['margin-left'] = -300 + "px"

} else {

box.style['margin-left'] = 0 + "px"

}

}

4.右侧侧边栏的问题

写右侧侧边栏的时候,使用margin-right,会发先页面右侧溢出

这是只要再body里加入

overflow-x:hidden;即可

5.另一个写法

使用定位的方式

1)HTML代码

  • list
  • list
  • list
  • list
  • list
  • list

打开/关闭右侧侧边栏

2)CSS样式

body {

position: relative;

left: 0;

padding: 0;

margin: 0;

/*overflow-x:hidden;*/

}

aside {

width: 300px;

height: 100%;

position: fixed;

right: 0;

top: 0;

background: #d4d4d4;

transition: right 2s ease;

}

.open {

right: 0px;

}

.close {

right: -300px;

}

3)JS代码

var aside = document.getElementById("aside")

function toggle() {

if (aside.offsetLeft == 1066) {

aside.setAttribute("class", "close")

} else {

aside.setAttribute("class", "open")

console.log("not in")

}

}

6.侧边栏缩入,保留小图标

原理就是,将不要显示的display:none;掉,然后将侧边栏宽度减小,修改一些样式即可

演示地址:http://runjs.cn/detail/dopafak1

1)html代码

  • LOGO

  • ![](icon.png) and List

  • ![](icon.png) and List

  • ![](icon.png) and List

  • ![](icon.png) and List

  • ![](icon.png) and List

2)JavaScript代码

var body = document.getElementsByTagName("body")[0]

var aside = document.getElementsByTagName("aside")[0]

function list() {

if (aside.clientWidth <= 40) {

body.className = ""

} else if (aside.clientWidth > 40) {

console.log("side")

body.className = "minibody"

}

}

3)CSS代码

* {

padding: 0;

margin: 0;

}

body {

overflow-x: hidden;

position: absolute;

height: 100%;

width: 100%;

}

a {

text-decoration-line: none;

color: #fff;

}

aside {

height: 100%;

width: 300px;

position: relative;

left: 0;

top: 0;

background: #243747;

transition: width .5s;

}

aside .first {

height: 20px;

text-align: center;

padding-top: 20px;

padding-bottom: 35px;

}

aside .first .logo {

color: #243747;

font-size: 30px;

background: lightcyan;

border-radius: 20px;

transition: color 2s;

}

aside .first .logo:hover {

color: crimson;

}

aside ul li {

width: 100%;

list-style-type: none;

padding-top: 5px;

}

aside ul li a {

display: block;

padding-left: 20px;

text-align: left;

color: #fff;

transition: color 2s;

}

aside .listtext {

font-size: 30px;

display: inline-block;

}

aside ul li a:hover {

color: #000;

background: lightblue;

}

.icon-package {

width: 30px;

height: 30px;

}

.btn {

border-radius: 5px;

border: 0;

background: #243747;

color: #fff;

position: absolute;

top: 50%;

right: -12px;

height: 44px;

cursor: pointer;

}

/*mini*/

.minibody .listtext {

display: none;

}

.minibody aside {

width: 40px;

text-align: center;

}

.minibody aside ul li a {

padding-left: 0;

}

.minibody aside .first .logo {

font-size: 12px;

}

html命名侧边栏_html可伸缩侧边栏相关推荐

  1. elementui 可伸缩侧边栏_Vue Element-UI 侧边栏高亮

    我们在使用 vue + element 写后台管理模板时,肯定逃不过左侧菜单也称侧边栏. 举例:我们现在有一个 A 模块,A 模块中有详情页面和编辑页面[一共三个页面],我们通常怎么考虑?将三个页面写 ...

  2. elementui 可伸缩侧边栏_ElementUI 侧边栏伸缩布局

    导航一 选项1 选项2 Main export default { data() { return { isCollapse: true }; }, methods: { handleOpen (ke ...

  3. jquery隐藏侧边栏和折叠侧边栏方法

    实现思路:和隐藏侧边栏实现基本上相同,折叠后(只显示图标的时候)使用css控制栏目显示和隐藏. <!doctype html> <html lang="en"&g ...

  4. layui隐藏侧边栏_layui实现侧边栏收缩的方法

    layui实现侧边栏收缩的方法:首先打开原生的左侧导航栏代码并进行修改:然后打开JavaScript代码文件:最后实现侧边栏收缩效果即可. 本教程操作环境:Windows7系统.layui2.4版,该 ...

  5. Flutter Drawer侧边栏、以及侧边栏内容布局

    1.Drawer(抽屉) 侧边栏 在 Scaffold 组件里面传入 drawer 参数可以定义左侧边栏,传入 endDrawer 可以定义右侧边栏.侧边栏默认是隐藏的,我们可以通过手指滑动显示侧边栏 ...

  6. html侧边栏jq,jQuery侧边栏实现代码

    先给大家展示下实现效果图,如果亲感觉是您想要的效果,请参考本代码. 实现代码如下所示: JavaScript菜单侧边展开(改良版) 系统管理 地区设置 分行设置 银行操作用户设置 密码修改 学校管理 ...

  7. java侧边栏_DrawerLayoutDemo【侧边栏(侧滑菜单)简单实现】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 简单实现侧边栏(侧滑菜单)效果: 点击触发打开左侧侧边栏,手势滑动关闭左侧侧边栏: 手势滑动打开右侧侧边栏,手势滑动关闭右侧侧边栏: ...

  8. html侧边栏添加滚动条,侧边栏滚动条

    先来简单说说原理:监测浏览器滚动条的距离,大于一定长度时,给导航栏添加"position:fixed",小于则取消,同时还添加了animate自定义的透明度渐变过渡! 小小滚动条, ...

  9. php如何去除侧栏,WordPress移除侧边栏图文教程

    无论免费主题还是付费的专业主题,大部分默认布局都会有一个侧边栏.但侧边栏并非适合每一个站点,有时候我们可能需要移除它,该怎么做? 可以使用多种方法从整个网站或仅从特定内容中删除WordPress侧边栏 ...

最新文章

  1. AI看电影看哭了...MIT科学家正在教AI感受电影中的喜怒哀乐
  2. Tianchi数据集最全更新!
  3. 多个线程访问共享对象和数据的方式
  4. Java 防抖动函数的实现
  5. TypeScript学习笔记1:变量赋值及书写方式
  6. VTK:几何对象之Polyhedron
  7. mysql2000 sp4_SQL Server 2000 (SP4)笔记整理(二):数据库表
  8. 离线部署CDH5.16.1及各种坑
  9. append生成新变量的时候,没有如预期(It's a feature,not a bug?)
  10. 开发指南专题十七-JEECG图表配置说明
  11. Linux 命令(129)—— passwd 命令
  12. Appium 国内下载地址(百度云盘)
  13. URL rewrite
  14. Rsshub如何通过docker命令搭建
  15. 前道道指令、后道道指令暨先天八卦指令、后天八卦指令
  16. SD/SDHC/SDXC区别
  17. 【SAP Basis】SAP用户账号管理
  18. 三星Galaxy S20:将侧面按钮更改为电源按钮
  19. linux系统FW升降级步骤,使用fwupd为Ubuntu 18.04系统更新固件的方法
  20. 行存与列存的简单对比

热门文章

  1. 不得不服!windows10docker效率
  2. 数字先锋 | 主机、硬盘、CPU统统没有? 这个电教室有点“潮”!
  3. 六月过一旬了,下面剩下不到20天写个简短的计划吧
  4. (转载)C单元测试框架——cmocka
  5. 计算机网络组建对等网,计算机网络实验二组建WINDOWS环境下的对等网并共享资源.pdf...
  6. SEO基础实战课程 ,新手入门-传智-专题视频课程
  7. vue3 vue2 视频 图片 懒加载插件
  8. FPGA 实现1553总线接口
  9. rm命令在删除文件时排除指定文件
  10. GPUAnimation的Mesh动画烘焙到贴图,学习笔记