onclick stay focused untill click another component from the area - html

I try to make a chat-app, now i'm trying to implement the cheats and when user click on one chat, styles must change and remain until the user focus it's gonna to another chat
In my example let's assume someone clicked on User 2. The chat changed style and now have the style that should have when someone open that chat. How can i make the style to stay like that until someone open another chat? I didn't find any css propriety or some react tricks.
.userChatBubbles {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 5%;
width: 100%;
height: 100%;
}
.allOfMessage {
width: 100%;
height: 20%;
display: flex;
flex-direction: row;
align-items: center;
margin-left: 13%;
margin-bottom: 1px;
}
.messageBubleNEWMSG {
display: flex;
flex-direction: row;
align-items: center;
width: 90%;
height: 80%;
font-size: 15px;
background: #1d1335;
opacity: 1;
border-radius: 2%;
padding-left: 4%;
margin-right: 10%;
font-family: 'Roboto', sans-serif;
}
.messageBuble {
display: flex;
flex-direction: row;
align-items: center;
width: 90%;
height: 80%;
font-family: 'Roboto', sans-serif;
font-size: 15px;
padding-left: 4%;
margin-right: 10%;
}
.photo {
background: green;
width: 45px;
height: 45px;
margin-top: 2%;
border-radius: 10%;
margin-right: 6%;
}
.messageBubleNEWMSG.personNameAndMsg.personName {
color: green !important;
margin-top: 200%;
}
.messageBuble .personNameAndMsg h3 {
color: #c2b4da;
font-family: 'Roboto', sans-serif;
font-weight: 100;
font-size: 15px;
}
.messageBuble .personNameAndMsg p {
color: #514b64;
margin-top: -8%;
/* margin-top: 1%; */
font-family: 'Roboto', sans-serif;
font-weight: 200;
}
.messageBubleNEWMSG .personNameAndMsg h3 {
color: #e1dbed;
font-family: 'Roboto', sans-serif;
font-weight: 200;
font-size: 15px;
}
.messageBubleNEWMSG .personNameAndMsg p {
color: #736f83;
margin-top: -8%;
font-family: 'Roboto', sans-serif;
font-weight: 500;
/* margin-top: 1%; */
}
.messageTime {
margin-left: auto;
color: #6e6d73;
}
<div class='userChatBubbles'>
<div class='allOfMessage'>
<div class='messageBuble'>
<div class='photo'></div>
<div class='personNameAndMsg'>
<h3>User</h3>
<p> When can we hangout?</p>
</div>
<div class='messageTime'>6m</div>
</div>
</div>
<div class='allOfMessage'>
<div class='messageBubleNEWMSG'>
<div class='photo'></div>
<div class='personNameAndMsg'>
<h3>User 2</h3>
<p> When can we hang out?</p>
</div>
<div class='messageTime'>6m</div>
</div>
</div>
<div class='allOfMessage'>
<div class='messageBuble'>
<div class='photo'></div>
<div class='personNameAndMsg'>
<h3>User 3</h3>
<p> When can we hangout?</p>
</div>
<div class='messageTime'>6m</div>
</div>
</div>
</div>

Related

*ngFor breaks css overflow

I made a list to test the overflow of a div. The problem is, the overflow dont works correct:
Instead of using the overflow scroll, it goes invisible through the div?
This is my html:
<div class="modelSamples">
<div id="samplesTitle">
SAMPLES
</div>
<div class="sampleList">
<div id="samples" *ngFor="let tape of sampeList">
<div id="sampleName"> {{tape.name}} </div>
<div id="samplePlay">
<mat-icon> play_circle </mat-icon>
</div>
</div>
</div>
</div>
</div>
CSS:
.modelSamples{
overflow-y: auto;
margin-top: 10px;
margin-left: 10px;
width: 30%;
height: 60%;
background-color: rgb(191 126 235 / 29%);
z-index: 1;
border-radius: 30px;
}
#samplesTitle{
display: flex;
font-family: Oswald;
width: 100%;
justify-content: center;
margin-top: 20px;
color: white;
font-size: 2rem;
padding-bottom: 15px;
}
#samples{
display: flex;
flex-direction: row;
font-family: Oswald;
color: white;
font-size: 20px;
margin-left: 20px;
justify-content: space-between;
}
#sampleName, #samplePlay{
padding-bottom: 10px;
}
#samplePlay{
padding-right: 30px;
}
I also tried it with using max-height for .sampleList but that also dont work

