Property scrollbar-width not working in css - html

I'm trying to set the width of the scrollbar to 'thin' and 'none', neither of them are working. I have also tried using -webkit-
NOTE: I'VE SET THE OVERFLOW TO 'AUTO', IS IT THAT THE SCROLLBAR-WIDTH PROPERTY IS NOT WORKING?
The following is my HTML:
<div class="chat__chatting">
<div class="chat__scrollable-chat">
<div class="chat__chatting__header">
<div class="chat__chatting__header--img">
<img src="../../assets/person.png" />
</div>
<div class="chat__chatting__header--descr">
<div class="chat__chatting__header--name">Alexender</div>
<div class="chat__chatting__header--location">Birmingham, United Kingdom</div>
<div class="chat__chatting__header--age">Age 24</div>
</div>
</div>
<div class="chat__chatting__body">
<div class="chat__chatting__body--rcv-msg">
<div class="chat__chatting__body--rcv-msg--img">
<img src="../../assets/person.png" />
</div>
<div class="chat__chatting__body--rcv-msg---text">How are you?</div>
</div>
<div class="chat__chatting__body--sent-msg">
<div class="chat__chatting__body--sent-msg--img">
<img src="../../assets/person.png" />
</div>
<div class="chat__chatting__body--sent-msg---text">I'm fine</div>
</div>
</div>
</div>
<div class="chat__chatting__footer">
<textarea rows="1" class="chat__chatting__footer--textfield"></textarea>
<div class="chat__chatting__footer--send-btn">
<img src="../../assets/send.svg" />
</div>
</div>
</div>
And SCSS:
.chat{
&__scrollable-chat {
overflow-y: auto;
flex-grow: 1;
scrollbar-width: none;
}
&__chatting {
border-radius: 4px;
flex: 3;
height: 100%;
background-color: #fff;
display: flex;
flex-flow: column;
flex-grow: 3;
&__header {
display: flex;
flex-direction: row;
justify-content: center;
padding: 2rem 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
&--img {
width: 11rem;
height: 11rem;
overflow: hidden;
border-radius: 50%;
overflow: hidden;
margin-right: 1.5rem;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
}
&--descr {
padding-top: 1rem;
}
&--name {
font-size: 2.2rem;
color: $color-text;
padding-bottom: 0.6rem;
}
&--location,
&--age {
color: rgb(163, 163, 163);
font-size: 1.5rem;
display: block;
}
}
&__footer {
background-color: #f9f9f9;
display: flex;
flex-direction: row;
padding: 1rem 3rem;
position: sticky;
left: 0;
bottom: 0;
align-items: stretch;
&--textfield {
border: 1px solid rgba(0, 0, 0, 0.1);
resize: none;
font-size: 1.7rem;
font-family: "Lato", sans-serif;
padding: 7px 1.4rem;
color: $color-text;
outline: none;
width: 100%;
scrollbar-width: none;
border-radius: 15px;
max-width: 100%;
margin-right: 1.2rem;
}
&--send-btn {
width: 4rem;
height: 4rem;
img {
height: 100%;
width: 100%;
object-fit: fit;
}
}
}
}
}
Can someone please come up with a possible solution.

The scrollbar-width is too new for browser. Ref: Can I use scrollbar-width?
For other solution only for webkit browser (chrome, safari, and newer edge)
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
::-webkit-scrollbar-thumb {
background-color: darkgrey;
outline: 1px solid slategrey;
}
<textarea>ABCDE<br>ABCDE<br>ABCDE<br>ABCDE<br>ABCDE<br>ABCDE</textarea>

From the URL below, you can see the "scrollbar-width" is quite unpopular among browsers so that might be the reason why it's not working =>
https://caniuse.com/?search=scrollbar-width
You can use WebKit like
You have an element with scroll functionality.
set "::-webkit-scrollbar" on the same scroll element =>
.scroll-element::-webkit-scrollbar {
width: 4px;
height: 100%;
background-color: gray;
}
Keep in mind that this "background-color: gray" is for the scrollbar background and NOT for the actual scroller.
Let's make the actual scroller (the moving part) a different color, now use the "::webkit-scrollbar-thumb" =>
.scroll-element::-webkit-scrollbar-thumb {
background: #000;
}

