How can CSS be utilized in PHP to automatically adjust menu widths based on screen resolution?

To automatically adjust menu widths based on screen resolution using CSS in PHP, you can use media queries in your CSS stylesheet to define different styles for different screen sizes. By detecting the screen width using PHP and then dynamically generating CSS styles based on the screen resolution, you can ensure that your menu widths adjust accordingly.

<?php
$screen_width = $_GET['screen_width']; // Assuming screen width is passed as a parameter

echo "<style>";
echo "@media screen and (max-width: 600px) {";
echo "  .menu { width: 100px; }"; // Adjust width for smaller screens
echo "}";
echo "@media screen and (min-width: 601px) {";
echo "  .menu { width: 200px; }"; // Adjust width for larger screens
echo "}";
echo "</style>";
?>