I am using bootstrap to try to create the following layout:
Find below my minimum example:
.curr {
font-size: 12px;
font-weight: 700;
letter-spacing: .5px;
}
.price {
-webkit-tap-highlight-color: transparent;
font-family: Trebuchet MS, roboto, ubuntu, sans-serif;
-webkit-font-smoothing: antialiased;
color: #131722;
white-space: nowrap;
display: inline-block;
font-size: 36px;
line-height: 1;
height: 34px;
font-weight: 700;
}
.diff {
-webkit-tap-highlight-color: transparent;
font-family: Trebuchet MS, roboto, ubuntu, sans-serif;
-webkit-font-smoothing: antialiased;
white-space: nowrap;
font-size: 18px;
color: #26a69a;
display: inline-block;
}
.markettime {
-webkit-tap-highlight-color: transparent;
font-family: Trebuchet MS, roboto, ubuntu, sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 11px;
line-height: 1;
letter-spacing: .4px;
text-transform: uppercase;
white-space: nowrap;
color: #37bc9b;
}
.markettime2 {
-webkit-tap-highlight-color: transparent;
font-family: Trebuchet MS, roboto, ubuntu, sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 11px;
line-height: 1;
letter-spacing: .4px;
text-transform: uppercase;
color: #787b86;
white-space: nowrap;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/js/bootstrap.bundle.js"></script>
<div class="row my-2">
<div class="col-lg-8">
<div class="card card-primary">
<div class="card-body p-2">
<div class="row">
<div>
<div>
<div class="row">
<div>
<div class="price">304.2<span class="">0</span></div>
</div>
<div>
<span class="curr"> USD</span>
</div>
<div>
<span class="diff">+3.57</span>
<span class="diff">(+1.19%)</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div>
<span class="markettime">Market Open</span>
<span class="markettime2">(May 07 13:19 UTC-4)</span>
</div>
</div>
</div>
</div>
</div>
</div>
As you can see the text looks quite similar, but does not align correctly.
Any suggestions why?
2
Answers
You have each of the parts stored in
div
s, which default todisplay: block
. Block-items take up their entire row. One option would be to set those displays toinline
:I do not recommend that you use inline styling like I’ve used, I just did a quick edit to show the difference when changing the
display
type.All those empty
<div>
s create new block elements that create a new line and fill up all the horizontal space available.I have cleaned up both the HTML and CSS code in here, but with only the HTML changes it will already work as expected:
Alternatively, you could use
display: inline
ordisplay: inline-block
to style those<div>
s differently, but I think that HTML code could be simplified a lot.