how to avoid overlapping when using position : fixed - html

Here is the current state of my project:
And on the left you see a sub menu with the next
:host {
height: 100%;
background-color: $color-blue-100;
width: 14rem;
margin: auto;
display: flex;
flex-direction: column;
position: fixed;
border-left: solid 1px;
//Doesn't matter below
h1 {
font-size: 23px !important;
text-align: center;
padding: 2rem 0;
margin: 0;
color: white;
}
a {
text-decoration: none;
height: 4rem;
font-size: 18px;
color: white;
background: $color-orange-100;
display: flex;
label {
margin: auto 0 auto 2rem;
}
}
And to the right I have 3 components written in angular and before them i'm inserting sub menu
<dash-admin-menu></dash-admin-menu>
<div class="vsk__column">
<dash-create-activity></dash-create-activity>
<dash-create-partner></dash-create-partner>
<dash-create-resort></dash-create-resort>
</div>
.#{css-namespace}column{
display: flex;
flex-direction: column;
width: 100%;
max-height: 100%;
margin-bottom: 1rem;
}
The problem is that i want my sub menu to be fixed but if I do so I'm overlapping my three components.
overlapped picture
How can I avoid this ?

what about setting a left margin on ".vsk_column" with the size equals to the width of the menu ?
You could use a variable in css

I assume you want to prevent the menu to be moved when scrolling on the right side? Maybe better not do set position:fixed on the left menu. Set it to height:100vh; and .vsk__column {overflow: auto;}

As an alternative (quite simple workaround), you can try to set the height of the dash-admin-menu and then offsetting the vsk__column div by the same amount of pixels (e.g. 100px), like in following:
<div class="admin_menu_wrapper>
<dash-admin-menu></dash-admin-menu>
</div>
<div class="vsk__column">
<dash-create-activity></dash-create-activity>
<dash-create-partner></dash-create-partner>
<dash-create-resort></dash-create-resort>
</div>
and then in CSS something like this:
.admin_menu_wrapper {
height: 100px;
}
.vsk__column {
margin-top: 100px;
}

Related

How to fix 'overflow: auto' not working as intended?

I have made an unsorted list that contains tabs that get created dynamically based on the value of my amount input field. The div of this list has its overflow set to auto to create a scrollbar when too many tabs are created. But for some reason the overflow auto doesn't work as intended.
These pictures show that I can fit a maximum of 21 tabs without a scrollbar. However, as I increase the amount of tabs they get squished together until the 24th tab and only after the 25th has been added the scrollbar appears. (The borders are for visualization purposes and show the dimensions of the div that contains the list as well as the div that contains that div)
These are the respective sections of my HTML and CSS:
#amount-and-tabs-container {
display: flex;
}
.container {
width: 50%;
display: inline-block;
}
#amount-container {
width: 10%;
min-width: 75px;
}
#tabs-container {
width: 100%;
overflow: auto;
border: 1px solid blue;
}
#tabs {
display: flex;
list-style-type: none;
margin: 0;
padding: 0;
border: 1px solid red;
}
.tab {
cursor: pointer;
text-align: center;
font-weight: bold;
padding: 10px;
margin-left: 20px;
width: 24px;
min-width 24px;
background-image: url("tab.png");
background-size: 100% 100%;
}
.tab.active {
background-image: url("tab_active.png");
}
.tab:hover {
background-image: url("tab_hover.png");
}
<div id="amount-and-tabs-container">
<div class="container" id="amount-container">
<label id="amount-label" for="amount">Amount:</label>
<input type="number" id="amount" value="1" min="1">
</div>
<div class="container" id="tabs-container">
<ul class="tabs" id="tabs"></ul>
</div>
</div>
I have tried to add a width and min-width to the tabs, but it doesn't do anything in regards to this problem. I suspect the cause to be the margin on the tabs, but I am not sure. My leading theory is that the margin gets prioritized above the width.
Answer:
'flex-shrink: 0' fixed this.

Flex-grow takes up its own margin as well when scrolling is needed

