[英]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.