skip to Main Content

I want to change the frontend font size from the admin panel in Laravel. Suppose there is a

<h2 class="intro">Introduction to PHP...?? </h2>

in style.css-->>>>

.intro{
   font-size:20px;
}

I want this font size dynamic from admin panel by catching the class. If i need 25px i use that or any size I need I will use that.

How can I do that in laravel??? Give me some suggestions to step up…

2

Answers


  1. One way to do this would be via Javascript and your controller:

    In your controller, just pass a variable called $fontSize to your view file. The with JavaScript, get the element by the class name and set the CSS font-size property to whatever value your $fontSize variable has like this:

    <script>
    let h2Item = document.querySelector('.intro');
    h2Item.style.fontSize = '{{ $fontSize }}'
    </script>
    

    Remember that the variable you are passing from your controller should not just be an integer, rather it should be something like 20px 30px 2em etcetera.

    Login or Signup to reply.
  2. You can simply use something like this:

    Save a file named style.php in the path where the asset files are located. Then use in your base blade file like this:

    <link href="{{ asset('path/style.php') . '?fontSize=' . $fontSize }}" rel="stylesheet"/>
    

    The fontSize variable is the font size you want to use.

    And use in style.php

    <?php
    header("Content-Type:text/css");
    ?>
    .intro {
       font-size: <?= $_GET['fontSize'] ?>;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search