CSS: draw lines between flexboxes - css

I successfully created a nested flexbox layout for my pedigree. But how do I draw lines inbetween? This is possible using CSS3, see http://thecodeplayer.com/walkthrough/css3-family-tree But this example doesn't explain anything and I cannot get it to work with my code.
I am not sure if my approach makes sense: it's flexbox columns inside flex-items that are aligned in a row.
pedigree {
border: 1px solid green;
/* flex container */
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-content: flex-start;
-ms-flex-line-pack: start;
align-content: flex-start;
-webkit-align-items: flex-start;
-ms-flex-align: start;
align-items: flex-start;
}
individual:nth-child(2n) {
background-color: #FFE6E6;
}
individual {
margin: 5px;
border: 1px solid red;
background-color: #E6E6FF;
/* flex item */
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: stretch;
-ms-flex-item-align: stretch;
align-self: stretch;
}
individual:before, .individual:after{
content: '';
position: absolute; top: 0; right: 50%;
border-top: 1px solid #ccc;
width: 50%; height: 20px;
}
individual:after{
right: auto; left: 50%;
border-left: 1px solid #ccc;
}
gen0, gen1, gen2, gen3 {
border: 1px solid blue;
/* flex item */
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: center;
-ms-flex-item-align: center;
align-self: stretch;
/* flex container */
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-content: flex-start;
-ms-flex-line-pack: start;
align-content: flex-start;
-webkit-align-items: flex-start;
-ms-flex-align: start;
align-items: flex-start;
justify-content: space-around;
}
ind_name, ind_birth, ind_marriage, ind_death {
border:none;
display:block;
}
ind_name {
font-weight: bold;
}
ind_birth:before {
content: "* ";
}
ind_marriage:before {
content: "oo ";
}
ind_death:before {
content: "+ ";
}
<html>
<body>
<pedigree>
<gen0>
<individual>
<ind_num>1</ind_num>
<ind_name>Individual</ind_name>
<ind_birth>19 Nov</ind_birth>
</individual>
</gen0>
<gen1>
<individual>
<ind_num>2</ind_num>
<ind_name>Father</ind_name>
<ind_birth>1 Mar</ind_birth>
</individual>
<individual>
<ind_num>3</ind_num>
<ind_name>Mother</ind_name>
<ind_birth>10 Sep</ind_birth>
</individual>
</gen1>
<gen2>
<individual>
<ind_num>4</ind_num>
<ind_name>Grandfather</ind_name>
<ind_birth>1 Nov</ind_birth>
</individual>
<individual>
<ind_num>5</ind_num>
<ind_name>Grandmother</ind_name>
<ind_birth>9 Feb</ind_birth>
</individual>
<individual>
<ind_num>6</ind_num>
<ind_name>Grandfather</ind_name>
<ind_birth>5 Jan</ind_birth>
</individual>
<individual>
<ind_num>7</ind_num>
<ind_name>Grandmother</ind_name>
<ind_birth>15 Nov</ind_birth>
</individual>
</gen2>
</pedigree>
</body>
</html>

I think the right approach here would be to use svg instead of the flexbox items you are using. That still gives you a lot of control on the display (via CSS) and animations/events, while allowing you indeed to draw the lines. Accessibility might be more complex to get right, though.

Related

How do I "vertically center" two flex items?

