logo
down
shadow

determining width of container based on how many flex items


determining width of container based on how many flex items

By : Shark Shore
Date : October 17 2020, 06:10 PM
this one helps. Consider CSS variable and you can easily define a number instead of a percentage
code :
.chart {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 0 15px;
  margin-bottom: 50px;
  position: relative;
}

.dot-black {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: black;
}

.dot-grey {
  width: 22px;
  height: 22px;
  border-radius: 11px;
  background: grey;
}

.unit {
  flex: 1;
  display: flex;
  align-items: center;
}
.line-grey {
  height: 2px;
  background: grey;
  flex-grow: 1;
}

.overlay {
  position: absolute;
  width: calc(var(--n,0) * (100% - 30px)/8); /* 2*15px padding and 8 items*/
  height: 50px;
  background: grey;
  border: solid 1px #000;
  opacity: 0.5;
  top: 0;
  left: 15px; /* padding */
}
<div class="chart">
  <div class="unit">
    <div class="dot-black"></div>
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="overlay" style="--n:2"></div>
</div>
<div class="chart">
  <div class="unit">
    <div class="dot-black"></div>
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="overlay" style="--n:4"></div>
</div>
<div class="chart">
  <div class="unit">
    <div class="dot-black"></div>
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="unit">
    <div class="line-grey"></div>
    <div class="dot-grey"></div>
  </div>
  <div class="overlay" style="--n:8"></div>
</div>


Share : facebook icon twitter icon
Make flex items take content width, not width of parent container

Make flex items take content width, not width of parent container


By : Marouf
Date : March 29 2020, 07:55 AM
hop of those help? Use align-items: flex-start on the container, or align-self: flex-start on the flex items.
No need for display: inline-flex.
Control width of flex items arranged vertically in a flex container

Control width of flex items arranged vertically in a flex container


By : YiPing Zhong
Date : March 29 2020, 07:55 AM
I hope this helps . Instead of flex-direction: column, you can try a wrapping flexbox using flex-wrap: wrap; and you can set:
code :
div {
  border: 1px solid;
  box-sizing: border-box;
}
.container {
  width: 400px;
  display: flex;
  flex-wrap: wrap;
}
.child {
  height: 200px;
}
.child.half {
  flex-basis: 50%;
  color: green;
}
.child:not(.half) {
  flex-basis: 100%;
  color: purple;
}
<div class="container">
  <div class="child half">
    HALF
  </div>

  <div class="child half">
    HALF
  </div>

  <div class="child">
    FULL
  </div>
  <div class="child">
    FULL
  </div>
  <div class="child">
    FULL
  </div>
  <div class="child">
    FULL
  </div>
</div>
How can I display 2 items in a flex container and keep set width and height of a flex item?

How can I display 2 items in a flex container and keep set width and height of a flex item?


By : user1835350
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have added settings for the flex items that contains the circle. By default the setting for flex-shrink is 1, which allows it to shrink if necessary. Setting it to zero ensures the circle is displayed as desired.
code :
* {
  box-sizing: border-box;
}

.container {
  border: thin solid green;
  padding: 1rem;
}

.inner {
  border: thin solid purple;
  display: flex;
  padding: 1rem;
}

.circle {
  width: 200px;
  height: 200px;
  background-color: red;
  border-radius: 100%;
  flex-shrink: 0;
}
<div class="container">
  <div class="inner">
    <div class="circle"></div>
    <div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
  </div>
</div>
Container width based on child flex items

Container width based on child flex items


By : Venkatesh Talari
Date : March 29 2020, 07:55 AM
I hope this helps you . I really attempted to code only with CSS and your code, but without success. I reached the desired result with some JavaScript code. Please, let me know if you can get some more elegant.
Note the css pointer-events: none; property in your li elements. It is very important here. If you want to use href in lis, I believe some refactoring will be needed.
code :
const sidebar = document.querySelector('.sidebar');
const ul = sidebar.querySelector('ul');

const showRemainder = () => {
  const width = ul.clientWidth * Math.ceil(ul.children.length / 5);
  sidebar.style.maxWidth = `${width}px`;
}

const hideRemainder = () => {
	sidebar.style.maxWidth = '80px';
}