How to get text to align alongside image if image is larger?

This is my code which works - used vehicle platform - HTML with flex, but isn't quite esthetically pleasing:
body {
font-family: Verdana, sans-serif;
font-size: 16px;
line-height: 18px;
}
header.infog {
background-color: #333;
color: #FFF;
margin-bottom: 25px;
padding: 30px;
}
footer.infog {
background-color: #333;
color: #FFF;
margin-top: 20px;
margin-bottom: 25px;
padding: 10px;
}
.mainwrapper {
border: 2px solid;
display: table;
margin-left: 50px;
width: 900px;
}
.itemwrapper {
display: table-row;
width: 90px;
margin-right: -40px;
}
.itemwrapper1 {
display: table-row;
margin-left: -356em;
width: 100px;
}
.itemwrapper1 img {}
.some-page-wrapper {
margin: 15px;
}
.row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
}
.column {
margin-left: 40px;
width: 600px;
color: #333;
margin: 0;
display: flex;
flex-direction: column;
flex-basis: 100%;
flex: 1;
padding: 20px;
}
.column1 {
margin-left: 40px;
background-color: blue;
color: #FFF;
margin: 0;
display: flex;
flex-direction: row;
flex-basis: 100%;
flex: 1;
padding: 20px;
}
.priceg {
font-size: 29px;
color: red;
padding-left: 500px;
}
.img-nac img {
max-width: 330px;
}
.img-nac1 img {
max-width: 460px;
}
.ncat {
flex-direction: row;
margin-left: -450px;
text-align: right 50px;
}
.ncat1 {
flex-direction: row;
margin-left: -200px;
text-align: right 50px;
}
.at1 {
white-space: nowrap;
margin-top: -20px;
}
.priceh {
margin-left: 180px;
margin-top: -20px;
}
.mainwrapper {
margin-bottom: 20px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Car , Van, Caravan Dealer | Quality Used Cars</title>
<link rel="stylesheet" type="text/css" href="styles/style.css">
</head>
<body>
<header class="infog">
header
</header>
<div class='some-page-wrapper'>
<div class='row'>
<div class='column1'>
2003 TOYOTA RAV4 2.0 GX
</div>
<div class='column1 priceg'>
£8995
</div>
</div>
<div class='row'>
<div class='column img-nac'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/2013_Toyota_RAV4_XLE_AWD_front_left.jpg/1280px-2013_Toyota_RAV4_XLE_AWD_front_left.jpg">
</div>
<div class='column ncat'>
black
</div>
</div>
</div>
<div class='some-page-wrapper'>
<div class='row'>
<div class='column1'>
2003 TOYOTA RAV4 2.0 GX
</div>
<div class='column1 priceg'>
£8995
</div>
</div>
<div class='row'>
<div class='column img-nac1'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/2013_Toyota_RAV4_XLE_AWD_front_left.jpg/1280px-2013_Toyota_RAV4_XLE_AWD_front_left.jpg">
</div>
<div class='column ncat'>
rowtt
</div>
</div>
</div>
<div class='some-page-wrapper'>
<div class='row'>
<div class='column img-nac'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/2013_Toyota_RAV4_XLE_AWD_front_left.jpg/1280px-2013_Toyota_RAV4_XLE_AWD_front_left.jpg">
</div>
<div class='column at1'>
<h3>2004 TOYOTA RAV4 2.0</h4>
black
</div>
<div class='column priceh'>
<h3>£6000</h4>
</div>
</div>
</div>
<footer class="infog">
footer
</footer>
</body>
</html>
The problem is that I'm trying to make it so that if the image is large it's still alongside the text, like this from my page:
The blue line below is actually a bit of the next image... I didn't screencap well.
I've not figured out how to with the CSS and max-width size to do this, resulting in:
The car description in the second flexbox (column and ncat classes) doesn't show up.
But it works fine with the smaller image; I'm trying to make it big enough for people to see.
This isn't the final version, as I'm adding Roboto font etc. in the CSS, but it's almost working.
I'd much appreciate any advice on how to ensure I can get this to work in flexbox.
Just update your CSS with the following code
body {
font-family: Verdana, sans-serif;
font-size: 16px;
line-height: 18px;
}
header.infog {
background-color: #333;
color: #FFF;
margin-bottom: 25px;
padding: 30px;
}
footer.infog {
background-color: #333;
color: #FFF;
margin-top: 20px;
margin-bottom: 25px;
padding: 10px;
}
.mainwrapper {
border: 2px solid;
display: table;
margin-left: 50px;
width: 900px;
}
.itemwrapper {
display: table-row;
width: 90px;
margin-right: -40px;
}
.itemwrapper1 {
display: table-row;
margin-left: -356em;
width: 100px;
}
.some-page-wrapper {
margin: 15px;
}
.row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
}
.column {
margin-left: 40px;
color: #333;
margin: 0;
display: flex;
flex-direction: column;
padding: 20px;
}
.column1 {
margin-left: 40px;
background-color: blue;
color: #FFF;
margin: 0;
display: flex;
flex-direction: row;
flex-basis: 100%;
flex: 1;
padding: 20px;
}
.priceg {
font-size: 29px;
color: red;
padding-left: 500px;
}
.img-nac img {
max-width: 330px;
}
.img-nac1 img {
max-width: 460px;
}
.ncat {
flex-direction: row;
text-align: right 50px;
}
.ncat1 {
flex-direction: row;
text-align: right 50px;
}
.at1 {
white-space: nowrap;
margin-top: -20px;
}
.priceh {
margin-left: 180px;
margin-top: -20px;
}
.mainwrapper {
margin-bottom: 20px;
}

