Simplify styling headings with the same height

Using flex we don't have to rely on JavaScript to equalize the item.
Besides, we've had problems with JavaScript in the past.

We're also adjusting the width of the elements; previously, even though
we defined a width of 16.666% for each element, only five elements would
be on the same row. It happenend because these elements were styled with
inline-block and the generated HTML contained a newline character
between <li> tags, meaning a space character was introduced between
elements. The width of the mentioned space character wasn't being taken
into account when calculating the width.

Using flex, there's no space character between items and we have to
define the margin between them. We're taking this margin into account
when calculating the width.
This commit is contained in:
Javi Martín
2021-03-11 19:57:37 +01:00
parent 16c582f282
commit f1b707f549
2 changed files with 20 additions and 3 deletions

View File

@@ -1,10 +1,27 @@
.groups-and-headings {
$spacing: rem-calc(4);
.headings-list {
display: flex;
flex-wrap: wrap;
list-style: none;
margin-left: -$spacing;
}
.heading {
border: 1px solid $border;
border-radius: rem-calc(3);
display: inline-block;
margin-bottom: $line-height / 2;
margin-left: $spacing;
width: 100%;
@include breakpoint(medium) {
width: calc(100% / 3 - #{$spacing});
}
@include breakpoint(large) {
width: calc(100% / 6 - #{$spacing});
}
a {
display: block;

View File

@@ -1,9 +1,9 @@
<div id="groups_and_headings" class="groups-and-headings">
<% budget.groups.each do |group| %>
<h2 id="<%= group.name.parameterize %>"><%= group.name %></h2>
<ul class="no-bullet" data-equalizer data-equalizer-on="medium">
<ul class="headings-list">
<% group.headings.sort_by_name.each do |heading| %>
<li class="heading small-12 medium-4 large-2" data-equalizer-watch>
<li class="heading">
<% unless budget.informing? || budget.finished? %>
<%= link_to budget_investments_path(budget.id,
heading_id: heading.id) do %>