码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决


     【现象描述】

    当text组件的内容较多多行显示的时候,相邻的div样式会显示异常,会从正常的圆形变为椭圆。

    代码如下:

    1. <template>
    2. <div class="container">
    3. <div style="align-items: center;">
    4. <div class="typscolor" style="background-color: blue; opacity: 0.26; margin-left: 16px;"></div>
    5. <text>{{text}}</text>
    6. <div class="typscolor" style="background-color: blue; opacity: 0.26; margin-left: 16px;"></div>
    7. <text>{{text}}</text>
    8. <div class="typscolor" style="background-color: blue; opacity: 0.26; margin-left: 16px;"></div>
    9. <text>{{text}}</text>
    10. </div>
    11. </div>
    12. </template>
    13. <style>
    14. .container {
    15. flex-direction: column;
    16. justify-content: center;
    17. height: 100%;
    18. }
    19. text {
    20. font-size: 24px;
    21. }
    22. .typscolor {
    23. border-radius: 50%;
    24. width: 30px;
    25. height: 30px;
    26. background-color: red;
    27. margin-right: 8px;
    28. }
    29. </style>
    30. <script>
    31. module.exports = {
    32. data: {
    33. text:'text文本内容过多时左边的圆圈会被拉伸'
    34. },
    35. onInit() {
    36. },
    37. }
    38. </script>

    如图所示

    异常

    cke_11537.png

    正常

    cke_56930.png

    【问题分析】

    当text组件内容过多时,flex布局的时候宽度超出会自动压缩,从而导致div标签被拉伸了

    【解决方法】

    可以给div标签设置flex-shrink: 0属性,即可解决该问题

    示例代码如下:

    1. <template>
    2. <div class="container">
    3. <div style="align-items: center;">
    4. <div class="typscolor" style="background-color: blue; opacity: 0.26; margin-left: 16px;"></div>
    5. <text>{{text}}</text>
    6. <div class="typscolor" style="background-color: blue; opacity: 0.26; margin-left: 16px;"></div>
    7. <text>{{text}}</text>
    8. <div class="typscolor" style="background-color: blue; opacity: 0.26; margin-left: 16px;"></div>
    9. <text>{{text}}</text>
    10. </div>
    11. </div>
    12. </template>
    13. <style>
    14. .container {
    15. flex-direction: column;
    16. justify-content: center;
    17. height: 100%;
    18. }
    19. text {
    20. font-size: 24px;
    21. }
    22. .typscolor {
    23. border-radius: 50%;
    24. width: 30px;
    25. height: 30px;
    26. background-color: red;
    27. margin-right: 8px;
    28. flex-shrink: 0; /*加上该属性即可解决拉伸问题*/
    29. }
    30. </style>
    31. <script>
    32. module.exports = {
    33. data: {
    34. text:'text文本内容过多时左边的圆圈会被拉伸'
    35. },
    36. onInit() {
    37. },
    38. }
    39. </script>

    如图所示:

    cke_155420.png

    欲了解更多详情,请参见:
    华为官网:
    https://developer.huawei.com/consumer/cn/forum/topic/0203908673278080243?fid=23?ha_source=zzh

  • 相关阅读:
    【DevOps系列】Docker数据卷(volume)详解
    从0搭建Vue3组件库(四): 如何开发一个组件
    记录一下自己涉及到的时间及金额方法的处理
    javascript的动态作用域和静态作用域
    高等数学(第七版)同济大学 习题8-1 个人解答
    408操作系统学习笔记——进程与线程、处理机调度、同步与互斥(PV操作)、死锁
    Spring MVC 中的数据验证技术
    CSS层级小技巧!如何在滚动时自动添加头部阴影?
    【LeetCode-简单题】383. 赎金信
    Java BufferedWriter.write()具有什么功能呢?
  • 原文地址:https://blog.csdn.net/weixin_44708240/article/details/125552008
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号