Why cant center the divs within a flexbox model

I am not able to align center the following divs on the full page width:
header
content
footer
But it does not work! Whats needs to be changed within my CSS to get it working?
body {
margin:0;
padding:0;
}
#wrapper {
display: flex;
flex-direction: column;
}
#header {
height: 50px;
}
#hero-wrapper {
background-image: url('https://unsplash.it/1500?random');
background-size: cover;
background-position: center;
width: 100vw;
height: calc(100vh - 50px);
display: flex;
flex-direction: column;
color:#ffffff;
}
#hero {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#hero-text{
font-family:'Roboto';
font-weight:900;
font-size:2em;
text-align:center;
}
#hero-footnote {
font-family: 'Cabin', sans-serif;
font-size: 12px;
padding: 5px 5px 10px 5px;
}
#content {
width: 1024px;
background-color:green;
}
#footer {
font-family: 'Cabin', sans-serif;
weight: 400;
background-color: #ffffff;
/* position: fixed; */
bottom: 0;
left: 0;
width: 100%;
font-size: 0.685em;
color: #1a1717;
padding-bottom: 5px;
}
#footer-info {
width: 1024px;
margin: auto;
padding-left: 3px;
padding-right: 3px;
text-align: left;
line-height: 42px;
}
span#footer-social-icons {
}
span#copyright-info {
font-family: 'Cabin', sans-serif;
weight: 400;
padding-left:10px;
}
span#contact-link {
font-family: 'Source Sans Pro', sans-serif;
weight: 200;
padding-left:10px;
}
<link href="https://fonts.googleapis.com/css2?family=Cabin&family=Source+Sans+Pro:wght#200&family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<div id="wrapper">
<div id="header">header</div>
<div id="hero-wrapper">
<div id="hero">
<div id="hero-text">
<span id="hero-header">sell the product</span><br />
<span id="hero-sub">On this page for less</span>
</div>
</div>
<div id="hero-footnote">© Copyright Text</div>
</div>
<div id="content">
<!-- Content-Loop -->
<div class="article">
Here come the Article
</div>
</div>
<div id="footer">
<div id="footer-info">
<span id="footer-social-icons"></span> <span id="copyright-info">Made with love by Y.</span> <span id="contact-link">Contact</span>
</div>
</div>
</div>
You can add align-items: center; to #wrapper.
Normally if you would have flex-direction: row; centering things would be justify-content: center; but as column change the axis so does the alignment properties. They kinda "go with the axis".
One thing though, I would strongly suggest that you don't style with id, use classes for that.
body {
margin:0;
padding:0;
}
#wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
#header {
height: 50px;
}
#hero-wrapper {
background-image: url('https://unsplash.it/1500?random');
background-size: cover;
background-position: center;
width: 100vw;
height: calc(100vh - 50px);
display: flex;
flex-direction: column;
color:#ffffff;
}
#hero {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#hero-text{
font-family:'Roboto';
font-weight:900;
font-size:2em;
text-align:center;
}
#hero-footnote {
font-family: 'Cabin', sans-serif;
font-size: 12px;
padding: 5px 5px 10px 5px;
}
#content {
width: 1024px;
background-color:green;
}
#footer {
font-family: 'Cabin', sans-serif;
weight: 400;
background-color: #ffffff;
/* position: fixed; */
bottom: 0;
left: 0;
width: 100%;
font-size: 0.685em;
color: #1a1717;
padding-bottom: 5px;
}
#footer-info {
width: 1024px;
margin: auto;
padding-left: 3px;
padding-right: 3px;
text-align: left;
line-height: 42px;
}
span#footer-social-icons {
}
span#copyright-info {
font-family: 'Cabin', sans-serif;
weight: 400;
padding-left:10px;
}
span#contact-link {
font-family: 'Source Sans Pro', sans-serif;
weight: 200;
padding-left:10px;
}
<link href="https://fonts.googleapis.com/css2?family=Cabin&family=Source+Sans+Pro:wght#200&family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght#400;500;900&display=swap" rel="stylesheet">
<div id="wrapper">
<div id="header">header</div>
<div id="hero-wrapper">
<div id="hero">
<div id="hero-text">
<span id="hero-header">sell the product</span><br />
<span id="hero-sub">On this page for less</span>
</div>
</div>
<div id="hero-footnote">© Copyright Text</div>
</div>
<div id="content">
<!-- Content-Loop -->
<div class="article">
Here come the Article
</div>
</div>
<div id="footer">
<div id="footer-info">
<span id="footer-social-icons"></span> <span id="copyright-info">Made with love by Y.</span> <span id="contact-link">Contact</span>
</div>
</div>
</div>
If you just want to center the text, use text-align: center and the parts?
Or if you are looking to do more centered-content, maybe make your #header, #content, and #footer the following:
display: flex;
flex-direction: column;
align-items: center;
Basically, flex boxes within flex boxes.