Related

How can I make this text boxes fill out the bottom of the images?

I am working on a layout where I have two movie posters besides each other. There are two things that I can't get to work at the moment:
The overlaying text box should have the width of the poster and be located at the bottom of it (the bottom line of the text box should be at the same position as the bottom line of the poster).
The images should automatically resize so that the posters are always fully on the screen. At the moment, the bottom of the posters is not visible if the window becomes too small. They should also always keep their original aspect ratio (currently also not given).
The posters and their respective texts should always be centered on the screen.
This is how far I've got, however trying to solve any of the mentioned problems has created new ones so far.
JSFiddle
.layout {
width: 100%;
display: flex;
gap: 16px;
}
.film {
flex-grow: 1;
}
.poster {
width: 100%;
height: 100%;
max-width: 500px;
max-height: 700px;
}
.overlay {
color: white;
text-align: center;
font-size: 20px;
font-family: sans-serif;
background-color: rgb(0, 0, 0);
background-color: rgb(0, 0, 0, 0.5);
padding: 20px;
position: absolute;
bottom: 0;
width: 100%;
}
.remove {
text-align: center;
padding: 10px;
background-color: rgb(0, 0, 0);
background-color: rgb(0, 0, 0, 0.5);
color: white;
}
<section class="layout">
<div class="grow1">
<img class="poster" src="https://upload.wikimedia.org/wikipedia/commons/2/29/Marie_Kr%C3%B8yer_movie_poster.jpg">
<div class="overlay">Title<br><span class="year">2014</span></div>
<div class="remove">
Remove Film
</div>
</div>
<div class="grow1">
<img class="poster" src="https://upload.wikimedia.org/wikipedia/commons/2/29/Marie_Kr%C3%B8yer_movie_poster.jpg">
<div class="overlay">Title<br><span class="year">2015</span></div>
<div class="remove">
Remove Film
</div>
</div>
</section>
Desired result (roughly):
Here you are:
* {
box-sizing: border-box
}
html,
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0
}
.layout {
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
gap: 16px;
padding: 16px;
}
.grow1 {
display: flex;
flex-direction: column;
justify-content: flex-end;
height: 100%;
max-width: 500px;
max-height: 700px;
position: relative;
}
.poster {
height: 100%;
align-self: center;
}
.overlay {
position: absolute;
right: 0;
left: 0;
bottom: 0;
color: white;
text-align: center;
font-size: 20px;
font-family: sans-serif;
background-color: rgba(0, 0, 0, .5);
padding: 20px 20px 10px;
}
.remove {
font-size: initial;
font-family: serif;
padding: 20px 0 0;
}
<section class="layout">
<div class="grow1">
<img class="poster" src="https://upload.wikimedia.org/wikipedia/commons/2/29/Marie_Kr%C3%B8yer_movie_poster.jpg">
<div class="overlay">Title<br><span class="year">2014</span>
<div class="remove">
Remove Film
</div>
</div>
</div>
<div class="grow1">
<img class="poster" src="https://upload.wikimedia.org/wikipedia/commons/2/29/Marie_Kr%C3%B8yer_movie_poster.jpg">
<div class="overlay">Title<br><span class="year">2015</span>
<div class="remove">
Remove Film
</div>
</div>
</div>
</section>

justify content won't align left