I have a container, in my case the body and html tags are the containers. And then I have 3 divs in them and I want the last one to fill the remaining vertical space available while still having a margin.
The third div is generated dynamically so I can't predict what height it's gonna need. The problem is, if it grows too much and a scrollbar is required, the bottom-margin it used to have goes away too. If a scrollbar is NOT required and doesn't appear, the margin is still there and everything looks like I want it to.
I tried to draw what I meant as best as I could in the above image. The 1st case is what I want to happen all the time, regardless of whether there's a scrollbar or not. The 2nd picture is what actually happens, the blue div loses its bottom margin, despite having it set.
Here's my CSS for the html and body tags (they contain the 3 divs, including the blue one):
html,
body
{
width: 100%;
height:100%;
margin: 0px;
padding: 0px;
display: flex;
flex-direction:column;
align-items: center;
background: #494d5f ;
}
and here's my code for the 3rd div, the blue one:
.bottomDiv
{
display:flex;
flex-direction:column;
background: #a0d2eb ;
align-items: center;
width: 97%;
margin-bottom:1.5%;
flex: 1 1 auto;
padding-top:1%;
padding-bottom:1%;
}
Maybe I didn't clarify well enough but the 3rd div in my case, the blue one grows just like it should, fully obeying its margins UNTIL a scrollbar appears and is needed. No matter the amount of growth it has to do, it does it perfectly while respecting its margin. But if it has to grow "out of bounds" of the page so to say, as in, a scrollbar is needed to display all the webpage then its margin is simply gone. IF there is NO scrollbar, everything looks perfect.
Just change this line: body { height: 100%; } to: body { min-height: 100vh; }.
With that line the body will have a height of at least the screen height (100vh) but allows i proper overflow as it is allowed to eb alrger then the screen. As such the margins wont get removed.
html,
body {
width: 100%;
min-height: 100vh;
margin: 0px;
padding: 0px;
display: flex;
flex-direction: column;
align-items: center;
background: #494d5f;
}
.topDiv,
.midDiv {
width: 97%;
height: 50px;
}
.topDiv {
margin-top: 1.5%;
background-color: red;
}
.midDiv {
background-color: blue;
}
.bottomDiv {
display: flex;
flex-direction: column;
background: #a0d2eb;
align-items: center;
width: 97%;
margin-bottom: 1.5%;
flex: 1 1 auto;
padding-top: 1%;
padding-bottom: 1%;
}
#height:checked + label::after {
content: "";
display: block;
height: 150vh;
}
<div class="topDiv"></div>
<div class="midDiv"></div>
<div class="bottomDiv">
<input type="checkbox" id="height" name="height">
<label for="height">checkmark me to extend box height</label>
</div>
I've put an example, so you may try this approach:
body,
html {
margin: 0;
padding: 0;
}
#page {
display: flex;
flex-direction: column;
height: 100vh;
outline: 1px solid purple;
}
#header {
height: 30px;
outline: 1px solid red;
}
#middle {
flex-grow: 1;
/* height: 100vh; */
/* flex-direction: column; */
outline: 1px solid green;
}
#footer {
outline: 1px solid blue;
}
<div id="page">
<div id="header">...</div>
<div id="middle">...</div>
<div id="footer">...</div>
</div>
Try to remove #footer and see that #middle fills the entire screen till the end.
In addition if you need any margins so you have to modify the container like this: #page { ..., margin: 10px; height: calc(100vh - 20px); }

Why is the <a> element inside <nav> losing a couple of pixels in the width?

I am creating a responsive menu for a website, but I have a problem: The a tag (red color) is losing a couple of pixels when defining the 100% width of the div (blue color).
To notice the difference it is necessary to open the link of the Pen, use the Chrome inspector and select the red box. The width is shown with pixels less than 30 (example: 28.72, 27.60, etc.).
I have tried other HTML tags although the result has been the same. Why does it happen and what would be the optimal solution for the tag to keep the width and height at 30px, please?
Here the pen: https://codepen.io/Jnico/pen/RQaEoa
body {
padding: 0;
margin: 0;
}
.menu__container {
width: 100%;
background: black;
padding: 0 5px;
}
.menu {
width: 100%;
max-width: 1024px;
height: 55px;
margin: auto;
display: flex;
align-items: center;
}
.logo {
width: 30px;
height: 30px;
background: red;
display: inline-block;
}
.menu__buttons {
width: 100%;
background: blue;
margin-left: 15px;
display: flex;
justify-content: space-between;
}
.button {
padding: 6px 20px;
border: 1px solid #FFFFFF;
}
<nav class="menu__container">
<div class="menu">
<a class="logo"></a>
<div class="menu__buttons">
<a class="button">Button 1</a>
<a class="button">Button 2</a>
</div>
</div>
</nav>
Because of flexbox..
Add flex: 0 0 auto to your .logo so it doesn't flex at all an it should be fine ;) Also, you don't need display:inline-block there, as it's a flex-item already.
.logo {
width: 30px;
height: 30px;
background: red;
flex:0 0 auto;
}
When i set display to inline-table or table is ok and set 30*30
or you can set flex to 0 0 auto;
Either you can use flex-wrap: wrap to the flex container if you want that the flexible items will wrap if necessary.
Or you have to use flex-basis:30px to the <a>(No need to mention the width) and
flex-grow:1 to the .menu__buttons so that it can take the remaining width...
And remove width:100% from the .menu__buttons...No need
Updated Code
My best alternative was:
.logo {
min-width: 30px
}
Because "min" can be used without interrupting my receptive system with fixed pixels or by adding extensive code.

