【div+css】关于滚动条

如何出现滚动条?

万变不离其宗:文档内容超过其高度就会有滚动条。

1.设固定高度+overflow:auto就会出现滚动条,此举措表示适配的时候会让自己崩溃。

2.设置top+bottom即可让它高度自动适应(此刻不设置div高度,文档内容自填充),当然此刻要注意好定位,定位不好,真的也会崩溃。

例子1:无固定高度的

<style type="text/css">
			html,body{
				margin:0;
				padding:0;
				height:100%;
			}
			.wrapper{
				height:100%;
				position: relative;
			}
			header{
				width:100%;
				height:100px;
				background: blue;
				color:#fff;
				position: absolute;
				top:0;
				left:0;
			}
			footer{
				width:100%;
				height:100px;
				background: blue;
				color:#fff;
				position: absolute;
				bottom:0;
				left:0;
			}
			.content{
				width:100%;
				position: absolute;
				top:100px;
				bottom: 100px;
				background: burlywood;
			}
			.section1{
				height: 100px;
				background: red;
			}
			.section2{
				height:30px;
				background: green;
			}
			.section3{
				width:100%;
				position: absolute;
				top:130px;
				bottom: 0;
				overflow: auto;
			}
		</style>
	</head>
	<body>
		<div class="wrapper">
			<header>header</header>
			<section class="content">
				<section class="section1">
					广告
				</section>
				<section class="section2">title</section>
				<section class="section3">
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
					<p>内容</p>
				</section>
			</section>
			<footer>footer</footer>
		</div>		
	</body>
效果示意图:




要实现自适应长度的横向滚动公告,可以使用CSS3的flex布局和marquee标签。具体步骤如下: 1. 使用一个div元素作为容器,设置宽度为100%、高度为固定值,并且设置overflow属性为hidden,使内容超过div大时被隐藏。 2. 在div容器内部创建一个ul元素,并使用CSS3的flex布局,设置flex-wrap属性为nowrap,使ul元素内部的li元素无法换行。 3. 对ul元素设置white-space属性为nowrap,使ul元素内部的文本不换行。 4. 对li元素设置display:inline-block,使li元素能够在一行内显示。 5. 使用marquee标签来实现横向滚动的效果,并将marquee标签内部的内容设置为ul元素。 6. 通过CSS3的media query来实现不同屏幕尺寸下的适配。 下面是示例代码: HTML代码: ``` <div class="notice-container"> <marquee behavior="scroll" direction="left"> <ul class="notice-list"> <li>第一条公告信息</li> <li>第二条公告信息</li> <li>第三条公告信息</li> <li>第四条公告信息</li> <li>第五条公告信息</li> <li>第六条公告信息</li> <li>第七条公告信息</li> </ul> </marquee> </div> ``` CSS代码: ``` .notice-container { width: 100%; height: 50px; overflow: hidden; } .notice-list { display: flex; flex-wrap: nowrap; white-space: nowrap; } .notice-list > li { display: inline-block; } @media screen and (max-width: 768px) { .notice-list > li { font-size: 12px; } } @media screen and (min-width: 768px) and (max-width: 992px) { .notice-list > li { font-size: 14px; } } @media screen and (min-width: 992px) { .notice-list > li { font-size: 16px; } } ``` 通过上述步骤,就可以实现一个自适应长度的横向滚动公告了。可以根据需要调整容器的高度、文本的字体大小、marquee标签的滚动速度等参数来适应不同的场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值