The CSS calc() function conveniently allows for dynamic width adjustments of elements. While supported by modern browsers, it lacks compatibility with older versions such as IE 5.5 and below.
To resolve this and extend support to Opera and the Android browser, consider using box-sizing: border-box instead.
For instance, assume a div with the class "sideBar" with an assumed width of 300px. To dynamically adjust the width of the "content" div based on the sidebar width, avoid using:
.content { width: calc(100% - 300px); }
Instead, apply the following styles:
.sideBar { position: absolute; top: 0; left: 0; width: 300px; } .content { padding-left: 300px; width: 100%; -moz-box-sizing: border-box; box-sizing: border-box; }
By defining a fixed width for the sidebar and applying box-sizing: border-box to the content div, the content's width adjusts automatically based on the sidebar's width, eliminating the need for calc(). This approach ensures compatibility across a wider range of browsers, including older versions of IE, Opera, and the Android browser.
The above is the detailed content of How to Achieve Dynamic Width Adjustments Without CSS Calc() for Wider Browser Compatibility?. For more information, please follow other related articles on the PHP Chinese website!