Here is the link to my project.
I want both of them to be "centered" so to speak. But yes, I know they can both take up 1 position. So I think if there is a way to draw a (invisible) horizontal line that is vertically centered. Then, I can just place one flex item right on top of this line, and the other right below it.
But I think there is a better way to do this that can be used to centered more than 2 flex items.
body{
background:#4A6556;
}
body>div>hello,hey{
background: #CCC;
border-radius: 7px;
margin: 5px;
padding: 20px;
}
body>div{
display: flex;
flex: row wrap;
flex-direction: column;
}
body>div>hey{
order:2;
font-family: 'Lato', sans-serif;
color:#212121;
}
body>div>hello{
order:1;
font-family: 'Kumar One', cursive;
color: #938653;
}
hello,
hey{
text-align: center;
}
<link href="https://fonts.googleapis.com/css?family=Kumar+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Kumar+One|Lato" rel="stylesheet">
<body>
<div>
<hello>Welcome!</hello>
<hey>This is my portfolio page.</hey>
</div>
</body>
It's not entirely clear from your question if you want the two items displayed side-by-side or one-on-top-of-the-other.
A. side by side
.va-twins {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.va-twins > * {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
body {
margin: 0; padding: 0; // SO reset, you don't need this.
}
<div class="va-twins">
<hello>Welcome!</hello>
<hey>This is my portfolio page.</hey>
</div>
If you need it, here's the fully prefixed code (for close to full browser compatibility 97.38% at the time of this posting)
.va-twins {
min-height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.va-twins > * {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-moz-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-moz-box-orient: vertical;
-moz-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
}
<div class="va-twins">
<hello>Welcome!</hello>
<hey>This is my portfolio page.</hey>
</div>
B. one on top of the other
.va-twins {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: stretch;
}
.va-twins > * {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
body {
margin: 0; padding: 0; // SO reset, you don't need this.
}
<div class="va-twins">
<hello>Welcome!</hello>
<hey>This is my portfolio page.</hey>
</div>
Fully prefixed:
.va-twins {
min-height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-moz-box-orient: vertical;
-moz-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: stretch;
-webkit-align-items: stretch;
-moz-box-align: stretch;
-ms-flex-align: stretch;
align-items: stretch;
}
.va-twins > * {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-moz-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-moz-box-orient: vertical;
-moz-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
-moz-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-webkit-align-items: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
}
<div class="va-twins">
<hello>Welcome!</hello>
<hey>This is my portfolio page.</hey>
</div>
You could use #media queries to switch between A. and B. on different screen sizes.

Stacking Divs in Reverse order Responsively [duplicate]

This question already has answers here:
CSS responsive float left and right (change which div goes on top)?
(2 answers)
Closed 7 years ago.
I have two div's that are side by side in a wider screen (say 1000 px)
Box 1 is the left of Box 2
When I change the screen size to say 330px, I want Box 2 ABOVE Box 1.
I have no issues getting BOX 1 ABOVE Box 2, but not the reverse.
I'm hoping this can be done with css - I can make it happen with javascript.
As you are saying about responsiveness, #media queries come into play. I don't fishing care about Old IE versions, so I am using FlexBox for your solution. We can have reverse and orders in flexbox.
Snippet
.flex-container {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-align-items: flex-start;
-ms-flex-align: start;
align-items: flex-start;
}
.flex-item {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
div {border: 1px solid #ccc; max-width: 100px;}
div div {width: 50px; height: 50px; line-height: 50px; text-align: center;}
#media (max-width: 330px) {
.flex-container {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column-reverse;
-ms-flex-direction: column-reverse;
flex-direction: column-reverse;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-align-items: flex-start;
-ms-flex-align: start;
align-items: flex-start;
}
.flex-item {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
}
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
</div>
Another option for older browsers with just using float in a cunning way.
Snippet with Floats
div {border: 1px solid #ccc; max-width: 104px;}
div div {width: 50px; height: 50px; line-height: 50px; text-align: center;}
div {overflow: hidden;}
div div {float: left;}
div div:first-child {float: right;}
#media (max-width: 330px) {
div div {float: none;}
}
<div class="container">
<div class="item">2</div>
<div class="item">1</div>
</div>
You can use a media query to modify CSS rules under certain screen width:
div {
width: 130px;
background-color: #7A9;
margin: 10px;
display: inline-block;
}
#media screen and (min-width: 331px) {
#box1 {
float: left;
}
#box2 {
float: right;
}
}
<div id="box2">BOX 2</div>
<div id="box1">BOX 1</div>

make flex item 90% wide

This is a simple question. I must be just missing the answer. I have a flex container with one flex item in it. I want the flex item to be 90% wide and centered vertically and horizontally. I just can't get it to be 90% wide. I am puzzled. Here's my code:
<div class="" id="popupContainer">
<div class="flex-item-popup" id="popup">
</div>
</div>
#popupContainer {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display:flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-content: flex-start;
align-items: center;
}
#popup {
width: 90%;
height: 90%;
flex-grow: 1;
flex-shrink: 0;
flex-basis: 200px;
justify-content: center;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-flex-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
background-color: black;
justify-content: center; /* align horizontal */
align-items: center; /* align vertical */
}
just delete these two and it will work proprely :
flex-grow: 1; flex-basis: 200px;
Live Demo

Vertical align inline-flex elements

I am trying to vertical-align 3 different inline-flex elements in a same div, but the last one doesn't fit as expected.
.container {
height: 100px;
width: 100%;
background-color: blue;
}
.container .left, .container .right {
height: 100%;
width: 30%;
}
.container .middle {
height: 100%;
width: 40%;
}
.container .left, .container .middle {
display: -webkit-inline-flex;
-webkit-justify-content: center;
-webkit-align-items: center;
display: -moz-inline-flex;
-moz-justify-content: center;
-moz-align-items: center;
}
.container .right {
display: -webkit-inline-flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-webkit-box-pack: center;
-webkit-flex-pack: center;
-webkit-justify-content: center;
-webkit-flex-align: center;
-webkit-align-items: center;
display: -moz-inline-flex;
-moz-justify-content: center;
-moz-align-items: center;
-moz-flex-direction: column;
}
.container .right ul {
padding: 0;
margin: 0;
}
<div class="container">
<div class="left">
<span>2014/01/21</span>
</div><div class="middle">
<button>Hello</button>
<button>Bye</button>
</div><div class="right">
<ul>
<li>Chocolate</li>
<li>Caramel</li>
<li>Watermelon</li>
</ul>
</div>
</div>
Just add vertical-align:top to .container .right :
.container .right {
display: -webkit-inline-flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-webkit-box-pack: center;
-webkit-flex-pack: center;
-webkit-justify-content: center;
-webkit-flex-align: center;
-webkit-align-items: center;
vertical-align: top;
}
JSFiddle

Vertical Aligning - IE10 Flex box not working

I have my center aligning working in all browsers that support it apart from IE10. I think that I have the syntax correct and that it does it support it. Could anyone help? DEMO
html {
height: 100%;
}
body {
background: red;
font-family: 'Open Sans';
min-height: 100%;
width: 100%;
display: -webkit-box;
-webkit-box-orient: horizontal;
-webkit-box-pack: center;
-webkit-box-align: center;
display: -moz-box;
-moz-box-orient: horizontal;
-moz-box-pack: center;
-moz-box-align: center;
display: -ms-flexbox;
-ms-box-orient: horizontal;
-ms-box-pack: center;
-ms-box-align: center;
display: box;
box-orient: horizontal;
box-pack: center;
box-align: center;
text-align: center;
}
.box {
background: none repeat scroll 0 0 #E7F3FF;
border: 4px solid #FFFFFF;
border-radius: 16px 16px 16px 16px;
box-shadow: 0 2px 2px rgba(1, 1, 1, 0.2);
color: #054B98;
height: 620px;
margin: 0 auto 20px;
position: relative;
width: 930px;
}
You have the right display value, but all of the other Flexbox properties you're using are wrong. The proper translation would be like this:
body {
background: red;
font-family: 'Open Sans';
min-height: 100%;
width: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-line-pack: center;
-webkit-align-content: center;
align-content: center;
}
However, if you're using Flexbox for vertical alignment purposes, this might be what you're needing instead:
body {
background: red;
font-family: 'Open Sans';
min-height: 100%;
width: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
Note that box-align and flex-align/align-items are not equivalent properties, but they're performing the same task here.
Adding an explicit height seems to be the appropriate solution.
From: Microsoft Connect - Min-height and flexbox (flex-direction:column) don't work together in IE 10 & 11-preview
In all other browsers that support flexbox, a flex-direction:column based flex container will honor the containers min-height to calculate flex-grow lengths. In IE10 & 11-preview it only seems to work with an explicit height value.

Resources