Вход

Просмотр полной версии : Как лучше построить html+css для столбчатых диаграмм?


AntonMs
13.01.2019, 16:20
У меня есть div блок и в него генерируются столбики относительной этой высоты для отображения статистики, но их высота отмериваться от верха а нужно чтобы 0% было внизу а 100% вверху как и рисуются такие диаграммы.

Есть пару идей реализации но это больше на "костыль" похоже чем на элегантное решение. Просьба подсказать решение.

VооDоо
13.01.2019, 19:20
AntonMs,
FlexBox?

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Demo</title>
</head>
<body>

<div id="items">
<div class="item item1"></div>
<div class="item item2"></div>
<div class="item item3"></div>
</div>

<style type="text/css">
#items {
width: 60px;
background-color: #eee;
border: 2px solid #ccc;
display: flex;
align-items: flex-end;
}

.item{
width: 10px;
height: 50px;
margin: 5px 5px 0 5px;
background-color: #333;
}

.item1{
height: 35px;
}

.item2{
height: 20px;
}
</style>

</body>
</html>

Строки 20 и 21.

Malleys
13.01.2019, 19:20
можно так (только сам смысл)
<style>
.chart {
width: 20em;
height: 20em;
background: #eee;
display: flex;
align-items: flex-end;
}

.chart > * {
background: deeppink;
flex: 1;
margin: .5em;
}
</style>

<div class="chart">
<div style="height: 20%;"></div>
<div style="height: 40%;"></div>
<div style="height: 80%;"></div>
<div style="height: 60%;"></div>
</div>

AntonMs
13.01.2019, 21:12
Спасибо большое! Именно то что нужно.