Flexbox layout - aligning element at the edge of one another - html

I'm creating a react component, but I don't know how to lay out the items.
It currently looks like this because of the Audio component:
I want both of the images to be aligned vertically to one another, like this:
#finish-content {
width: 100%;
position: relative;
border: 1px solid black;
border-radius: 25px;
margin-left: 1.5rem;
text-align: center;
}
.game-finish-flex {
display: flex;
flex-direction: column;
}
.game-finish-upper {
display: flex;
justify-content: center;
}
.game-finish-image, .game-finish-image-secundar {
border-radius: 15px;
}
.game-finish-image {
margin-top: 1rem;
width: 300px;
height: 200px;
}
.game-finish-image-secundar {
width: 300px;
height: 150px;
}
.message-finish {
border: 1px solid black;
border-radius: 1.5rem;
width: 50%;
margin: 1.5rem auto;
height: 2.5rem;
width: 300px;
line-height: 2.5rem;
}
.circle-audio {
color: #fff;
border: 1px solid black;
border-radius: 50%;
}
.fa-stack-custom {
cursor: pointer;
margin-left: 1rem;
}
span.audio-gameinfo {
margin-left: 0rem;
margin-bottom: 0.5rem;
}
.audio-finish {
margin-top: 1rem;
}
.game-details-image {
margin-top: 2rem;
border-radius: 15px;
width: 15rem;
height: 15rem;
}
.game-answers-image {
border-radius: 15px;
width: 15rem;
height: 15rem;
margin: 0 !important;
padding: 0 !important;
}
.draggable-game-image {
border-radius: 15px;
margin: 0 1rem 1rem 1rem;
}
#media (max-width: 800px)
{
.game-answers-image {
width: 12rem;
height: 12rem;
}
}
<div id="quiz-container">
<div class="row">
<div id="finish-content">
<div class="game-finish-flex">
<div class="game-finish-upper">
<div class="game-image-wrapper"><img class="game-finish-image" src="/Untitled.png" alt="test"></div>
<span class="fa-stack fa-stack-custom audio-finish"><i
class="far fa-circle fa-stack-2x circle-audio"></i><i
class="fa fa-volume-up fa-stack-1x"></i></span>
</div>
<div class="message-finish">test</div>
<div class="game-image-wrapper"><img class="game-finish-image-secundar" src="/Untitled.png" alt="test">
</div>
</div><button class="btn btn-outline-success next-button">Next</button>
</div>
</div>
</div>
How can I change the layout to look like in the second picture, without deleting the Audio component?
Thanks.

from the looks of your code and the picture. Let me walk through my solution to the problem. Get rid of the audio component as it is interrupting with the flow of the box you want to align. Second, make sure both the images are the same width, which can be done as a percentage of the parent container. Now, I'm assuming you still want that audio component on your site, so a couple of solutions can be:
Position this audio box inside the div of the upper image. Use negative margins/positioning to make sure it stays at the right of this box. This can be achieved using something like position:absolute, right:0, margin-right: -10%, transform: translateX(10%).
Make the parent container width: 50%, margin: 0 auto. So it's center. Now align-items: flex-start. This will make the first items aligned, as flexbox isn't trying to center them by distributing their individual widths and space around them.