I'm practicing CSS/flexbox reproducing the login page of instagram but i'm facing a issue with horizontal alignment that i can't figure out what's wrong.
There's two major containers inside one big wrapper ("instagram-wraper" - each one get 50% of the width of that wraper).
Container 1 (left): "cellphone-img" that contain only a cellphone img
Container 2 (right): "account-info-container" that contain all the login inputs, subscribe, and so on.
The image on the left side work as intended, but what i'm trying to do is to align all the content in the account-info-container to the left with justify-content, essentially putting the image and the login containers side by side, but it doesn't work. What am i missing? (bet it's something simple...)
Thanks in advance.
PS: I didn't work on the responsiveness yet.
/* General settings */
* {
margin: 0;
padding: 0;
text-decoration: none;
box-sizing: border-box;
text-decoration: none;
font-family: "Roboto";
}
body {
width: 100%;
min-height: 100vh;
background-color: rgb(243, 243, 243);
font-size: 14px;
}
.flex-container {
display: flex;
/* max-width: 1200px; */
margin: auto;
width: 100%;
}
/* Wrapper img + wrapper login */
.instagram-wrapper {
align-items: center;
width: 60%;
height: 85vh;
}
/* Cellphone img container */
.cellphone-img {
display: flex;
align-items: center;
justify-content: flex-end;
width: 50%;
/* margin-left: 150px; */
}
.cellphone-img img {
height: 630px;
width: auto;
}
/* Login + subscribe + ap-downloads */
.account-info-container {
display: flex;
align-items: center;
flex-direction: column;
justify-content: flex-start;
width: 50%;
/* margin-right: 150px; */
}
/* Login wrapper */
.login-container {
flex-direction: column;
height: 420px;
width: 70%;
border: 1px solid rgba(var(--b6a, 219, 219, 219), 1);
background-color: #fff;
}
.insta-logo {
width: 100%;
display: flex;
justify-content: center;
padding-top: 55px;
padding-bottom: 35px;
}
/* Login inputs container */
.login {
align-items: center;
flex-direction: column;
}
.login input {
width: 85%;
height: 36px;
background-color: rgba(var(--b3f, 250, 250, 250), 1);
border: 1px solid rgba(var(--ca6, 219, 219, 219), 1);
border-radius: 3px;
font-size: 13px;
padding-left: 8px;
}
.input-login {
margin-bottom: 10px;
}
.input-password {
margin-bottom: 20px;
}
.login-btn {
width: 85%;
background-color: rgba(var(--d69, 0, 149, 246), 1);
border: 1px solid transparent;
border-radius: 4px;
color: #fff;
font-size: 14px;
padding: 5px 9px;
cursor: pointer;
font-weight: 600;
box-sizing: border-box;
}
.or-ruler {
width: 85%;
color: rgba(var(--f52, 142, 142, 142), 1);
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
margin-top: 20px;
}
.or-ruler::before {
content: "";
width: 120px;
height: 1px;
background-color: rgba(var(--ca6, 219, 219, 219), 1);
}
.or-ruler::after {
content: "";
width: 120px;
height: 1px;
background-color: rgba(var(--ca6, 219, 219, 219), 1);
}
.facebook-login-btn {
width: 85%;
color: #385185;
background-color: transparent;
border: none;
cursor: pointer;
margin: 30px auto;
display: flex;
justify-content: center;
}
.facebook-login-btn img {
width: 17px;
height: auto;
margin-right: 5px;
}
.forget-pass-link {
font-size: 12px;
cursor: pointer;
padding-bottom: 40px;
color: #00376b;
}
/* Subscribe container */
.subscribe {
align-items: center;
justify-content: center;
border: 1px solid rgba(var(--b6a, 219, 219, 219), 1);
background-color: #fff;
height: 70px;
width: 70%;
margin-top: 10px;
margin-bottom: 30px;
}
.subscribe p a {
font-weight: 600;
color: rgba(var(--d69, 0, 149, 246), 1);
}
/* Apps download wrapper */
.app-download {
align-items: center;
flex-direction: column;
width: 70%;
}
.app-imgs {
display: flex;
width: 100%;
justify-content: space-around;
}
.app-imgs img {
width: 170px;
height: auto;
padding-top: 30px;
}
/* Footer */
.footer-section {
max-width: 60%;
height: 100px;
margin: auto;
margin-bottom: 200px;
}
footer {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 12px;
}
footer div {
margin: 8px auto;
}
footer a {
margin: auto 10px;
color: rgba(var(--f52, 142, 142, 142), 1);
text-decoration: none;
}
<div class="instagram-wrapper flex-container">
<div class="cellphone-img">
<img src="./images/instagram-celular2.png" alt="instagram cellphone" />
</div>
<div class="account-info-container">
<div class="login-container flex-container">
<div class="insta-logo">
<img src="./images/instagram-logo.png" alt="instagram-logo" />
</div>
<div class="login flex-container">
<input class="input-login" type="text" placeholder="Telefone, nome do usuário ou email" />
<input class="input-password" type="text" placeholder="Senha" />
<button class="login-btn">Entrar</button>
<div class="or-ruler">
<span> OU <span>
</div>
<button class="facebook-login-btn">
<span><img src="./images/fb-icon.png" alt="" /></span>
<span>Entrar com o Facebook</span>
</button>
<a class="forget-pass-link" href="">Esqueceu a senha?</a>
</div>
</div>
<div class="subscribe flex-container">
<p>Não tem uma conta? Cadastre-se</p>
</div>
<div class="app-download flex-container">
<p>Obtenha o aplicativo.</p>
<div class="app-imgs">
<img src="./images/apple-button.png" alt="appstore-img" />
<img src="./images/googleplay-button.png" alt="googleplay-img" />
</div>
</div>
</div>
</div>
<section class="footer-section">
<footer>
<div>
Meta
About
Blog
Jobs
Help
API
Privacy
Terms
Top Accounts
Hashtags
Locations
Instagram Lite
Contact Uploading & Non-Users
</div>
<div>
Dance
Food & Drink
Home & Garden
Music
Visual Arts
</div>
<div>
English
© 2022 Instagram from Meta
</div>
</footer>
</section>
If both of your items inside the container are each 50% width, they won't move horizontally—they're spanning across the entire container; there's no free space (and justify-content works by distributing free space).
Remove the width: 50% rule and work on each item individually (using width, margin and/or flex properties).
Also, the justify-content property doesn't take left and right values. They're invalid. Here are the values that work.
Finally, when you're ready to pin both items to the left, consider flex auto margins.

Flexbox - Search result popup underneath searchbox

I want to learn how to build a textbox that is an auto-expanding sort of search box like you see on Google:
Desired Result
Before
After
High-Level Design
In this design below, I demonstrate that I want it to visually seem as if the textbox itself is expanding. The way I see it, there is an input box for the text, but the height of the underlying searchbox-container is auto expanding on the y-axis.
Attempt
nav {
font-family: "Inter", sans-serif;
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
align-items: center;
flex-direction: column;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
margin-top: 20px;
display: flex;
align-items: center;
}
.search-icon {
padding-left: 15px;
}
.search-box input[type="text"] {
border: none;
margin-left: 20px;
font-family: "Inter";
width: 70%;
}
.search-box input[type="text"]:focus {
outline-width: 0;
}
.search-results {
display: flex;
flex-direction: column;
width: 98%;
height: auto;
border-radius: 0px;
border-color: #b7b5b5;
border-style: solid;
background-color: white;
border-width: 0px 1px 1px 1px;
border-radius: 0px 0px 20px 20px;
-webkit-box-shadow: 10px 13px 0px 0px rgba(0, 0, 0, 0.07);
-moz-box-shadow: 10px 13px 0px 0px rgba(0, 0, 0, 0.07);
box-shadow: 10px 13px 0px 0px rgba(0, 0, 0, 0.07);
}
.search-result:last-child {
border-bottom: none;
}
.search-result:hover:last-child {
border-bottom: none;
border-radius: 0px 0px 20px 20px;
}
.search-result {
width: 100%;
border-bottom: 1px solid #b7b5b5;
padding-left: 20px;
padding-top: 10px;
padding-bottom: 10px;
}
.search-result:hover {
background-color: #f7f7f7;
}
.links-container {
width: 55%;
height: 100%;
}
<nav>
<div class="nav-container">
<div class="search-container">
<div class="search-box">
<ion-icon name="search-outline" class="search-icon"></ion-icon>
<input type="text" placeholder="Search articles & videos here" />
</div>
<div class="search-results">
<div class="search-result">Result 1</div>
<div class="search-result">Result 2</div>
<div class="search-result">Result 3</div>
</div>
</div>
<div class="links-container"></div>
</div>
</nav>
Current Outcome:
Clearly this is not looking good. I'm new to Flexbox so having some difficulty structuring this to achieve the previously mentioned goal.
This had a lot of stuff that needed to change, so I pretty much rewrote it. Hopefully, I've given you some ideas to build on.
Some points:
display: flex should only be set on a flex container, not on the cell elements.
Use flex-basis if you need to set the width of a flex cell (don't use width).
Don't use margins. Use flex-gap to space out your cells.
Don't set the height unless you have to. Let the flex display try to set it for you first. In this example, we have to set the height of the link elements to keep them from being the same height as the search elements. (Short of using a grid, there's no way around that that I can see.)
Prefer padding to size your elements. (Very much prefer it over height.)
If you want something with two dimensions, don't use flex at all. Use grid. A vertical flex within a horizontal flex is beginning to push the envelope for what flex is intended for (a one-dimensional arrangement of a set of related elements); you could just as well set this up as a grid with blank areas beneath the menu.
As for dynamically resizing the container div, you don't have to do anything special. If you programmatically add elements to the container, flex will take care of resizing it.
Here's some code:
* {
box-sizing: border-box;
}
nav {
min-width: 800px;
padding: 20px;
background-color: #f7f7f7;
width: 100%;
justify-content: center;
display: flex;
column-gap: 40px;
}
a {
text-decoration: none;
padding: 20px;
}
.search-container {
border: 2px solid darkgrey;
border-radius: 20px;
flex-basis: 40%;
display: flex;
flex-direction: column;
justify-content: center;
column-gap: 20px;
z-index: 1;
}
.search-container a, .search-container p {
border-bottom: 1px solid #b7b5b5;
background-color: white;
text-align: center;
}
.search-container p {
margin: 0;
padding: 30px 20px;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
}
.search-container a:last-child {
border: none;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
}
.links-container {
display: flex;
padding: 10px 0;
flex-basis: 40%;
z-index: 1;
}
.links-container a {
height: 60px;
padding: 20px 40px;
background-color: blue;
color: white;
}
.links-container a:hover {
background-color: green;
}
.header-overlay {
width: 100%;
min-width: 800px;
height: 120px;
background-color: lightgrey;
position: absolute;
}
<body>
<header>
<div class="header-overlay"></div>
<nav>
<div class="search-container">
<p>Search Results</p>
Result 1
Result 2
Result 3
Result 4
Result 5
</div>
<div class="links-container">
One
Two
Three
</div>
</nav>
</header>
</body>
As you can see, this code (especially the HTML) is simpler than yours. Basically, a flex is a container (with display: flex set) and a single set of nested elements. Any of those elements can be a container for another flex. That's what we have here: the nav is a flex with two elements, and each of those elements (search and links) is a flex container as well. A few observations:
Using box-sizing: border-box everywhere will make your life a lot easier. You probably have had the experience of setting up two divs, setting their width to 50%, and being mystified that they won't fit on one line. It's because by default, padding and borders get added onto the outside of the div at the specified width, so its width becomes more than 50%. What this setting does is put padding and borders inside the width instead of outside it.
Notice how to set border-radius for only some of the corners using border-top-left-radius, etc.
Your design appears to want to have your search results drop below the header. This is a bit difficult to do with any setting for the search results themselves. The easier way to do it is to simply "fake" it overlaying a div at the top. You'll see that I've set div.header-overlay to position: absolute. That positions it at the top of the screen. Then, setting the z-index to 1 for both the search and links elements brings them above the header overlay.
When you run the code here, the links take up more than 40% of the horizontal space; that's because the padding I used make it do that. I set the min-width to 800px so it wouldn't look too squashed, but that causes horizontal scrolling here, which isn't the best for an actual page. So, you'll want to play with flex-grow and flex-shrink, as well as media queries and different layouts for different screens, to make the layout more responsive.
That should give you some missing pieces for building flex displays. You can tinker with the markup and settings and learn more.
Hope this works for you!
nav {
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
display: flex;
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
position: absolute;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
padding-left: 20px;
display: flex;
flex-direction: column;
}
.search-results {
width: 90%;
display: flex;
height: 200px;
border-radius: 0px;
border-color: #b7b5b5;
border-style: solid;
background-color: white;
border-width: 0px 1px 1px 1px;
}
.search-result {
width: 100%;
border-bottom: 1px solid blue;
height: 20px;
}
.links-container {
width: 55%;
height: 100%;
}
nav {
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
display: flex;
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
justify-content: center;
align-items: top;
flex-direction: row;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
position: absolute;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
padding-left: 20px;
display: flex;
flex-direction: column;
}
.search-results {
width: 90%;
display: flex;
flex-direction:column;
align-items: center;
height: 200px;
border-radius: 0px;
border-color: #b7b5b5;
border-style: solid;
background-color: white;
border-width: 0px 1px 1px 1px;
}
.search-result {
position:relative;
text-align:center;
top: 40px;
width: 100%;
border-bottom: 1px solid blue;
height: 20px;
z-index: 9999;
}
.links-container {
width: 55%;
height: 100%;
}
<nav>
<div class="nav-container">
<div class="search-container">
<div class="search-box"></div>
<div class="search-results">
<div class="search-result">Result 1</div>
<div class="search-result">Result 2</div>
<div class="search-result">Result 3</div>
<div class="search-result">Result 4</div>
<div class="search-result">Result 5</div>
</div>
</div>
<div class="links-container"></div>
</div>
</nav>
Add this to align center of div
.search-container {
align-items: top;
flex-direction: row;
}
instead of
.search-container {
align-items: center;
flex-direction: column;
}
And add
.search-results {align-items: center;} to align center
then add to search-result,
.search-result {
position:relative;
text-align:center;
top: 40px;
z-index: 9999;
}
For search result add js
function myFunction() {
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("search-box");
filter = input.value.toUpperCase();
ul = document.getElementById("search-results");
li = ul.getElementsByTagName("div");
for (i = 0; i < li.length; i++) {
a = li[i];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
Working demo
function searching(input) {
input.classList.add("active");
var input, filter, ul, li, a, i, txtValue;
filter = input.value.toUpperCase();
ul = document.getElementById("search-results");
li = ul.getElementsByTagName("div");
for (i = 0; i < li.length; i++) {
a = li[i];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
function fun(obj){
obj.classList.add("active");
}
nav {
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
display: flex;
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
justify-content: center;
align-items: top;
flex-direction: row;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
position: absolute;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
padding:0 30px;
display: flex;
top:18px;
flex-direction: column;
}
.search-box.active{
border:none;
border-bottom:1px solid #b7b5b5;
border-radius:0px;
background:transparent;
}
.search-box.active ~ .search-results{
visibility:visible;
}
.search-results {
width: 100%;
display: flex;
flex-direction:column;
align-items: center;
height: 180px;
background:#fff;
border-radius: 30px;
border: 1px solid #b7b5b5;
visibility:hidden;
margin-top:15px;
}
.search-result {
position:relative;
text-align:center;
top: 40px;
width: 100%;
border-bottom: 1px solid #ccc;
height: 20px;
z-index: 9999;
}
.links-container {
width: 55%;
height: 100%;
}
<nav>
<div class="nav-container">
<div class="search-container">
<input class="search-box" id="search-box" type="search" onkeyup="searching(this)" onfocus="fun(this)" placeholder="Please search fruits..">
<div class="search-results" id="search-results">
<div class="search-result">Apple</div>
<div class="search-result">Mango</div>
<div class="search-result">Orange</div>
<div class="search-result">Grape</div>
<div class="search-result">Watermelon</div>
</div>
</div>
<div class="links-container"></div>
</div>
</nav>

Text Centered and Button Right Justified

How do I make the text appear in the center and the button appear to the right of the box while still being able to nicely scale the screen? Meaning the space between the box and the text will grow when the screen zoomed out and space will shrink when the screen zoomed in.
Here is what I have...
https://imgur.com/a/MigatID
Here is what I want to get...
https://imgur.com/H2gCl0S
EDIT: Here is the JSFiddle...
https://jsfiddle.net/d697spr8/1/
<div id="outer">
<div class="topStuff">
<p>Games</p>
<div class="dropdownListPg">
<button class="dropbtn" style="height: 50px; width: 120px">Sort By
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdownListPg-content" style="color: black">
<button style="height: 50px; width: 120px">Alphabetical</button>
<button style="height: 50px; width: 120px">Date</button>
<button style="height: 50px; width: 120px">User Score</button>
</div>
</div>
</div>
</div>
#outer
{
min-width: 1200px;
}
.topStuff
{
display: flex;
justify-content: center;
margin: 0;
margin-top: 20px;
margin-left: 150px;
margin-right: 150px;
padding: 0;
background-color: #999999;
}
.dropdownListPg
{
display: inline;
}
.dropdownListPg .dropbtn
{
}
.dropdownListPg-content
{
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
width: fit-content;
height: fit-content;
overflow-x: hidden;
margin: 0;
padding: 0;
}
.dropdownListPg-content a
{
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
color: black !important;
margin: 0;
padding: 0;
}
.dropdownListPg-content a:hover
{
background-color: wheat !important;
}
.dropdownListPg:hover .dropdownListPg-content
{
display: block;
}
You can use flex positioning. Also i noticed that you nested <button></button> inside <a></a> it is considered a bad practise to nest interactive element into another interactive element.
Also there is another variant with position: absolute applied to dropdown, but in that case flex is better.
#outer {
min-width: 1200px;
}
.topStuff {
display: flex;
justify-content: center;
margin-top: 20px;
margin-left: 150px;
margin-right: 150px;
background-color: #999999;
}
.holder {
flex: 1 0 auto;
}
.holder--align--right {
display: flex;
justify-content: flex-end;
}
.dropdownListPg {
position: relative;
}
.dropdownListPg-content {
position: absolute;
top: 100%;
z-index: 1;
display: none;
width: 100%;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdownListPg-content a {
display: block;
color: black;
padding: 12px 16px;
text-decoration: none;
text-align: left;
}
.dropdownListPg-content a:hover {
background-color: wheat;
}
.dropdownListPg:hover .dropdownListPg-content {
display: block;
}
<div id="outer">
<div class="topStuff">
<div class="holder"></div>
<p>Games</p>
<div class="holder holder--align--right">
<div class="dropdownListPg">
<button class="dropbtn" style="height: 50px; width: 120px">Sort By
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdownListPg-content">
Alphabetical
Date
User Score
</div>
</div>
</div>
</div>
</div>

Flexbox grow or shrink makes the div shift slightly

I am using flexbox to design this navigation bar
Eveything is working fine except for two problems:
The second div grows and shrinks as required but when the content gets too large the second div shifts to the left slightly.
I can't understand how to place a 4th div just below div 2(which should also grow and shrink like div 2) while maintaining all four in the same line as this is my first time with flexbox implementation. Ex:
The 4th div should be in the position of black mark and both the text and black mark should be vertically centered.
html,
body {
background-image: url("../images/theme1.png");
background-repeat: repeat;
}
.conversationHeader {
background-color: rgba(255, 255, 255, 0);
border: none;
min-height: 60px;
display: block;
}
.headerOnScroll {
background-color: rgba(255, 255, 255, 1);
box-shadow: 0 4px 6px -3px rgba(0, 0, 0, 0.2);
}
.horizontalLayout {
width: 100%;
margin: 0!important;
padding: 0 9px!important;
height: 68px;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
}
.conversationBackButton {
font-size: 24px;
width: 40px;
height: 40px;
padding: 8px!important;
margin-right: 16px;
color: #1D333E!important;
display: inline-flex;
}
.conversationDetails {
background-color: #cccccc;
font-family: robotoregular, 'sans-serif'!important;
font-size: 18px!important;
color: #546770;
flex-wrap: nowrap;
flex-grow: 1;
flex-shrink: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: block;
}
.avatar {
min-width: 40px;
width: 40px;
height: 40px;
}
.composeMessageContainer {
background-color: white;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<nav class="navbar navbar-fixed-top conversationHeader headerOnScroll">
<div class="container-fluid">
<div class="navbar-header horizontalLayout">
<a class="navbar-brand text-center conversationBackButton">
<span class="ionicons ion-android-arrow-back"></span>
</a>
<div class="conversationDetails">John Doe</div>
<img class="img-circle img-responsive avatar" src="images/dp.png">
</div>
</div>
</nav>
<div class="container-fluid navbar-fixed-bottom composeMessageContainer">
Text
</div>
If you add flex-shrink: 0 to the .conversationBackButton and .avatar it should work fine, as it will prevent them to shrink
.conversationBackButton {
font-size: 24px;
width: 40px;
height: 40px;
padding: 8px!important;
margin-right: 16px;
color: #1D333E!important;
display: inline-flex;
flex-shrink: 0; /* added */
}
.avatar {
min-width: 40px;
width: 40px;
height: 40px;
flex-shrink: 0; /* added */
}
To make the 4th div line up with the 2nd, move its markup the navbar-header horizontalLayout, remove navbar-fixed-bottom and change its CSS rule to this
.composeMessageContainer {
flex-basis: calc(100% - 56px - 40px);
margin-left: 56px;
background-color: red;
}
Update after a question edit
To make the 4th div line up with the 2nd, move its markup the conversationDetails, put the existing text in conversationDetails in its own div and remove navbar-fixed-bottom
.composeMessageContainer {
background-color: red;
}
Stack snipper
html,
body {
background-image: url("../images/theme1.png");
background-repeat: repeat;
}
body {
padding-top: 80px;
}
.conversationHeader {
background-color: rgba(255, 255, 255, 0);
border: none;
min-height: 60px;
display: block;
}
.headerOnScroll {
background-color: rgba(255, 255, 255, 1);
box-shadow: 0 4px 6px -3px rgba(0, 0, 0, 0.2);
}
.horizontalLayout {
width: 100%;
margin: 0!important;
padding: 0 9px!important;
height: 68px;
display: inline-flex;
flex-wrap: wrap;
align-items: center;
}
.conversationBackButton {
font-size: 24px;
width: 40px;
height: 40px;
padding: 8px!important;
margin-right: 16px;
color: #1D333E!important;
display: inline-flex;
flex-shrink: 0; /* added */
}
.conversationDetails {
background-color: #cccccc;
font-family: robotoregular, 'sans-serif'!important;
font-size: 18px!important;
color: #546770;
flex-wrap: nowrap;
flex-grow: 1;
flex-shrink: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: block;
}
.avatar {
min-width: 40px;
width: 40px;
height: 40px;
flex-shrink: 0; /* added */
}
.composeMessageContainer {
background-color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<nav class="navbar navbar-fixed-top conversationHeader headerOnScroll">
<div class="container-fluid">
<div class="navbar-header horizontalLayout">
<a class="navbar-brand text-center conversationBackButton">
<span class="ionicons ion-android-arrow-back"></span>
</a>
<div class="conversationDetails">
<div>John Doe</div>
<div class="composeMessageContainer">
Text
</div>
</div>
<img class="img-circle img-responsive avatar" src="images/dp.png">
</div>
</div>
</nav>