Reputation: 119
I'm trying to build a family tree, I have a problem with connecting lines, I managed to do first row, with oblique lines, however when I apply the same to the second row the oblique lines disappears. Any ideas how to fix it?
* {
margin: 0;
padding: 0;
}
body {
background: url(../img/bg.jpeg);
}
img {
border-radius: 100%;
width: 150px;
height: 150px;
box-shadow: 4px 4px 13px #222;
border: solid 3px #606f46;
}
span {
background: #beebb3;
border-color: #606f46;
border-radius: 30px 0 30px 0;
padding: 2px;
border-style: solid;
margin-top: 5px;
box-shadow: 4px 4px 13px #222;
}
h1 {
/* width: 580px; */
font-family: 'My Soul', cursive;
font-size: 3.6rem;
text-align: center;
margin: 10px auto;
padding-top: 10px;
}
#no1 {
display: flex;
justify-content: center;
width: 190px;
line-height: 60px;
margin: auto;
}
#container1 {
width: 580px;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
text-align: center;
margin: auto;
}
#container a {
display: block;
color: #000;
text-decoration: none;
background-color: #beebb3;
}
#no1 a {
height: 60px;
}
#no2 {
display: flex;
justify-content: center;
width: 190px;
line-height: 60px;
margin: auto;
margin-top: 9px;
}
#no3 {
display: flex;
justify-content: center;
width: 190px;
line-height: 60px;
margin: auto;
margin-top: 9px;
}
#no4 {
display: flex;
justify-content: center;
width: 190px;
line-height: 60px;
margin: auto;
margin-top: 9px;
}
.container2 {
display: flex;
justify-content: center;
margin-left: 240px;
}
.container3 {
display: flex;
justify-content: center;
margin-left: 35px;
margin-right: 150px;
}
.container4 {
display: flex;
justify-content: center;
margin-right: 240px;
}
.tree {
display: flex;
flex-direction: column;
align-items: center;
margin: 10px;
}
.level1 {
display: flex;
height: 3px;
width: 18%;
border-style: hidden solid solid solid;
margin: auto;
border-width: thick;
}
.oblique1 {
width: 23%;
transform: rotate(-30deg);
border-width: thick;
border-style: hidden hidden solid hidden;
}
.oblique2 {
width: 23%;
transform: rotate(30deg);
border-width: thick;
border-style: hidden hidden solid hidden;
}
.line_container1 {
display: flex;
margin-left: 200px;
margin-top: 17px;
}
.line_container2 {
display: flex;
}
.images {
background-color: white;
}
.container22 {
width: 700px;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
text-align: center;
margin: auto;
}
<!DOCTYPE html>
<html>
<head>
<title>Family Tree</title>
<link rel="shortcut icon" href="./img/family-tree.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="./css/style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=My+Soul&family=Sacramento&display=swap" rel="stylesheet">
</head>
<body>
<div id="container1">
<h1>___Family Tree___</h1>
<div id="no1">
<div class="tree">
<img src="https://entertainment.time.com/wp-content/uploads/sites/3/2013/05/fictioninfluence_list_homersimpson.jpg">
<span>
Homer Simpson
</span>
</div>
<div class="tree">
<img class="images" src="https://static.wikia.nocookie.net/theultimatesimpsons/images/0/0f/Marge-Simpson-icon.png/revision/latest?cb=20180210061653">
<span>
Marge Simpson
</span>
</div>
</div>
<div class="level1"></div>
<div class="line_container1">
<div class="oblique1"></div>
<div class="oblique2"></div>
</div>
</div>
<div class="container22">
<div id="no2">
<div class="tree">
<img src="https://openpsychometrics.org/tests/characters/test-resources/pics/S/2.jpg">
<span>
Bart Simpson
</span>
</div>
<div class="tree">
<img src="https://mella187.github.io/Cartoon-Hero/img/lisa-avatar.jpg">
<span>
Lisa Simpson
</span>
</div>
<div class="tree">
<img src="https://i.pinimg.com/originals/e5/4a/bc/e54abc44b68d6b2770696b789b20dafa.png">
<span>
Abraham Simpson
</span>
</div>
<div class="tree">
<img class="images" src="https://icons.iconarchive.com/icons/jonathan-rey/simpsons/256/Maggie-Simpson-icon.png">
<span>
Maggie Simpson
</span>
</div>
</div>
<div class="line_container2">
<div class="level1">
<div class="line_container1">
<div class="oblique1"></div>
<div class="oblique2"></div>
</div>
</div>
<div class="level1">
<div class="line_container1">
<div class="oblique1"></div>
<div class="oblique2"></div>
</div>
</div>
</div>
</div>
<div id="no3">
<div class="tree">
<img class="images" src="https://cdn.quotesgram.com/img/7/98/1464708000-Ned_Flanders.png">
<span>
Ned Flanders
</span>
</div>
<div class="tree">
<img class="images" src="https://i.pinimg.com/originals/b7/4f/ae/b74faea8de35d22b703b6ae32f891a92.png">
<span>
Elizabeth Hoover
</span>
</div>
<div class="tree">
<img class="images" src="https://static.wikia.nocookie.net/p__/images/3/3a/Seymour_Skinner.png/revision/latest/top-crop/width/360/height/360?cb=20200804144332&path-prefix=protagonist">
<span>
Seymour Skinner
</span>
</div>
<div class="tree">
<img class="images" src="https://www.personality-database.com/profile_images/20160.png">
<span> Edna Krabappel
</span>
</div>
<div class="tree">
<img class="images" src="https://static.wikia.nocookie.net/p__/images/b/b4/Barnild_Gumble.png/revision/latest/top-crop/width/360/height/360?cb=20160402113506&path-prefix=protagonist">
<span>
Barney Gumble
</span>
</div>
<div class="tree">
<img class="images" src="https://static.wikia.nocookie.net/simpsons/images/d/d5/Patty_Bouvier1.png/revision/latest/top-crop/width/360/height/360?cb=20201222215313">
<span>
Selma Bouvier
</span>
</div>
</div>
<div id="no4">
<div class="container2">
<div class="tree">
<img src="https://www.canncentral.com/wp-content/uploads/2019/09/Kent_Brockman-Cannabis-1.jpg">
<span>
Kent Brockman
</span>
</div>
<div class="tree">
<img src="https://untappd.akamaized.net/site/beer_logos_hd/beer-1158277_7220b_hd.jpeg">
<span>
Mayor Quimby
</span>
</div>
<div class="tree">
<img src="https://i.pinimg.com/474x/8e/a1/2b/8ea12bd79870a03994fbf65f63baaa92--school-pictures-sideshow.jpg">
<span>
Sideshow Bob
</span>
</div>
</div>
<div class="container3">
<div class="tree">
<img class="images" src="https://static.wikia.nocookie.net/p__/images/8/81/Wiggum_with_coffee.png/revision/latest/top-crop/width/360/height/360?cb=20160322214733&path-prefix=protagonist">
<span>
Clancy Wiggum
</span>
</div>
</div>
<div class="container4">
<div class="tree">
<img src="https://www.kindpng.com/picc/m/394-3940977_los-simpson-nikki-mckenna-hd-png-download.png">
<span>
Nikki McKenna
</span>
</div>
<div class="tree">
<img src="https://topicimages.mrowl.com/large/owl/thesimpsons/characters/milhousevanhou_1.jpg">
<span>
Milhouse Van Houten
</span>
</div>
</div>
</div>
</body>
</html>
Upvotes: 2
Views: 1545
Reputation: 44086
First, try using more semantic tags, in the example <main>
, <section>
, <figure>
, and <figcaption>
were used instead of <div>
and <span>
. It doesn't make the HTML invalid if you only use <div>
and <span>
but it'll hold less meaning and there's a greater chance of errors being overlooked.
display: table/table-row/table-cell
was assigned to <main>/<section>/<figure>
respectively. Using <table>
for layout is highly discouraged, but using other tags that behave like a <table>
is ok. In the example, the table-like layout is 3 rows (one row for each generation) and 5 columns. The only borders that are visible are actually the lines that connect "leaves" to each other (as spouses or siblings). For demonstration purposes I added a little JavaScript -- just click anywhere to toggle the invisible borders off and on.
Further details are commented in the example below
<!DOCTYPE html>
<html>
<head>
<title>Family Tree</title>
<link rel="shortcut icon" href="./img/family-tree.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="./css/style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=My+Soul&family=Sacramento&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
}
/*
Default font-size is referenced here
Any rem used elsewhere will be directly referenced to this font-size
Default is dynamic -- whenever window is resized, it will adjust to width
if it is bigger than height and vice versa.
In turn, anything in rem will also adjust 2.5vmax === 1rem
*/
html {
font: 2.5vmax/1.5 Sacramento;
}
body {
padding-bottom: 12px;
}
/*
As a <table>, main will adhere to what each column is in width. this
behavior allows it to scale to the width of viewport (window).
*/
main {
display: table;
table-layout: fixed;
width: 100%;
background: transparent;
}
h1 {
display: table-caption;
margin: 10px auto;
padding-top: 10px;
font-family: 'My Soul';
font-size: 2.6rem;
text-align: center;
}
/*
As a <tr>, it automatically holds it's children in a solid row
*/
section {
display: table-row;
background: transparent;
}
/*
As a <td>, padding, vertical-align, width, etc are handled so each one is
uniformly the same height and content is evenly positioned.
*/
figure,
.cell {
display: table-cell;
width: 20%;
background: transparent;
}
img {
width: 7.5em;
height: 7.5rem;
border: solid 3px #606f46;
border-radius: 100%;
box-shadow: 4px 4px 13px #222;
}
figcaption {
width: min-content;
margin-top: -5px;
padding: 10px;
border-style: solid;
border-color: #606f46;
border-radius: 30px 0 30px 0;
background: #beebb3;
box-shadow: 4px 4px 13px #222;
text-align: center;
}
/*
These tags act as empty cells and are placed in-between each "leaf". The majority
of the lines are from their visible borders.
*/
.cell b {
display: block;
position: relative;
z-index: -1;
min-height: 4rem;
}
/*
Applied to .cell between parents -- it connects them
*/
.parents b {
border-top: 6px solid black;
}
/*
Applied to .cell between parents -- it adds a descendant line
*/
.parents b::before {
content: '';
display: block;
position: absolute;
left: 45%;
width: 1px;
height: 8.25rem;
border: 3px solid black;
background: black;
}
/*
Applied to .cell between siblings and the <figure> of any middle children
-- it connects them
*/
.siblings {
border-top: 6px solid black;
}
/*
Applied to .cell to the right of the oldest child and to the left of the
youngest child
*/
.elder,
.baby {
position: relative;
}
/*
Applied to .cell to the right of the oldest child and adds an arrow
*/
.elder::before {
content: '\002b9f';
position: absolute;
left: -1rem;
top: -1.5rem;
font-size: 2rem;
transform: rotate(45deg);
}
/*
Applied to the .cell to the left of the youngest child and adds an arrow
*/
.baby::after {
content: '\002b9f';
position: absolute;
right: -1rem;
top: -1.5rem;
font-size: 2rem;
transform: rotate(-45deg);
}
/*
For demonstration purposes
Styles showLayout(e) toggles on every click (optional)
*/
.show .cell b {
outline: 3px dotted rgba(255, 0, 50, 0.6);
}
.show .cell {
outline: 2px dashed rgba(129, 129, 129, 0.4);
}
</style>
</head>
<body>
<main>
<h1>___Simpson Family Tree___</h1>
<section>
<div class='cell'><b></b></div>
<figure>
<img src="https://i.pinimg.com/originals/e5/4a/bc/e54abc44b68d6b2770696b789b20dafa.png">
<figcaption>Abraham Simpson</figcaption>
</figure>
<div class='cell parents'><b></b></div>
<figure>
<img src='https://comicvine.gamespot.com/a/uploads/square_tiny/11/111746/6556151-mona_simpson.png'>
<figcaption>Mona Simpson</figcaption>
</figure>
<div class='cell'><b></b></div>
</section>
<section>
<div class='cell'><b></b></div>
<div class='cell'><b></b></div>
<figure>
<img src="https://entertainment.time.com/wp-content/uploads/sites/3/2013/05/fictioninfluence_list_homersimpson.jpg">
<figcaption> Homer Simpson </figcaption>
</figure>
<div class='cell parents'><b></b></div>
<figure>
<img src="https://static.wikia.nocookie.net/theultimatesimpsons/images/0/0f/Marge-Simpson-icon.png">
<figcaption>Marge Simpson</figcaption>
</figure>
</section>
<section>
<figure>
<img src="https://openpsychometrics.org/tests/characters/test-resources/pics/S/2.jpg">
<figcaption>Bart Simpson</figcaption>
</figure>
<div class='cell siblings elder'><b></b></div>
<figure class='siblings'>
<img src="https://mella187.github.io/Cartoon-Hero/img/lisa-avatar.jpg">
<figcaption>Lisa Simpson</figcaption>
</figure>
<div class='cell siblings baby'><b></b></div>
<figure>
<img src="https://icons.iconarchive.com/icons/jonathan-rey/simpsons/256/Maggie-Simpson-icon.png">
<figcaption>Maggie Simpson</figcaption>
</figure>
</section>
</main>
<script>
/*
For demonstration purposes - it exposes the borders (optional)
*/
document.querySelector('main').onclick = showLayout;
function showLayout(e) {
this.classList.toggle('show');
}
</script>
</body>
</html>
Upvotes: 1