Can the audio icon be anywhere? IF so, try this snippet.
#finish-content {
border: 1px solid black;
border-radius: 25px;
margin-left: 1.5rem;
text-align: center;
}
.game-finish-flex {
display: flex;
flex-direction: column;
justify-content: center;
}
.game-finish-upper {
display: flex;
justify-content: center;
}
.game-finish-image,
.game-finish-image-secundar {
border-radius: 15px;
}
.game-finish-image {
margin-top: 1rem;
width: 300px;
height: 200px;
}
.game-finish-image-secundar {
width: 300px;
height: 150px;
}
.message-finish {
border: 1px solid black;
border-radius: 1.5rem;
width: 50%;
margin: 1.5rem auto;
height: 2.5rem;
width: 300px;
line-height: 2.5rem;
}
.circle-audio {
color: #fff;
border: 1px solid black;
border-radius: 50%;
}
.fa-stack-custom {
cursor: pointer;
margin-left: 1rem;
}
span.audio-gameinfo {
margin-left: 0rem;
margin-bottom: 0.5rem;
}
.audio-finish {
position: relative;
display: flex;
top: 60px;
right: -50px;
align-content: flex-end;
justify-content: flex-end;
}
.game-details-image {
margin-top: 2rem;
border-radius: 15px;
width: 15rem;
height: 15rem;
}
.game-answers-image {
border-radius: 15px;
width: 15rem;
height: 15rem;
margin: 0 !important;
padding: 0 !important;
}
.draggable-game-image {
border-radius: 15px;
margin: 0 1rem 1rem 1rem;
}
#media (max-width: 800px) {
.game-answers-image {
width: 12rem;
height: 12rem;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css"
integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<title>home</title>
</head>
<body>
<div id="quiz-container">
<div class="row">
<div id="finish-content">
<div class="game-finish-flex">
<div class="game-finish-upper">
<div class="game-image-wrapper">
<div class="audio-finish">
<span class="fa-stack fa-stack-custom">
<i class="far fa-circle fa-stack-2x circle-audio"></i>
<i class="fa fa-volume-up fa-stack-1x"></i>
</span>
</div>
<img class="game-finish-image" src="https://i.stack.imgur.com/Rkwue.png" alt="test">
</div>
</div>
<div class="message-finish">test</div>
<div class="game-image-wrapper"><img class="game-finish-image-secundar"
src="https://i.stack.imgur.com/4QcJ1.png" alt="test">
</div>
</div>
<button class="btn btn-outline-success next-button">Next</button>
</div>
</div>
</div>
</body>
</html>

Related

Make spacing independent of other elements (CSS)

I have a logo on the far left. There is a div container in the middle and a div container on the far left. All packed together in a div container.
I have the middle container on margin: auto; adjusted so that it has the same distance on both sides.
The problem is that if I move the logo left or right, the middle container also moves. How can I ensure that the middle container always stays in the middle no matter what happens left or right?
body {
margin: 0%;
font-family: Arial, Helvetica, sans-serif;
}
.container1 {
height: 70px;
background-color: #e7e0e0;
display: flex;
justify-content: space-between;
align-items: center;
}
.container12 {
margin-left: 50px;
}
.container12 h1 {
font-size: 20px;
}
.container13 {
margin-right: 25px;
}
.container13 a {
margin: 0%;
text-decoration: none;
color: black;
float: inline-start;
}
.container13 a:hover {
text-decoration: underline;
}
.trennlinie {
border-right: 1px solid grey;
padding-top: 15px;
padding-bottom: 15px;
padding-right: 12.5px;
}
.trennliniehilfe {
padding-left: 12.5px;
padding-top: 15px;
padding-bottom: 15px;
}
.container2 {
height: 80px;
border-bottom: 1px solid rgb(187, 187, 187);
display: flex;
align-items: center;
}
.airbnblogo {
width: 50px;
}
.airbnbcont {
margin-left: 110px;
;
}
.mittecontainer {
display: flex;
margin: auto;
float: inline-start;
background-color: rgb(214, 212, 212);
border: 2px solid black;
border-radius: 15px;
padding-right: 5px;
}
.mittecontainer p {
margin-left: 11.5px;
}
.part3 {
display: flex;
align-items: center;
margin-right: 35px;
}
.derretter {
margin-right: 15px;
}
.interneticon {
margin-right: 15px;
width: 30px;
}
.Pics img {
width: 250px;
vertical-align: middle;
}
.Pics {
display: flex;
justify-content: center;
margin-top: 80px;
border: 2px solid white;
}
.p1 {
border-right: 1px solid grey;
padding-right: 12.5px;
}
.p2 {
border-right: 1px solid grey;
padding-right: 12.5px;
}
.Pics p {
display: flex;
justify-content: center;
}
.pics2 {
background-color: black;
padding-right: 10px;
padding-left: 10px;
padding-top: 10px;
border-radius: 10px;
}
.pics2 p {
background-color: black;
color: white;
border: 2px solid white;
border-radius: 15px;
padding: 5px;
}
.pics2 p:hover {
background-color: white;
color: black;
}
.ia {
width: 30px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Airbnb.com</title>
</head>
<body>
<div class="container1">
<div class="container12">
<h1>Hier kommt das Airbnb 2022: Winter-Update</h1>
</div>
<div class="container13">
<a class="trennlinie" href="">Film abspielen</a>
<a class="trennliniehilfe" href="">Alle Neuigkeiten entdecken</a>
</div>
</div>
<div class="container2">
<div class="airbnbcont">
<img class="airbnblogo" src="airbnb.png">
</div>
<div class="mittecontainer">
<p class="p1">Irgendwo</p>
<p class="p2">Eine Woche</p>
<p>Gäste hinzufügen</p>
</div>
<div class="part3">
<div class="derretter">
<p>Als Gastgeber:in loslegen</p>
</div>
<div class="interneticon">
<img class="ia" src="internet.png" alt="">
</div>
<div>
<img class="ia" src="menu.png" alt="">
</div>
</div>
</div>
<div class="Pics">
<div class="pics2">
<img src="din1.jpg"> <br>
<p>Jetzt Flug sichern!</p>
<p>Weitere Infos</p>
<p>Standort</p>
</div>
</div>
</body>
</html>
Inside the container2 class in the style tag, replace display: flex; to be display: grid; and add grid-template-columns: 25% 50% 25%;. Like this:
.container2 {
height: 80px;
border-bottom: 1px solid rgb(187, 187, 187);
display: grid;
grid-template-columns: 25% 50% 25%;
align-items: center;
}
And don't forget if there are too many CSS styles, then make an external CSS link so that giving css styles is easier.

Why does the image within the box shrink upwards when the window shrinks?

I really don't know what I'm doing wrong here. I want the image inside the box to stay centered when the window shrinks. Furthermore, I would have thought that align-items: center; would work, but apparently not. The colors are only relevant for me, so I understand what's going on. I don't know if there is a solution for this either, but I hope so. And please ignore the naming and order of the individual classes, I couldn't do better ...:)
.megadiv {
max-width: 1600px;
margin: auto;
text-align: center;
}
.centerbox {
display: flex;
justify-content: space-between;
}
.left {
width: 64%;
background-color: red;
justify-content: space-between;
border: 2px solid gray;
display: flex;
}
.insideleft {
width: 20%;
background-color: yellow;
align-items: center;
text-align: center;
align-content: center;
}
.insideright {
width: 78%;
background-color: purple;
float: right;
padding-top: 2%;
text-align: left;
border-left: 2px ridge #ffa54f;
padding-left: 2%;
padding-bottom: 1%;
}
.picture {
width: 80%;
border-radius: 1%;
margin-top: 10%;
margin-bottom: 8%;
}
.right {
width: 34%;
border: 2px solid gray;
height: 20px;
}
h7 {
color: rgb(0, 153, 158);
font-size: large;
font-family: sans-serif;
}
.textpart {
margin-bottom: 0.5%;
}
<div class="megadiv">
<div class="centerbox">
<div class="left">
<div class="insideleft">
<h20>
<a href="">
<img class="picture" src="https://images-na.ssl-images-amazon.com/images/I/71hi8fWdX2L.jpg"> </a>
</h20>
</div>
<div class="insideright">
<h7>Headline</h7><br>
<h4>
<div class="textpart">Authors</div>
<div class="textpart">Views <a class="" href="">Chapter 2</a></div>
<div class="textpart">Genres: Action - Adventure - Comedy</div>
<div class="textpart">Rating: ⭐⭐⭐⭐⭐</div>
</h4>
</div>
<div class="right">
wawaeaweew
</div>
</div>
</div>
h4 and h20 are empty
You're pretty close to getting the image vertically aligned as you wanted. Try this out, and see if this works the way you would like:
.megadiv {
max-width: 1600px;
margin: auto;
text-align: center;
}
.centerbox {
display: flex;
justify-content: space-between;
}
.left {
width: 64%;
background-color: red;
justify-content: space-between;
border: 2px solid gray;
display: flex;
}
.insideleft {
display: flex;
width: 20%;
background-color: yellow;
align-items: center;
text-align: center;
align-content: center;
}
.insideright {
width: 78%;
background-color: purple;
float: right;
padding-top: 2%;
text-align: left;
border-left: 2px ridge #ffa54f;
padding-left: 2%;
padding-bottom: 1%;
}
.picture {
width: 80%;
border-radius: 1%;
margin-top: 10%;
margin-bottom: 8%;
}
.right {
width: 34%;
border: 2px solid gray;
height: 20px;
}
h7 {
color: rgb(0, 153, 158);
font-size: large;
font-family: sans-serif;
}
.textpart {
margin-bottom: 0.5%;
}
<div class="megadiv">
<div class="centerbox">
<div class="left">
<div class="insideleft">
<a href="">
<img class="picture" src="https://images-na.ssl-images-amazon.com/images/I/71hi8fWdX2L.jpg"> </a>
</div>
<div class="insideright">
<h7>Headline</h7><br>
<h4>
<div class="textpart">Authors</div>
<div class="textpart">Views <a class="" href="">Chapter 2</a></div>
<div class="textpart">Genres: Action - Adventure - Comedy</div>
<div class="textpart">Rating: ⭐⭐⭐⭐⭐</div>
</h4>
</div>
<div class="right">
wawaeaweew
</div>
</div>
</div>
I saw you used align-items: center; in the .insideleft CSS selector which is for aligning a container's children to the center like you want, you'll just want to make this a flexbox to make this work. To do this, simply add display: flex; to the .insideleft selector like in the example. I also removed the <h20> tag from the HTML as this is not valid or necessary.
As for the image shrinking down when the screen width is shrinked - this is because you're using percentages for the widths for all the containers and the image. If you want the image to stop shrinking after a certain point, you can add min-width: 80px; /* (this can be any number of pixels) */ to your .picture selector to make the image stop shrinking once it gets to a certain width of pixels.
Flexbox is super useful for position elements in CSS and I'd recommend looking into this more to have a better understanding. Check out this link here if you'd like an overview of the different flexbox CSS properties.
I am not 100% sure on your intent - Here I changed the class names a bit for clarity and adjusted the markup for a left-middle-right
Not a huge fan of % for padding and margin sizing myself (em feels more clear since it is based on the current font size)
Not strictly needed but I added the containing element class in a few places in CSS for clarity example: .left-pane .picture-container
.page-container {
max-width: 1600px;
text-align: center;
}
.container-box {
display: flex;
align-content: space-between;
}
.container-box .left-pane {
width: 20em;
display: flex;
align-items: center;
justify-content: center;
background-color: #FF0000;
border: 2px solid gray;
}
.left-pane .picture-container {
width: 30%;
background-color: yellow;
align-items: center; /* vertical */
align-content: center; /* horizontal */
}
.left-pane .picture-container .picture {
width: 80%;
border-radius: 1%;
margin-top: 10%;
margin-bottom: 8%;
}
.container-box .middle-pane {
width: 70em;
background-color: #FFDDDD;
padding-top: 2%;
padding-left: 2%;
padding-bottom: 1%;
border-left: 2px ridge #ffa54f;
}
.middle-pane .headline {
color: rgb(0, 153, 158);
font-size: 1.5em;
font-family: sans-serif;
margin-bottom: 1em;
background-color: #eeeeee;
}
.middle-pane .textpart {
margin-bottom: 0.5em;
}
.container-box .right-pane {
height: 20px;
border: 2px solid gray;
}
<div class="page-container">
<div class="container-box">
<div class="left-pane">
<div class="picture-container">
<div>
<a href="">
<img class="picture" src="https://images-na.ssl-images-amazon.com/images/I/71hi8fWdX2L.jpg"> </a>
</div>
</div>
</div>
<div class="middle-pane">
<div class="headline">Headline</div>
<h4>
<div class="textpart">Authors</div>
<div class="textpart">Views <a class="" href="">Chapter 2</a></div>
<div class="textpart">Genres: Action - Adventure - Comedy</div>
<div class="textpart">Rating: ⭐⭐⭐⭐⭐</div>
</h4>
</div>
<div class="right-pane">
wawaeaweew
</div>
</div>
</div>

How can I line up this button better with the content in the middle? It seems off center to me:

margin-top on the button itself may be the answer but it feels wrong to me. If it is hopefully an answer will confirm. What is the best solution to lower the button a smidgen?
The codepen for extra context: https://codepen.io/AdanRod133/full/WNZEYJX
body {
font-family: "Poppins", sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: coral;
display: grid;
grid-template-columns: 100px 300px 115px;
grid-row-gap: 1em;
justify-content: space-around;
align-items: center;
width: 50%;
height: 100px;
padding: 10px;
}
img {
width: 100%;
height: 100%;
background-color: #2D8C9E;
}
.btn-learn {
justify-self: center;
align-self: center;
height: 40px;
border: none;
border-radius: 10px;
width: 125px;
}
.body-title {
font-size: 1.15em;
line-height: 1.5em;
font-weight: bold;
justify-self: center;
}
.text-body {
font-size: 16px;
grid-column: 3 / 5;
}
<div class="container">
<img src="" alt="">
<div class="content">
<h3 class="body-title">
Startup
</h3>
<p class="text-body">Create Websites Online using the Startup Boostrap 5 builder</p>
</div>
<button class="btn btn-learn">Learn More <i class="fas fa-arrow-right"></i></button>
</div>
I have wrapped your button in a flex container and used its property align-items: center
There were also some styling changes I have made
you have made three column in grid with 100px 300px and 100px
but assigned the button with width: 125px that will make the styling error
<div class="container">
<img src="" alt="">
<div class="content">
<h3 class="body-title">
Startup
</h3>
<p class="text-body">Create Websites Online using the Startup Boostrap 5 builder</p>
</div>
<div class="button-container">
<button class="btn btn-learn">Learn More <i class="fas fa-arrow-right"></i></button>
</div>
</div>
body{
font-family: "Poppins", sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container{
background-color: coral;
display: grid;
grid-template-columns: 100px 300px 125px;
grid-row-gap: 1em;
justify-content: space-between;
align-items: center;
width: 40%;
height: 90px;
padding: 5px 20px;
}
img{
width: 100%;
height: 100%;
background-color: #2D8C9E;
}
.btn-learn{
/* justify-self: center; */
/* align-self: center; */
height: 40px;
border: none;
border-radius: 10px;
width: 100%;
/* margin-top: 16px; */
}
.body-title{
font-size: 1.15em;
line-height: 1.5em;
font-weight: bold;
justify-self: center;
}
.text-body{
font-size: 16px;
grid-column: 3 / 5;
}
.button-container
{
height: 100%;
margin: 0;
padding: 0;
display: flex;
align-items:center
}
You should restructure your div in a better way. For example, I think you are looking for content box like this:
I would suggest you to use Bootstrap if you are new to front-end web development.
Here is an example of how your Bootstrap-5 code looks.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<title>Hello, world!</title>
<style>
body {
font-family: "Poppins", sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
img {
width: 100%;
height: 100%;
background-color: #2d8c9e;
}
.btn-learn {
justify-self: center;
align-self: center;
height: 40px;
border: none;
border-radius: 10px;
width: 125px;
}
.body-title {
font-size: 1.15em;
line-height: 1.5em;
font-weight: bold;
justify-self: center;
}
.text-body {
font-size: 16px;
grid-column: 3 / 5;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-2">
<img src="" alt="" />
</div>
<div class="col-8">
<h3 class="body-title">Startup</h3>
<p class="text-body">Create Websites Online using the Startup Boostrap 5 builder</p>
</div>
<div class="col-2 d-flex flex-column justify-content-center">
<button class="btn btn-learn">Learn More <i class="fas fa-arrow-right"></i></button>
</div>
</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"
></script>
</body>
</html>
Here is the css file .
body {
font-family: "Poppins", sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: coral;
display: flex;
flex-wrap:no-wrap;
justify-content: space-between;
align-items: center;
width: 80%;
height: 100px;
padding: 10px;
}
img {
width: 100px;
height: 100px;
background-color: #2D8C9E;
}
.content {
padding:0% 2%;
}
.body-title {
font-size: 1.15em;
line-height: 1.5em;
font-weight: bold;
justify-self: center;
}
.text-body {
font-size: 16px;
grid-column: 3 / 5;
}
.btn-learn {
height: 40px;
border: none;
border-radius: 10px;
width: 125px;
}
And html file like this
<div class="container">
<img src="" alt="">
<div class="content">
<h3 class="body-title">
Startup
</h3>
<p class="text-body">
Create Websites Online using the Startup Boostrap 5 builder
</p>
</div>
<button class="btn btn-learn">
Learn More
<i class="fas fa-arrow-right"></i>
</button>
</div>
Here is the result: https://codepen.io/AdanRod133/full/WNZEYJX
.btn-learn{
position: relative;
height: 40px;
border: none;
border-radius: 5px;
background-color: #00A57F;
color: #D8D7DF;
height: 2.5em;
padding: 10px 25px;
outline: none;
cursor: pointer;
display: inline-block;
justify-self: end;
transition: all .2s ease-in-out;
}
I got rid of the width and set the button to inline-block. Then added some padding.
I wanted to make something css-grid only in order to get more practice in.
Working with the padding as well as adding grid gap allowed the items to
sit where I wanted them to.

Making two circles to come on top of the vertical line in CSS

I want to make the orange and the blue circles on the top of the line going in-between.
.content-wrap {
border-left: 1px dashed black;
height: 5em;
position: absolute;
}
.content-wrap::before {
position: absolute;
top: calc(50% - 1px);
right: 0;
left: 0;
Content: "";
border: none;
height: 2px;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="content-wrap">
<font-awesome-icon class="icon1" fixed-width icon="dot-circle" />
<font-awesome-icon class="icon2" fixed-width icon="map-marker-alt" />
</div>
Current output:
Desired Output:
I did not use befoe:: effect.see if this helps.
.content-wrap {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: min-content;
margin: 0 auto;
padding: 2rem;
border-radius: 0.25rem;
background: #3e3e3e;
}
.circle {
color: pink;
font-size: 1.25rem;
}
.dotted {
border-left: 0.125rem dashed #f0f0f0;
height: 8rem;
}
.marker {
color: lightblue;
font-size: 1.25rem;
}
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<body>
<div class="content-wrap">
<i class="fas fa-dot-circle circle"></i>
<div class="dotted"></div>
<i class="fa fa-map-marker marker" aria-hidden="true"></i>
</div>
</body>

Absolute div inside flexbox div behaving like fixed

I'm designing a responsive chat page view on react and i'm struggling with the following problem.
I have a div menu with absolute position which is displayed on top of all the elements when click the menu button as you can see here:
Everything seems ok, even when i resize the screen to phone dimentions it displays as i expect because i have a media query which modifies the left property to fit the div where i want. But on the phone view, when i scroll the page the div moves in its offset position along the screen and i couldn't fixing it:
As far i know this behavior corresponds to fixed position, i've got understood that if i apply an absolute position the div should stays on his place. But i don't know what is happening here. Maybe it may be messing up it because i'm working with flex (everything is positioned with flex using its direction property to arrange my elements).
This is my JSX code:
return (
<div id="chat-page-main-container" onClick={onMainContainerClick}>
<div id="chat-main-menu-select" style={{ display: displayMenu }}>
<ul className="list-group">
<li className="list-group-item">Profile</li>
<li className="list-group-item">Create new group</li>
<li className="list-group-item">Log out</li>
</ul>
</div>
<div id="chat-left-side-content">
<div id="chat-main-menu">
<img
src="https://upload.wikimedia.org/wikipedia/commons/e/e8/The_Joker_at_Wax_Museum_Plus.jpg"
alt="unavailable"
/>
<div id="chat-main-menu-options">
<div className="main-menu-options-icons">
<i id="chat-comment-icon" className="fa fa-comments"></i>
</div>
<div
className="main-menu-options-icons"
style={{ backgroundColor: selectedItem }}
>
<i
id="chat-menu-icon"
className="fa fa-bars"
onClick={onMenuIconClick}
></i>
</div>
</div>
</div>
<div id="search-conversation-bar">
<i className="fa fa-search"></i>
<input type="text" placeholder="Search for a conversation" />
</div>
<div id="chats-component-container">
{data.map((object, index) => (
<ChatCard key={index} data={object} />
))}
</div>
</div>
<div id="chat-right-side-content">
<div id="conversation-splash-screen">
<img src={conversationImage} alt="unavailable" />
<h3>Welcome to tellit chat page!</h3>
<p>
You can search for a contact or a conversation on the left menu.
</p>
</div>
</div>
</div>
);
And this is my SASS code:
::-webkit-scrollbar {
width: 8px
}
::-webkit-scrollbar-track {
background: whitesmoke;
}
::-webkit-scrollbar-thumb {
background: #bababa;
}
#chat-page-main-container {
display: flex;
flex-direction: row;
height: 100%;
overflow-x: auto;
white-space: nowrap;
#chat-main-menu-select {
position: absolute;
top: 4em;
left: 12em;
ul {
border-radius: 5px;
cursor: pointer;
}
li:hover {
background-color: #ededed;
}
}
#chat-left-side-content {
display: flex;
flex-direction: column;
min-width: 400px;
height: 100%;
border-right: solid 1px #bababa;
#chat-main-menu {
width: 100%;
height: 71px;
padding: 10px 25px;
border-bottom: solid 1px #bababa;
background-color: #EDEDED;
img {
width: 50px;
height: 50px;
border-radius: 50%;
float: left;
}
#chat-main-menu-options {
display: flex;
flex-direction: row;
float: right;
height: 100%;
padding-top: 5px;
.main-menu-options-icons {
font-size: 25px;
opacity: 0.5;
text-align: center;
width: 40px;
border-radius: 50%;
margin: 0 10px;
i {
cursor: pointer;
}
}
}
}
#search-conversation-bar {
display: flex;
flex-direction: row;
justify-content: center;
width: 100%;
background-color: #EDEDED;
padding: 10px 0;
border-bottom: solid 1px #bababa;
input {
border-radius: 30px;
border: none;
width: 85%;
height: 40px;
font-family: "Segoe UI";
font-size: 13px;
padding: 0 43px;
&:focus {
outline: none;
}
}
i {
font-size: 20px;
position: relative;
left: 30px;
top: 10px;
}
}
#chats-component-container {
overflow-y: auto;
overflow-x: hidden;
}
}
#chat-right-side-content {
display: flex;
flex-direction: row;
justify-content: center;
width: 100%;
height: 100%;
background-color: white;
#conversation-splash-screen {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 5em;
img {
width: 30em;
height: 30em;
}
}
}
}
#media (max-width: 500px) {
#chat-left-side-content {
min-width: 300px !important;
}
#chat-right-side-content {
min-width: 600px !important;
#conversation-splash-screen {
padding-top: 3em !important;
}
}
#chat-main-menu-select {
left: 6em !important;
}
}
Another fact i want to add is that i also tried to change the absolute position to relative, but this last mess up the container div displaying a space blank or rearranging the elements inside.
Any suggestion or code correction is welcome. Thank you.
set position: relative for parent (#chat-page-main-container)