码农知识堂 - 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

  • 相关阅读:
    R语言dplyr包filter函数过滤dataframe数据中指定数据列的内容为(等于指定向量中的其中一个)在指定列表中的数据行
    BASH shell脚本篇3——字符串处理
    生信学院|10月13日《SOLIDWORKS参数化应用——DriveWorksXpress》
    红黑树(一) - 算法原理与介绍
    【甄选靶场】Vulnhub百个项目渗透——项目十六:FristiLeaks_1.3(文件上传,py脚本改写,sudo提权,脏牛提权,源码获取)
    JavaScript 的发展历史
    python爬虫top250电影数据
    CMake库搜索函数居然不搜索LD_LIBRARY_PATH
    红外避障模块介绍
    深入理解WPF的ResourceDictionary
  • 原文地址:https://blog.csdn.net/weixin_44708240/article/details/125552008
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号