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>  
  
相关推荐
htzyl2067 小时前
前端样式-弹窗淡入淡出,为什么你的 `transition` 一直不生效
前端·css·html
Brookty7 小时前
CSS基础知识(二):盒模型、内外边距、外边距折叠与父子元素的布局关系
前端·css
Mh1 天前
我是如何设计品牌站组件库的?
前端·css·设计模式
Brookty1 天前
CSS基础知识(一):选择器、优先级、层叠与继承、边框属性及盒模型
前端·css
htzyl2061 天前
CSS中,`:has()` 能帮你删掉的 4 类 JS
前端·css
jianqiang.xue2 天前
Espressif-IDE进入维护模式:乐鑫把ESP32开发的宝押给VS Code
前端·css·ide
feixing_fx2 天前
CSS 变量(Custom Properties):构建可扩展的主题切换系统
前端·css·前端框架·html·css3
晓得迷路了4 天前
栗子前端技术周刊第 154 期 - Parcel 3 Alpha、JS 调查报告、Vite 漏洞...
前端·javascript·css
ZhengEnCi5 天前
登录页电脑端怎么设计才不空:5 种布局方案与可粘贴 AI 提示词
前端·css·设计
神膘护体小月半6 天前
css - 元素背景图由 hover 触发,初次加载时闪动的解决办法
前端·javascript·css