失效的scroll-x
{{item.title}} {{item.content}}
scroll-view { width: 80%; white-space: nowrap;}.item-content { width: 40%; display: inline-block; border: 1rpx solid gray; text-align: center;}
data: { list: [{title:"题目1", content:"内容1"}, {title:"题目2", content:"内容2"}, {title:"题目3", content:"内容3"}, {title:"题目4", content:"内容4"}] }
在微信小程序的文档中,使用scroll-view标签,然后给它设置一个scroll-x就可以实现元素,横向排列,可以左右滑动。。。。
澳门太阳集团,设置横向滑动 scroll-x=”true”。 scroll-view设置宽度及white-space属性。
item设置display: inline-block属性。
然而,在实际开发中,发现并不是这么简单。。。贴上部分wxml和wxss代码…
white-space:属性设置如何处理元素内的空白。
jed_shi 剩余09:43:21 ¥321 加入 jed_shi 剩余09:43:21 ¥321 加入 jed_shi 剩余09:43:21 ¥321 加入 jed_shi 剩余09:43:21 ¥321 加入 .scroll-box { margin-top: 33rpx; padding-bottom: 40rpx;}.scroll-box .box:first-child { margin-left: 32rpx;}.scroll-box .box { width: 296rpx; margin-right: 32rpx;}.scroll-box .box .box-hd { display: flex; align-items: center;}.scroll-box .box .box-hd image { width: 64rpx; height: 64rpx; border-radius: 50%; margin-right: 15rpx;}.scroll-box .box .box-hd .info { display: flex; flex-direction: column;}.scroll-box .box .box-hd .info .name { font-size: 28rpx; color: #333; line-height: 1; padding-bottom: 10rpx;}.scroll-box .box .box-hd .info .time { font-size: 22rpx; color: #999; line-height: 1;}.scroll-box .box .box-img { margin-top: 16rpx;}.scroll-box .box .box-img image { width: 296rpx; height: 222rpx; border-radius: 15rpx;}.scroll-box .box .box-extra { display: flex; justify-content: space-between;}.scroll-box .box .box-extra .price { font-size: 32rpx; color: #f15733;}.scroll-box .box .box-extra button { width: 104rpx; height: 44rpx; background-color: #f15733; color: #fff; margin: 0; padding: 0; font-size: 26rpx; line-height: 44rpx; margin-right: 8rpx;}
normal 默认。规定段落中的文本不进行换行,空白会被浏览器忽略。
发现实际出来的效果是这样的。。扎心了,老铁!!!
pre 空白会被浏览器保留。其行为方式类似 HTML 中的 pre 标签。
后来发现其实只要给scroll-view加上white-space: nowrap;
,给scroll-view的子元素box加上display:inline-block就行了。。。
nowrap 文本不会换行,文本会在在同一行上继续,直到遇到br 标签为止。
.scroll-box {white-space: nowrap;}.scroll-box .box{display:inline-block}
pre-wrap 保留空白符序列,但是正常地进行换行。
就可以很爽的横向滑动了。。。。完美解决了
pre-line 合并空白符序列,但是保留换行符。
可以不用给scroll-view设置display:flex;这种属性了,但一定要加上这个
inherit 规定应该从父元素继承 white-space 属性的值。
.scroll-box {white-space: nowrap;}
display:
inline-block;设置为内联块。内联块可以设置长宽,但不从父元素继承长宽。即子元素不换行,成一行排列。
总结
PS:关于小程序 scroll-view 左右横向滑动没有效果问题
以上所述是小编给大家介绍的微信小程序scroll-x失效的完美解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
小程序组件 scroll-view
中分别有上下竖向滑动和左右横向滑动之分,在这次项目中刚好需要用到横向滑动,但在测试过程中发现横向滑动没有了效果,经调试发现:
1.scroll-view 中的需要滑动的元素不可以用 float 浮动;
2.scroll-view 中的包裹需要滑动的元素的大盒子用 display:flex;
是没有作用的;
3.scroll-view 中的需要滑动的元素要用 dislay:inline-block;
进行元素的横向编排;
4.包裹 scroll-view 的大盒子有明确的宽和加上样式–>
overflow:hidden;white-space:nowrap;
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
- TI8奖金突破1000万欧元,等第破千送季军神盾
- phpExcel导出大量数据出现内存溢出错误的解决方法_php技巧_脚本之家澳门太阳集团:
- jquery动态添加删除_javascript技巧_脚本之家,用Python写冒泡排序代码
- oracle自动清理archivelog文件的具体方法
- Python网页抓取urllib
- 4英寸高能版上架
- CSS布局之列表_javascript技巧_脚本之家
- SqlServer查询和Kill进程死锁的语句,守护多进程模式的实例代码_php实例_脚本之家
- 支撑时间的收获_时间日期_脚本之家澳门太阳集团
- JavaScript质量评定字符串中是不是带有html标签达成格局_javascript本领_脚本之家