CSS 经典使用场景

CSS 经典使用场景

要滚动的页面,滚动条不占据空间,当我们把鼠标悬浮在滚动页面上面的时候,滚动条出现。

html 复制代码
  <style>
  .box {
    width: 350px;
    overflow: hidden;  /* 父元素hidden */
    height: 650px;
    box-shadow: 0 0 5px rgba(93, 96, 93, 0.5);
  }
  .box:hover {
    overflow: overlay; /* 当hover效果的时候,滚动条出现 */
  }
  .box .item {
	width: 300px;
	height: 200px;
  }
  img {
   width: 100%;
   height: 100%;
  }
  </style>
  <div class="box">
    <div class="item">
      <img src="https://n.sinaimg.cn/sinacn20119/548/w1322h826/20190408/3862-hvhrcxn2259616.jpg" alt="">
    </div>
    <div class="item">
      <img src="https://n.sinaimg.cn/sinacn20119/548/w1322h826/20190408/3862-hvhrcxn2259616.jpg" alt="">
    </div>
	<div class="item">
      <img src="https://n.sinaimg.cn/sinacn20119/548/w1322h826/20190408/3862-hvhrcxn2259616.jpg" alt="">
    </div>
	<div class="item">
      <img src="https://n.sinaimg.cn/sinacn20119/548/w1322h826/20190408/3862-hvhrcxn2259616.jpg" alt="">
    </div>
  </div>

谷歌版本高的浏览器,会把overflow: overlay;当成overflow: auto;用
比较好的解决方法是:el-scrollbar组件。这个自带上面的效果

一段可滚动的文字

其实非常简单,就是给文字的div加一个动画。让整体向左或者右移动。

html 复制代码
<!doctype html>  
<html>  
<head>  
<title>LOOP</title>  
<style>  
@keyframes loop {  
	0% {  
		transform: translateX(0);  
	}  
	100% {  
		transform: translateX(-100%);  
	}  
}  
  
.box {  
	white-space: nowrap;  
}  
  
.scrollDiv {  
	width: 600px;  
	display: inline-block;  
	text-align: center;  
	animation: loop 2s linear infinite;  
}  
</style>  
</head>  
<body>  
<div class="box">  
	<div class="scrollDiv">  
		这是一段可以滚动的文本  
	</div>  
</div>  
</body>  
  
</html>  
  
相关推荐
刃神太酷啦2 天前
前端入门第一课:HTML 基础语法 + 常用标签 + 实战全解
服务器·c语言·前端·javascript·css·c++·html
扶苏10022 天前
CSS 图标换色指南:用 brightness / invert / mask 把任意图片改成想要的颜色
css
我命由我123452 天前
CSS - CSS 媒体查询 orientation
前端·javascript·css·html·css3·html5·js
zhanghaha13143 天前
HTML系列教程:18_HTML / CSS 颜色零基础详解
css·html·tensorflow
Aaswk3 天前
从 HTML/CSS/JS 到 Vue + Axios 的一篇实战笔记
前端·css·vue.js·html
xieliyu.4 天前
前端基础:常见CSS选择器用法
前端·css·笔记·vscode
cll_8692418916 天前
WordPress Single Post 文章页美化:响应式表格、图片优化与自动悬浮 Table of Contents(CSS + JS)
前端·css
愛芳芳6 天前
基于 Electron + Vue3 的仿 PC 微信客户端项目实战
前端·javascript·css·elementui·typescript·electron·vue
feixing_fx6 天前
伪类与伪元素的魔法:纯 CSS 打造炫酷的按钮悬停特效
前端·css·css3
Peter-Code7 天前
微前端避坑指南:主应用与子应用的高度及滚动条协调
css·前端框架·微前端