Positioning text and image as centered horizontally using position: relative

I was wondering how I can position the text centered horizontally. Centered horizontally with the image. I do not want to use the position: absolute attribute. This is because the length of the right and left text can change and to have an absolute attribute, you need a fixed width/size.
body {
padding: 0;
margin: 0;
}
.right-text {
position: relative;
display: inline-block;
font-family: arial;
font-size: 13px;
}
.icon {
position: relative;
display: inline-block;
width: 32px;
height: 32px;
background: url("https://i.imgur.com/VXlnn8a.png");
}
.left-text {
position: relative;
display: inline-block;
font-family: arial;
font-size: 13px;
font-weight: 700;
}
<div class="right-text">Right</div><div class="icon"></div><div class="left-text">Left</div>
You can use flexbox to align items horizontally center by adding below code to the parent div
.parent{
display:flex;
align-items: center;
}
This is the running Snippet of your code having this changes
body{
padding: 0;
margin: 0;
font-family: arial;
}
.content{
display: flex;
align-items: center;
}
.right-text {
font-size: 13px;
}
.icon {
width: 32px;
height: 32px;
background: url("https://i.imgur.com/VXlnn8a.png");
}
.left-text {
font-size: 13px;
font-weight: 700;
}
<div class="content">
<div class="right-text">Right</div>
<div class="icon"></div>
<div class="left-text">Left</div>
</div>
You can just simply add a flexbox container and set its property align-items to center.
<div class="container">
<div class="right-text">Right</div>
<div class="icon"></div>
<div class="left-text">Left</div>
</div>
And this is the class container:
.container{
display: flex;
align-items: center;
justify-content: center;
}
Hi If you want vertical align here is the updated snippet
body {
padding: 0;
margin: 0;
}
.right-text {
position: relative;
display: inline-block;
font-family: arial;
font-size: 13px;
}
.icon {
position: relative;
display: inline-block;
width: 32px;
height: 32px;
background: url("https://i.imgur.com/VXlnn8a.png");
top: 10px;
margin: 0 5px;
}
.left-text {
position: relative;
display: inline-block;
font-family: arial;
font-size: 13px;
font-weight: 700;
}
<div class="right-text">Right</div><div class="icon"></div><div class="left-text">Left</div>
You actually need to wrap your right-text, icon and left-text element in childContainer and then wrap your childContainer element in parentContainer wrap.
<div class="parentContainer">
<div class="childContainer">
<div class="right-text">Right</div><div class="icon"></div><div class="left-text">Left</div>
</div>
</div>
Next, you have to apply FlexBox with center justify-content and align-items value and you also need to add height: 100vh. Mentioned changes are applied on a below code snippet. Try this I hope it'll help you out. Thanks
body {
padding: 0;
margin: 0;
}
.right-text {
position: relative;
display: inline-block;
font-family: arial;
font-size: 13px;
}
.icon {
position: relative;
display: inline-block;
width: 32px;
height: 32px;
background: url("https://i.imgur.com/VXlnn8a.png");
}
.left-text {
position: relative;
display: inline-block;
font-family: arial;
font-size: 13px;
font-weight: 700;
}
.parentContainer {
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
}
<div class="parentContainer">
<div class="childContainer">
<div class="right-text">Right</div><div class="icon"></div><div class="left-text">Left</div>
</div>
</div>