Reposition div left of another div rather than below

I am attempting to tile a webpage with div elements of various sizes. However, I am running into an issue with once x number of div elements have filled the width of the screen the following div is placed below the previous 'row', rather than being floated to fit into space between elements in the previous 'row'. The code below better demonstrates what I mean; I'd like the 'game' div to be floated to fit into the space above where it is currently positioned.
h1 {
color: white;
}
.center {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.container {
display: inline-block;
}
.default {
margin: 1em;
float: left;
}
/* For hover text */
.hover_img {
width: 100%;
height: 100%;
position: relative;
float: left;
}
.hover_img h4 {
color: white;
}
.hover_img:hover img {
opacity: .2;
}
.hover_img:hover .center_text {
display: block;
}
.center_text {
position: absolute;
top: 50%;
left: 0;
display: none;
font-weight: bold;
text-align: center;
}
img {
margin: 0;
}
.rectangle-tile-horizontal {
height: 15em;
width: 35em;
}
.red {
background-color: rgba(255, 63, 63, 0.8);
}
#game, #game img {
width: 30em;
height: 30em;
}
#app, #app img {
width: 40em;
height: 35em;
}
<div class="container">
<div class="rectangle-tile-horizontal red center default">
<h1><b>Projects</b></h1>
</div>
<div class="rectangle-tile-horizontal hover_img default" id="app">
<img src="http://cohenwoodworking.com/wp-content/uploads/2016/09/image-placeholder-500x500.jpg">
<div class="center_text"><h4>Web App</h4></div>
</div>
<div class="hover_img default" id="game">
<img src="http://cohenwoodworking.com/wp-content/uploads/2016/09/image-placeholder-500x500.jpg">
<div class="center_text"><h4>Breakout</h4> </div>
</div>
I'm afraid what you want to do is actually re-order your divs to create a space-filling layout. To the best of my knowledge, using only CSS for this is difficult, if not outright impossible.
I suggest you take a look at this SO post, or perhaps even the Bulma framework is what you want.
If, however, you move away from re-ordering the containers automagically and instead look towards a solution that elastically adapts the width of each container to fill the available space while maintaining its "order" (first, second, third), I am sure CSS will be a viable solution. If you require assistance, please use the search or ask anew.
Create a style for your div class or id like
.className
{display:inline;}
and use it in your each div
Hope this will help you
An example of this
http://jsfiddle.net/JDERf/

CSS Flexbox- Too much extra vertical space

I'm really new to CSS/programming in general and am trying to build a website logo for a friend as practice. He wants his name justified across the entire header and responsive to the page, and I came up with something that ALMOST works perfectly. Here's what I've got:
<style>
body {
background: black;
}
.container {
overflow: hidden;
line-height: 1em;
color: white;
}
.header {
border: 1px solid white;
width:30%;
margin: 20px 0 0 0;
padding: 5px;
display:flex;
flex-direction: column;
line-height: 0em;
align-items: center;
}
.header h1{
flex-direction: row;
display:flex;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
align-self: center;
width: 100%;
}
.header h1 p {
text-align: center;
/* background: gray;
*/
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
width: 100%;
font-size: 20px;
}
</style>
<div class="container">
<div class="header">
<h1><p>I</p><p>S</p><p>T</p><p>H</p><p>I</p><p>S</p></h1>
<h1><p>T</p><p>O</p><p>T</p><p>A</p><p>L</p><p>L</p><p>Y</p></h1>
<h1><p>I</p><p>N</p><p>S</p><p>A</p><p>N</p><p>E</p><p>?</p></h1>
</div>
</div>
So it looks okay, at the moment, and I'm comfortable incorporating it into the rest of the site CSS. The problem I'm having is twofold:
A) I cannot seem to adjust the flexbox properties to eliminate/control all of that empty space. The width is fine but the box is too high, and I'm unsure which combination of properties I need to achieve fine-grained control of the header's height.
B) It has 20 p's in a row at the end. This seems inefficient? I'd like to keep it pure CSS for the moment, so this might be unavoidable, but is there a better way to do this by incorporating another language?
Apologies for any rookie mistakes/StackOverflow faux pas. Infinite apologies if this has already been answered clearly elsewhere.