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>  
  
相关推荐
海兰21 小时前
【应用】UUID v7 生成器 HTML 代码
css·html·css3
feixing_fx2 天前
告别枯燥字体:Web 字体加载策略与 font-display 最佳实践
前端·css·前端框架·交互·css3
ly76892 天前
CSS 从入门到进阶:系统掌握现代网页样式与布局
前端·css
前端技术官2 天前
一行 CSS 新特性干掉 20 行 JavaScript ?
css·滚动驱动动画·容器查询·:has()·anchor positioning
Beginner x_u2 天前
Tailwind CSS 速通:有 CSS 基础的实战入门
css·tailwindcss·工程化
WL_arm3 天前
Vibe Coding(氛围编程)入门
javascript·css·人工智能·html5
谙忆10244 天前
图片裁剪总是跑偏?用 object-fit、object-position 和真实像素把坐标对齐
javascript·css·图像识别
01_ice4 天前
前端学习css
前端·css·学习
zh_xuan4 天前
个人主页左侧菜单支持分组,以及菜单显示和隐藏
前端·javascript·css
Ming_studying4 天前
HTML + CSS + JavaScript实现可视化JSON工具:格式化、折叠、搜索与错误定位
javascript·css·html·json·数据可视化·web工具