flexbox: vertically center two divs

I have a modal in the center of the screen that has an header.
That header must contain a title and the button to close it.
--------------------------------
| (close)|
| Text |
| |
--------------------------------
So basically I have two requirements:
Every text inside the header must be centred vertically.
Be able to position the "(close)" close to the header in the corner.
Right now I have everything vertically centred but the elements I put inside the header for ma pile:
--------------------------------
| |
| Text |
| (close) |
| |
--------------------------------
.modal-payment__wrapper { // <- this is the whole box
max-width: 50%;
width: 500px;
height: 200px;
background: white;
font-family: 'Lato', 'sans-serif';
}
.modal__header { // <- this is the header
display: flex;
justify-content: center;
flex-direction: column;
width: 100%;
height: 50px;
background-color: black;
color: white;
font-size: 16px;
padding-left: 20px;
}
.modal__header__title { // <- this is "text"
text-transform: uppercase;
letter-spacing: 2px;
font-size: 1.7em;
padding: 10px;
flex-grow: 0;
flex-srhink: 0;
flex-basis: auto;
align-self: auto;
}
<div class="modal-payment__background">
<div class="modal-payment__wrapper">
<div class="modal__header">
<div>
Text
</div>
<div class="modal__header__x"
#click="closeModal">
x
</div>
</div>
<div class="modal__body">
What am I missing?
There were quite a few errors in the code provided, but I think this is what you need. I had to remove the #click since that's not recognized here.
.modal-payment__wrapper {
max-width: 50%;
width: 500px;
height: 200px;
background: white;
font-family: 'Lato', 'sans-serif';
}
.modal__header {
width: 100%;
height: 50px;
background-color: black;
color: white;
font-size: 16px;
padding-left: 20px;
position: relative;
display: flex;
align-items: center;
}
.modal__header__title {
text-transform: uppercase;
letter-spacing: 2px;
font-size: 1.7em;
}
.modal__header__x {
position: absolute;
right: .5em;
top: 0;
}
<div class="modal-payment__background">
<div class="modal-payment__wrapper">
<div class="modal__header">
<div class="modal__header__title">
Text
</div>
<div class="modal__header__x">
x
</div>
</div>
</div>
</div>
Yuo can do it like this. See comments in code to get where you are doing mistakes are what was left.
.modal-payment__wrapper {
max-width: 50%;
width: 500px;
height: 200px;
background: white;
font-family: 'Lato', 'sans-serif';
}
.modal__header {
display: flex; // You need this
justify-content: center;
flex-direction: row; // You need this
width: 100%;
height: 50px;
background-color: black;
color: white;
font-size: 16px;
padding-left: 20px;
}
// You will need below css
.modal__header > div{
justify-content: space-around;
width: 50%;
align-self: center;
}
.modal__header__title { // <- this is "text"
text-transform: uppercase;
letter-spacing: 2px;
font-size: 1.7em;
padding: 10px;
flex-grow: 0;
flex-shrink: 0; // Spelling mistake
flex-basis: auto;
align-self: auto;
}
.modal__header__x{
color: #fff; // You need this
}
<div class="modal-payment__background">
<div class="modal-payment__wrapper">
<div class="modal__header">
<div class="modal__header__title">
Text
</div>
<div class="modal__header__x"
#click="closeModal">
x
</div>
</div>
<div class="modal__body">
BODY
</div> <!-- Missing /div in your code -->
</div> <!-- Missing /div in your code -->
</div> <!-- Missing /div in your code -->