A div has been styled with overflow-y: auto
, triggering the appearance of a vertical scroll bar when the content exceeds the height of the div. This causes the content to shift horizontally to accommodate the scroll bar, resulting in misalignment with the headers positioned above the div.
No Scroll Bar:
https://i.sstatic.net/jiN3y.png
With Scroll Bar:
https://i.sstatic.net/82ZN0.png
The query is whether CSS offers a method to detect the appearance of the scroll bar and incorporate padding/margin adjustments to the right of the headers accordingly.
An attempt was made using containment (reference: https://www.w3.org/TR/css-contain-3/) as follows:
.drivers-box {
padding: 5px;
border: 1px solid $ra-pam-control-border-grey;
width: 100%;
height: 65px;
overflow-y: auto;
container-type: inline-size;
}
.driver-header {
padding: 0 6px;
}
@container (min-width: 280px) {
.driver-header {
padding: 0 15px 0 6px;
}
}
<div class="drivers">
<div class="driver-row driver-header">
<div style="font-weight: 100">{{ 'CEBM_DRIVERS_LABEL' | translate }}</div>
<div class="driver-row-btns">
<i class="fas fa-chart-scatter" style="cursor: auto;" title="show in scatter plot"></i>
<i class="fas fa-chart-line" style="cursor: auto;" title="show in time series"></i>
<i class="fas fa-fill" style="color: red; cursor: auto" title="select series color"></i>
<i class="fas fa-trash" style="cursor: auto;" title="delete driver"></i>
</div>
</div>
<div class="drivers-box">
<div class="driver-row" ng-repeat="driver in drivers">
<div>{{ driver.name }}</div>
<div class="driver-row-btns">
<input type="checkbox" title="show in scatter plot" ng-checked="driver.showInScatterPlot" ng-click="showInScatterPlotClicked(driver.id)" />
<input type="checkbox" title="show in time series" ng-checked="driver.showInTimeSeries" ng-click="showInTimeSeriesClicked(driver.id)"/>
<i ng-style="{ color: driver.color }" class="fas fa-circle" title="select series color" ng-click="seriesColorClicked(driver.id)"></i>
<i class="fas fa-trash" title="delete driver" ng-click="deleteDriverClicked(driver.id)"></i>
</div>
</div>
</div>
<button class="mini-btn" style="margin-top: 5px;" ng-click="addDriverClicked()">{{ 'CEBM_ADD_DRIVER_BTN_TEXT' | translate }}</button>
</div>
However, this implementation yielded no results, suggesting that it does not recognize the terms container-type
or @container
(used within an SCSS file).
https://i.sstatic.net/HdnIy.png
The question now arises - is containment being utilized correctly? Is there another approach to address this issue effectively?
Your insights are greatly appreciated!