I'm trying to build a tooltip for my items using flexboxes to align content inside them.
Here is a little image of how I imagined it would look:
here is my CSS code attempt of the image above:
.hud-tt-container {
display: flex;
width: 100%;
height: auto;
box-sizing: border-box;
}
.hud-tt-info-container {
width: auto;
height: 64px;
flex-grow: 1;
border: 1px solid yellow;
box-sizing: border-box;
}
.hud-tt-info-block {
width: auto;
height: 32px;
border: 1px solid grey;
box-sizing: border-box;
}
.col-full {
width: 100%;
height: 32px;
float: left;
border: 1px solid gray;
box-sizing: border-box;
}
.col-half {
width: 50%;
height: 32px;
float: left;
border: 1px solid gray;
box-sizing: border-box;
}
.hud-tt-lv-container {
width: 64px;
height: 64px;
flex-grow: 0;
border: 1px solid blue;
box-sizing: border-box;
}
<div class="hud-tooltip f16 fwhite">
<div class="hud-tt-container">
<div class="hud-tt-info-container">
<div class="col-full"></div>
<div class="col-half"></div>
<div class="col-half"></div>
</div>
<div class="hud-tt-lv-container">
<canvas id="Bar"></canvas>
</div>
</div>
</div>
I'm currently using col class to arange them this way. This way it also works, but I want to use flexboxes for this, so to use hud-tt-info-block
The level and info container align just as I want them to. Level container takes 64x64px, while info container takes all the space left. But I'm not sure how to align info blocks the way i want them to be using flexbox
Using flexbox to align col classes is very important due to large numbers. Flexbox can adapt width as numbers get bigger, whereas my current solution doesn't work well with large numbers
You can nest flex elements, where adding display: flex to the .hud-tt-info-container being a flex item, it also becomes a flex container, and its children becomes flex items and so on.
See notes in CSS
.hud-tt-container {
display: flex;
}
.hud-tt-info-container {
flex-grow: 1; /* fill remaining space */
display: flex; /* added */
flex-wrap: wrap; /* added, allow items to wrap */
height: 64px;
}
.hud-tt-info-block {
height: 32px;
border: 1px solid gray;
box-sizing: border-box;
}
.col-full {
flex-basis: 100%; /* changed, take full width and push
the other items to a new row */
}
.col-half {
flex-basis: 50%; /* changed */
}
.hud-tt-lv-container {
width: 64px;
height: 64px;
border: 1px solid blue;
box-sizing: border-box;
}
<div class="hud-tooltip f16 fwhite">
<div class="hud-tt-container">
<div class="hud-tt-info-container">
<div class="hud-tt-info-block col-full"></div>
<div class="hud-tt-info-block col-half"></div>
<div class="hud-tt-info-block col-half"></div>
</div>
<div class="hud-tt-lv-container">
<canvas id="Bar"></canvas>
</div>
</div>
</div>
Related
I have a problem with positioning the vertical line. Here's the project:
https://prnt.sc/wp2vh4
div class="col span-1-of-2"
to separate those two lists BUT - there's a grey vertical line in the 'center' between them. When I make border-right for the first div, it's way too on the right side. How can I make this line more in the center?
two elements are block - should it be something connected to that? but I don't want to 'ruin' the column system.
You could essentially take the two columns and give them a box-shadow of a half pixel each (totaling to 1px side by side). Half pixels don't work with border declarations reason being.
.container {
display: flex;
height: 150px;
}
.col {
align-items: center;
display: flex;
flex: 1;
justify-content: center;
}
.left {
box-shadow: .5px 0 0 #000;
}
.right {
box-shadow: -.5px 0 0 #000;
}
<div class="container">
<div class="col left">Left</div>
<div class="col right">Right</div>
</div>
There are a lot of ways to do this, another solution would be using the old columns css property, like this
.container {
columns: 2;
column-gap: 0;
column-fill: balance;
column-rule: 2px solid #ff44cc;
text-align: center;
padding: 10px;
}
<div class="container">
<div>Block</div>
<div>Block</div>
</div>
Take the solution that mosts suits you.
There are many ways to accomplish a vertical divider between columns.
Option #1
The easiest is to utilize CSS flex-box to create the columns. This will cause both columns to be the same height in the container and you can use a border to create the visual divider.
/* this section illustrates the container sizes */
#container {
border: 1px dashed #dadada;
padding: 2px;
}
.col {
padding: 20px;
font-family: Helvetica, Arial, Sans-serif;
background: tan;
border: 1px dashed #333;
}
/* this shows the solution */
#container {
display:flex;
justify-content: space-between;
}
.col {
flex-basis: 50%;
}
.col:first-child {
border-right: 3px solid aqua;
}
<div id="container">
<div class="col">Column 1</div>
<div class="col">Column 2 with lots of content that makes it much taller than the other column and messes with heights.</div>
</div>
Option #2
Use a pseudo element on the parent container to create a border.
/* this section illustrates the container sizes */
#container {
border: 1px dashed #dadada;
padding: 2px;
}
.col {
padding: 20px;
font-family: Helvetica, Arial, Sans-serif;
background: tan;
border: 1px dashed #333;
}
/* The solution */
#container {
position: relative;
overflow: auto;
}
#container:before {
content: '';
width: 2px;
background: aqua;
position: absolute;
top: 0;
left: 50%;
bottom: 0;
transform: translateX(-50%);
}
.col {
float:left;
width: calc(50% - 42px);
/* need to remove the border & padding width from the full width */
}
<div id="container">
<div class="col">Column 1</div>
<div class="col">Column 2 with lots of content that makes it much taller than the other column and messes with heights.</div>
</div>
Option #3
Really there are lots more options, a CSS gradient background, shadows, CSS Grid, CSS Columns, this list goes on.
I tried by using display inline-block to achieve 3 columns but 3rd column comes at separate row:
.wrapper {
width: 100%;
}
.column {
display: inline-block;
min-height: 150px;
width: 33.33%;
border: 1px solid black;
min-width: 300px;
margin-bottom: 8px;
}
<div class="wrapper">
<div class="column">abc</div>
<div class="column">def</div>
<div class="column">ghi</div>
</div>
Not able to figure out the reason.
I dont know this is exactly what you need , i have remove the default whitespace of the inline-block using font-size:0 and add box-size property you dont need to change the width 33.3% to 33% the width please check the snippet
.wrapper {
width: 100%;
font-size: 0;
}
.column {
display: inline-block;
min-height: 150px;
width: 33.33%;
border: 1px solid black;
margin-bottom: 8px;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
-moz-box-sizing: border-box;
}
<div class="wrapper">
<div class="column">abc</div>
<div class="column">def</div>
<div class="column">ghi</div>
</div>
By Default inline-block count space as a element. You can do this in two different ways:
Method (Using Font Size)
*,*:after,*:before {
box-sizing: border-box;
}
.wrapper {
width: 100%;
font-size:0px;
}
.column {
display: inline-block;
min-height: 150px;
width: 33.33%;
border: 1px solid black;
/*min-width: 300px;*/
margin-bottom: 8px;
font-size:16px;
}
<div class="wrapper">
<div class="column">abc</div>
<div class="column">def</div>
<div class="column">ghi</div>
</div>
Method Removing extra Space
*,*:after,*:before {
box-sizing: border-box;
}
.wrapper {
width: 100%;
}
.column {
display: inline-block;
min-height: 150px;
width: 33.33%;
border: 1px solid black;
/*min-width: 300px;*/
margin-bottom: 8px;
}
<div class="wrapper">
<div class="column">abc</div><!--
--><div class="column">def</div><!--
--><div class="column">ghi</div>
</div>
As per your comment you want margin-right:5px and achieve same thing. for this you can use width in calc format. check below snippet
*,*:after,*:before {
box-sizing: border-box;
}
.wrapper {
width: 100%;
}
.column {
display: inline-block;
min-height: 150px;
width: calc(33.33% - 5px);
width: -moz-calc(33.33% - 5px);
width: -webkit-calc(33.33% - 5px);
border: 1px solid black;
/*min-width: 300px;*/
margin-bottom: 8px;
margin-right: 5px;
}
<div class="wrapper">
<div class="column">abc</div><!--
--><div class="column">def</div><!--
--><div class="column">ghi</div>
</div>
Use Table for it, Best Option
No width, No Float
table{table-layout:fixed;width:500px;border-collapse:collapse;text-align:center;}
<table border="1">
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</table>
By default browser renders a gap between two div which are positioned inline.
Making the parent width:100%, and children width:33.33% will not make children fit in the parent, because DOM calculates the gap between child div.
To make the child div fit the parent, you need to modify the width smaller than 33.33%.
If you still want to use 33.33% width. Try this
Link For reference
Unexpected gap between div inline-block
hope this helps..
One simple way to solve this issue is to set the .wrapper to display: table; and set its children to display: table-cell;. See the example below for the outcome.
.wrapper {
width: 100%;
display: table;
}
.column {
display: table-cell;
min-height: 150px;
width: 33.33%;
border: 1px solid black;
min-width: 300px;
margin-bottom: 8px;
}
<div class="wrapper">
<div class="column">abc</div>
<div class="column">def</div>
<div class="column">ghi</div>
</div>
If you are working in bigger screen like (1600,1920) then please use media query. And nothing to do any changes in margin and other as well.
Please update this property
For < 1366 screen resolution use this css
width:32.90% //instead of 32.90% you may use width: 32%;
For > 1366 width:33% is working
in .column class
width: 33%;
So column class look like
.column {
display: inline-block;
min-height: 150px;
width: 33%;
border: 1px solid black;
min-width: 300px;
margin-bottom: 8px;
}
Because it's 1px border surrounded to div.And their is default Margin:8 to body tag.
Width:33% is not working in 1366 screen resolution. So here you must need to use width:32.90% either 32%
Do change in Width and add Box-Sizing will help you.
.column {
display: inline-block;
min-height: 150px;
width: 33.1%;
border: 1px solid black;
min-width: 300px;
margin-bottom: 8px;
box-sizing: border-box;
}
Try keeping the div in one line in your editor.
<div class="wrapper">
<div class="column">abc</div><!--
--><div class="column">def</div><!--
--><div class="column">ghi</div>
</div>
You can use flex, flex is very good to make responsive div. It's a simple example.
--- HTML ----
<div class="flex-wrapper">
<your-element class="item"> 1 </your-element>
<your-element class="item"> 2 </your-element>
<your-element class="item"> 3 </your-element>
</div>
--- CSS ---
.flex-wrapper {
display: flex;
flex-wrap: wrap; // if you want to lots of items, will be wrapped
}
.item {
width: 33.3%;
}
and if your items have margin, you can calculate that like this.
.item {
margin: 5px;
width: calc(33.3% - 10px);
}
Example :
I hope will be helped you.
Use the following properties to your column class
.column {
display: inline-block;
min-height: 150px;
width:32%;
float:left;
margin-left:4px;
border: 1px solid black;
min-width: 300px;
margin-bottom: 8px;
}
Reason
float:left; property will align your div's on left hand side
width:32%; property will give width of 32 % instead of 33.33% as
1px you are assigning to border, which needs to be accommodated from
the width itself.
margin-left:4px; property will add spacing between divs, this is
for nicety.
Your column class needs a couple of minor fixes, float and width changes:
.column {
display: inline-block;
float: left;
min-height: 150px;
width: 33%;
border: 1px solid black;
min-width: 300px;
margin-bottom: 8px;
}
I have this setup
HTML:
body, html {
margin: 0;
height: 100%;
}
.cont{
border:solid 1px red;
display:inline-block;
}
.left {
float: left;
width: 300px;
height: 30px;
border:solid 1px #000;
}
.big{
width:600px;
}
.right {
border:solid 1px #000;
min-width:200px;
overflow: auto;
height: 30px;
padding-left:5px;
padding-right:10px;
padding-top:3px;
background:green
}
<div class='cont'>
<div class='left'>1</div>
<div class='left'>2</div>
<div class='left big'>3</div>
<div class='left big'>4</div>
<div class='right'>Dynamic Div</div>
</div>
Codepen link for those who prefer that
I need the 'right' div to be placed on the right of div 4. What happens is, if there is leftover space of >=200px after placing the numbered divs, the input text div gets squeezed in there. I don't want that.
Essentially the 'right' div always needs to be on the right of the last numbered div, and filling in the remaining space on the right. If the remaining space is less than 200px, the div should move to the next row.
Each of the numbered divs will have varied widths, although that probably doesn't matter here.
Can I achieve this without jquery?
Thanks.
EDIT: I was able to get this done using flexbox
.cont{
border:solid 1px red;
display:flex;
flex-wrap: wrap;
}
.right {
flex-grow:1;
border:solid 1px #000;
.....
}
Using flex boxes it is possible to get this done.
View it on jsfiddle.
Snippet (updated with width: fit-content):
body, html {
margin: 0;
height: 100%;
}
.cont {
border: solid 1px red;
/*display: inline-block;*/
display: flex; /* added */
flex-wrap: wrap; /* added */
width: -webkit-fit-content; /* chrome 22+, opera 15+, safari 6.1+ */
width: -moz-fit-content; /* firefox 3+ */
width: fit-content; /* default */
}
.left {
border: solid 1px #000;
float: left;
height: 30px;
/*width: 300px;*/
min-width: 300px; /* added */
max-width: 300px; /* added */
box-sizing: border-box; /* added */
}
.big {
/*width: 600px;*/
max-width: 600px; /* added */
min-width: 600px; /* added */
}
.right {
border: solid 1px #000;
min-width: 200px;
overflow: auto;
height: 30px;
padding-left: 5px;
padding-right: 10px;
padding-top: 3px;
background: green;
flex: 1; /* added */
}
<div class='cont'>
<div class='left'>1</div>
<div class='left'>2</div>
<div class='left big'>3</div>
<div class='left big'>4</div>
<div class='right'>Dynamic Div</div>
</div>
You can learn more about flexboxes from these links:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
http://www.w3schools.com/css/css3_flexbox.asp
Here's an image of what I'm referring to:
If you have some fixed height h from the baseline that the pin lies, and the green element is dynamically sized, how can you make the orange element take the space between the two?
Have exactly what you need in this case using a flexbox.
The pin approximately stays at the same height above the baseline give or take 1px.
How it works: When the green element grows say 10px the pin is elevated by 5px. But the flex setup means the dummy and the orange box reduces 5px each thus keeping the pin at a contant height.
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
height: 100px;
border-bottom: 1px solid black;
}
.dummy {
flex: 1;
}
.top {
height: 20px;
width: 20px;
border: 1px solid green;
position: relative;
}
.top div {
position: absolute;
height: 3px;
width: 3px;
background: #880015;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.bottom {
width: 50px;
border: 1px solid orange;
flex: 1;
}
<div class="wrapper">
<div class="dummy"></div>
<div class="top">
<div></div>
</div>
<div class="bottom"></div>
</div>
You can use table properties for this. Table cells fill its parent width. If one cell is short, the other one will expand to fill its parent. The trick here is to rotate 90º your "table" and it's done. To change the 'height" of your pinned item you will actually be changing its width. The anchor element will resize accordingly.
Be aware of this though: http://caniuse.com/#search=transform
.baseline{
height: 100px;
width: 100px;
border: 3px solid black;
display: table;
transform: rotate(90deg);
}
.pinned,.anchored{
display: table-cell;
}
.pinned{
width: 30px;
border: 3px solid green;
}
.anchored{
border: 3px solid orange;
}
<div class="baseline">
<div class="pinned">
</div>
<div class="anchored">
</div>
</div>
I've got the following code:
.wrapper {
display: flex;
height: 25px;
}
.myInput {
width: 50px;
height: 100%;
border: 1px solid grey;
border-right: none;
}
.myInputAddon {
width: 25px;
height: 100%;
background-color: green;
border: 1px solid green;
}
<div class="wrapper">
<input class="myInput">
<div class="myInputAddon" type="number"></div>
</div>
I thought, when I give a hardcoded height to my wrapper div (in the example 25px) and then height: 100%; to his child-elements, they would flex correctly and have the same height.
But in my snippet, my input is higher than my div.
If I remove the height from the wrapper div and give the input a height 23px and to the child-div 25px, it works. But I would like to set it a little bit dynamically.
It should look like this:
How can I do this?
Thanks and cheers.
The problem is default padding of input element so you can just add box-sizing: border-box and keep padding inside height of element.
.wrapper {
display: flex;
height: 25px;
}
.wrapper * {
box-sizing: border-box;
}
.myInput {
width: 50px;
height: 100%;
border: 1px solid grey;
border-right: none;
}
.myInputAddon {
width: 25px;
height: 100%;
background-color: green;
border: 1px solid green;
}
<div class="wrapper">
<input class="myInput">
<div class="myInputAddon" type="number"></div>
</div>
The input element has default styling from the browser:
Make the following adjustments:
.wrapper {
display: flex;
height: 25px;
}
.myInput {
width: 50px;
height: 100%;
border: 1px solid grey;
border-right: none;
box-sizing: border-box; /* NEW; padding and border now absorbed into height:100% */
}
.myInputAddon {
width: 25px;
height: 100%;
background-color: green;
border: 1px solid green;
box-sizing: border-box; /* NEW */
}
<div class="wrapper">
<input class="myInput">
<div class="myInputAddon" type="number"></div>
</div>