Home > Web Front-end > CSS Tutorial > How to Achieve `width: calc(100% - 100px)` Functionality Using jQuery?

How to Achieve `width: calc(100% - 100px)` Functionality Using jQuery?

Patricia Arquette
Release: 2024-12-14 13:25:11
Original
651 people have browsed it

How to Achieve `width: calc(100% - 100px)` Functionality Using jQuery?

Alternative to CSS width:calc(100% -100px) Using jQuery for Compatibility

Seeking a cross-compatible alternative to CSS's "width: calc(100% -100px)", which provides the desired functionality but may not be universally supported, one can turn to jQuery.

jQuery Solution:

jQuery offers a straightforward method to replicate the CSS expression for browsers that lack its support:

$('#yourEl').css('width', '100%').css('width', '-=100px');
Copy after login

This code assigns a 100% width to the targeted element and then subtracts 100px from its width value. This effectively mimics the functionality of "width: calc(100% -100px)", making it responsive and compatible with browsers that do not natively support the calc expression.

jQuery's ability to handle relative calculations effortlessly makes this method a convenient and reliable alternative to manually implementing the calculation yourself.

The above is the detailed content of How to Achieve `width: calc(100% - 100px)` Functionality Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template