与css风格抗争

8yparm6h  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(197)

我正在创建一个react聊天应用程序,90%的工作已经完成,但我正在努力使用css来获得更好的ui体验。
我正在努力解决两个问题:
发送方和接收方仅在一侧
如果文本太长,而没有进入下一行,它将离开查看屏幕(希望所有内容都在屏幕内),当我能够筛选右侧的发送者部分时,则只有图像的对齐方式不同,否则img从文本的右侧到左侧

img样本:

代码:

js部分:

// few lines
<main>
    {messages && messages.map(msg => <Message key={msg.id} messageIN={msg}/>)}
    <span ref={autoScrollToDown}></span>
</main>
// few lines
function Message(props){

    const { text, uid, photoURL } = props.messageIN;
    const messageType = uid === auth.currentUser.uid ? 'sent' : 'received';

    if(messageType==='sent'){
        return(
            <div className="msgsent">
                <p>{text}</p>
                <img src={photoURL} alt="ProfilePic"/>
            </div>
        )
    } 
    else if(messageType==='received'){
        return(
            <div className="msgreceived">
                <img src={photoURL} alt="ProfilePic"/>
                <p>{text}</p>
            </div>
        )
    }
    else{
        return(
            <div className="msgerror"> 
                <p>Oops! Some unexpected problem occurred</p>
            </div>
        )
    }
}

css部分:

.msgsent{
    display: grid;
    grid-template-columns: auto auto;
    justify-content: right;
    grid-column: 0px;
    flex-direction: row-reverse;
    display: flex;
    flex-direction: row;
    align-items: center;
}
.msgsent img{
    width: 40px;
    height: 40px;
    border-radius: 50px;
    margin: 2px 5px;
    justify-content: center;
}
.msgsent p{
    margin-bottom: 12px;
    padding: 10px 10px;
    border-radius: 15px;
    position: relative;
    text-align: center;
    background: #6bd5ff;
    display: flex;
    color: rgb(31, 31, 31);
    transition: all 0.5s ease 0s;
}
.msgsent p:hover{
    box-shadow: 0px 0px 30px -10px #6bd5ff;
}
.msgreceived{
    display: grid;
    grid-template-columns: auto auto;
    grid-column: 0px;
    flex-direction: row-reverse;
    display: flex;
    flex-direction: row;
    justify-content: left;
    align-items: center;
}
.msgreceived img{
    width: 40px;
    height: 40px;
    border-radius: 50px;
    margin: 2px 5px;
    justify-content: center;
}
.msgreceived p{
    margin-bottom: 12px;
    padding: 10px 10px;
    border-radius: 15px;
    position: relative;
    text-align: center;
    background: #dddbe6;
    display: flex;
    color: black;
    transition: all 0.5s ease 0s;
}
.msgreceived p:hover{
    box-shadow: 0px 0px 30px -10px #6bd5ff;
}
.msgerror{
    left: 30%;
    right: 30%;
    border-radius: 15px;
    color: rgb(255, 255, 123);
    margin: 5px 5px;
    justify-content: center;
    display: flex;
    background-color: transparent;
    text-align: center;
    border: 1px solid rgb(255, 255, 123);
    box-shadow: 0px 0px 30px -5px rgb(255, 255, 123);
    transition: all 0.5s ease 0s;
}
.msgerror:hover{
    background-color: rgba(241, 153, 153, 0.096);
    color: rgb(255, 123, 123);
    border: 1px solid rgb(255, 123, 123);
    box-shadow: 0px 0px 30px -5px rgb(255, 123, 123);
    letter-spacing: 2px;
}
main{
    top:95px;
    right: 5px;
    left: 5px;
    bottom: 55px;
    overflow-y: scroll;
    position: fixed;
    display: grid;
    grid-template-rows: auto;
    grid-row-gap: 4px;
}
main::-webkit-scrollbar {
    border-radius: 50px;
    width: 0.25rem;
} 
main::-webkit-scrollbar-track {
    background: #1e1e24;
} 
main::-webkit-scrollbar-thumb {
    background: #6649b8;
}

这是所有的代码,请帮助我使ui更漂亮
-非常感谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题