250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- CLASS
- error
- blockchain
- Ethereum
- evm
- REACT
- concept
- express.js
- Interface
- built in object
- 기준
- 삶
- useState
- hardhat
- SSR
- tailwindcss
- solidity
- typeScript
- node.js
- Redux
- bitcoin
- Props
- HTML
- JavaScript
- CSS
- middleware
- nextJS
- API
- web
- graphQL
Archives
- Today
- Total
ReasonJun
CSS / tailwindcss : rtl, ltr text-reverse problem 본문
728x90
Doing :
While configuring the chat page, I wanted the chat bubbles to be on either side using 'rtl', 'ltr'.
<div
className={`grid w-full grid-cols-[40px_1fr] gap-3 mx-auto`}
style={{ direction: `${isSender ? 'rtl' : 'ltr'}` }}
>
<div>
<Avatar
alt='user Image'
img={isSender ? senderImage! : receiverImage}
rounded
/>
</div>
<div className='flex flex-col items-start justify-center'>
<div className='flex items-center gap-2 mb-2 text-sm'>
<span className='font-medium'>{isSender ? 'You' : receiverName}</span>
<span className='text-sx text-gray-500 opacity-80'>
{fromNow(time)}
</span>
</div>
{messageImage && (
<div className='overflow-hidden rounded-md mx-[0.6rem] max-w-[80%]'>
<Image src={messageImage} width={300} height={300} alt='' />
</div>
)}
{messageText && (
<div
className={`p-2 break-all text-white rounded-lg ${
isSender
? 'bg-orange-500 rounded-tr-none'
: 'bg-gray-400 rounded-tl-none'
}`}
>
<p>{messageText}</p>
</div>
)}
</div>
</div>
problem:
The results were as follows.
Why:
The issue you are facing seems to be related to the style attribute where you set the direction based on the isSender prop. The problem is that the direction is set to "rtl" when isSender is true, which causes the text to be displayed in reverse order (right-to-left).
To fix this, you can use CSS flexbox to handle the alignment and ordering of the elements inside the grid without changing the text direction.
Solvement:
<div className={`grid w-full grid-cols-[40px_1fr] gap-3 mx-auto`}>
<div>
<Avatar
alt='user Image'
img={isSender ? senderImage : receiverImage}
rounded
/>
</div>
<div
className={`flex flex-col items-${isSender ? 'end' : 'start'} justify-center`}
>
<div className='flex items-center gap-2 mb-2 text-sm'>
<span className='font-medium'>{isSender ? 'You' : receiverName}</span>
<span className='text-sx text-gray-500 opacity-80'>{fromNow(time)}</span>
</div>
{messageImage && (
<div className='overflow-hidden rounded-md mx-[0.6rem] max-w-[80%]'>
<Image src={messageImage} width={300} height={300} alt='' />
</div>
)}
{messageText && (
<div
className={`p-2 break-all text-white rounded-lg ${
isSender
? 'bg-orange-500 rounded-tr-none'
: 'bg-gray-400 rounded-tl-none'
}`}
>
<p>{messageText}</p>
</div>
)}
</div>
</div>
728x90
'Frontend > CSS' 카테고리의 다른 글
CSS : cubic-bezier, background-clip, scrollLeft, innerWidth (0) | 2023.06.14 |
---|---|
Webkit in css (0) | 2023.06.14 |
CSS : min-content, object-fit, letter-spacing, inset, grid, grid-template-columns, box-shadow (0) | 2023.06.13 |
CSS : media (0) | 2023.06.06 |
CSS : Animation (0) | 2023.06.06 |
Comments