sidebar.addEventListener('mouseover', showRemainder);

sidebar.addEventListener('mouseout', hideRemainder);
.sidebar {
  background: #ccc;
  max-width: 80px;
  width: auto;
  height: 400px;
  overflow: hidden;
  transition: all 0.5s ease;
}

.sidebar ul {
  list-style-type: none;
  height: 400px;
  display: flex;
  padding: 0;
  margin: 0;
  flex-flow: column wrap;
  align-content: flex-start;
}

.sidebar ul li {
  display: flex;
  pointer-events: none;
  justify-content: center;
  align-items: center;
  background: #000;
  height: 80px;
  width: 80px;
  color: #fff;
  box-sizing: border-box;
  border: 1px solid #fff;
}
<nav class="sidebar">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li>
        <li>11</li>
        <li>12</li>
        <li>13</li>
    </ul>
</nav>
How do i set a flex-container to be the width of its flex-items?

How do i set a flex-container to be the width of its flex-items?


By : Maikel Bradshaw
Date : March 29 2020, 07:55 AM
Any of those help If you mean you want the container to be the width of the items, rather than the items expanding to the container width...
You may be able to get that by changing display:flex to display:inline-flex
Related Posts Related Posts :
  • Hide empty table (with whitespace) with css
  • <div.main> </div.main> - Syntax
  • How to stop text going under or over picture
  • <picture>: if multiple media queries match, which one has priority?
  • How can i change the width and the height size of the div class "col-sm-9"?
  • css typewriter effect, shows all text then starts the effect
  • How to put a div and nested divs with min height of all body
  • How to ease out a loading screen in Angular?
  • How do I scale specific points while leaving other points alone?
  • Is there a need to install CSS3 plug-ins?
  • I want to style inputs inside a div with html
  • Vue-select drop-down not working properly
  • How to use the euro symbol in PL/SQL code?
  • HTML table with millions of cells ignores cell's fixed dimensions
  • Alternately coloring the virtual rows created by CSS flex
  • Checkbox change event receiving undefined value
  • Layout breaking when title of post breaks to next line or stacks
  • How to rotate an image in all the direction using css
  • Cannot open link in a new tab inside iframe
  • Hyperlinks do not work on left mouse click
  • Bootstrap - NavBar is not collapsing well first element
  • Which input type is this?
  • Steam a live Video using HTML
  • How to style the last Angular component on the page?
  • How to scale an image to its original size by CSS?
  • Can i write typescript with in <Script> tag?
  • Smalltalk Seaside - How do I change the size of a button?
  • Validation of input type number in Angular 6
  • How to prevent VS Code from breaking up long HTML lines into multiple lines?
  • How to adjust the width of react flexbox grid items to allow space between them?
  • How can I add 2 separate backgrounds in html?
  • WCAG 2.0 redundant links
  • I want to put footer at the bottom of the page
  • Have footer be pushed to the bottom without hovering over info
  • Why does viewbox attribute affect the size of the SVG element?
  • Is there a way to implement proper links using `<a href="/">` with github pages?
  • Changing CSS with the checkbox check
  • Insert React variable as attribute in html tag
  • How to give opacity to parent div in such a way that it does not effect child div?
  • Making 2 lists Side-by-Side
  • Convert XML to HTML Table in XSLT
  • Why am I getting error in *ngIf of angular reactive form
  • How can I make my site open Instagram in-app?
  • How to select h4 heading
  • Aligning flex items vertically
  • How to create images with border radius?
  • html: max function in font-size doesn't work
  • How to make an element sticky?
  • Vertically align html-entity characters in monospace font?
  • Fitting a 'widescreen' image into a square div
  • How to create background with triangle shapes?
  • How can I spread out my flex items to more than the width of a container?
  • Unable to put anchor tag inside HTML code tag
  • Center fit images of any size to parent div
  • Why doesn't my CSS border appear on a span around a button?
  • How to implement light color change of a traffic light with pure css?
  • Make CSS max-width larger than parent
  • How to apply `display:none;` to everything except an `<td class="cc">text</td>`?
  • dateClick not emitted in fullcalendar angular
  • What is the difference between HTML and XHTML?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk