简体   繁体   English

为什么当我试图减小反应中的 div 大小时我的文本不换行

[英]Why my text don't wrap when I'm trying to decrease my size of div in react

I don't understand but when I am trying to do it in simple html. The text is not overlapping in div but in reactjs it is overlapping.我不明白,但是当我尝试在简单的 html 中进行操作时。文本在 div 中不重叠,但在 reactjs 中重叠。 Here is my problem.这是我的问题。

    const comments = [
        {uid:'1231BASDADA123',comment:"BoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
        {uid:'1231BASDADA123',comment:"Bobo"},
    ]
   
/In my output function/
<div className="list">
     {props.comments.map((item,idx) => {
      return(
        <div className='user'>
            <div className="user-uid">
               <h6> {item.uid}</h6>
            </div>
            <div className="user-comment">
               <h5>
                 {item.comment}
               </h5>
         </div>
     </div>
     )
    })}
</div>
/My CSS/ 

.fandom .topic-comments .list {
    width: 500px;
    height: 500px;
    overflow: auto;
    background: linear-gradient(46deg,black,gray);
}

.fandom .topic-comments .list .user {
    width: auto;
    height: 50px;
    padding: 10px;
    background: black;
    color: rgb(201,198,52);
    border-bottom: 2px solid rgb(235, 231, 23);
}

Just don't mind the .fandom.topic-comment it doesn't have to do anything in this problem只是不要介意.fandom.topic-comment它在这个问题上不需要做任何事情

So as you see in my first comments the longest comment overlaps to my user-comment and then I don't know how to fix it.. I try different variety of flexShrink or flexDirection in style base on this react native [Link] ( React native text going off my screen, refusing to wrap. What to do? ) and other stuff but the word doesn't really WRAP MY TEXT and I'm so done with this.. I always get this problem anywhere in my projects and I just do something like <br/> but I'm so sick of it I wanna wrap it on its own not doing some <br/>因此,正如您在我的第一条comments中看到的那样,最长的评论与我的user-comment评论重叠,然后我不知道如何解决它。我尝试了基于此反应本机 [链接] 的不同风格的flexShrink or flexDirection flexDirection本机文本从我的屏幕上消失,拒绝换行。怎么办? )和其他东西,但这个词并没有真正换行我的文本,我已经完成了这个。我总是在我的项目中的任何地方遇到这个问题,我只是做类似<br/>的事情,但我受够了,我想把它自己包装起来,而不是做一些<br/>

Any idea how to fix this?知道如何解决这个问题吗? This doesn't work in reactjs but when I try this in normal html it is working very well and I don't know why..这在 reactjs 中不起作用,但是当我在正常的 html 中尝试时,它工作得很好,我不知道为什么..

UPDATE Here is the sample when my text is not much更新这是我的文字不多时的示例在此处输入图像描述 Here is the sample when my text is a lot这是我的文字很多时的示例在此处输入图像描述 I also tried this when <textarea> but still does the same thing in我也在<textarea>时尝试过这个,但仍然在做同样的事情

If this is not enought can you just give me guys a demo of how I will wrap my text in my div in react please?如果这还不够,你们能给我演示一下我如何将我的文本包装在我的 div 中以做出反应吗? I badly hate this bug cause I always encounter this whenever my projects have a long text...the solution must be somehow related to mine....我非常讨厌这个错误,因为每当我的项目有很长的文本时,我总是会遇到这个问题……解决方案一定与我的有某种关系……

You can use word-wrap: break-word;你可以使用word-wrap: break-word; and white-space: normal;white-space: normal; on user-comment to fix it根据user-comment修复它

 .fandom.topic-comments.list { width: 500px; height: 500px; overflow: auto; background: linear-gradient(46deg, black, gray); }.fandom.topic-comments.list.user { width: auto; height: 50px; padding: 10px; background: black; color: rgb(201, 198, 52); border-bottom: 2px solid rgb(235, 231, 23); }.fandom.topic-comments.list.user.user-comment { word-wrap: break-word; white-space: normal; }
 <div class="fandom"> <div class="topic-comments"> <div class="list"> <div class='user'> <div class="user-uid"> <h6>1231BASDADA123</h6> </div> <div class="user-comment"> <h5> BoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBoboBobo </h5> </div> </div> </div> </div> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改屏幕尺寸时,我的文字无法停留在背景上 - I'm can't get my text to stay over my background when changing screen size 我对HTML缺乏经验,不理解为什么我的按钮不遵循CSS - I'm inexperienced with HTML and don't understand why my buttons don't follow my CSS 为什么我的单选按钮集不包装在具有CSS最大宽度的div中? - Why don't my radiobutton sets wrap in a div with a css max-width? 为什么wt-sky-root div 出现在我的html 中,而我没有用fi 写它 - Why the wt-sky-root div appears in my html when I don't write it in fi 单击时,我的单选按钮不会更改为“已检查”。 我正在尝试使用它来更改显示的内容 - My radio buttons don't change to Checked when clicked. I'm trying to use this to change the content displayed 为什么我的section标签与div容器重叠? 我正试图在主页下面的部分 - why is my section tag overlapping my div container? I'm trying to out the section under the homepage 我试图将图像用作“ li a”之一,但img和a的高度不同。 - I'm trying to use an image as one of my “li a” but the img and the a's don't stay at the same height . 我的OrgChart尝试包装; 我不要这个 - My OrgChart tries to wrap; I don't want this 如果我在div中放置文本动画效果,则后续的div背景不会显示 - My subsequent div backgrounds don't show up if I put a text animation effect in a div 当我减小浏览器的大小时,我的导航栏与我的徽标重叠 - My navbar is overlapping with my logo when I decrease the size of my browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM