Home > Enterprise >  Change Font Size from Admin Panel Laravel
Change Font Size from Admin Panel Laravel

Time:10-30

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

<h2 >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...

CodePudding user response:

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'] ?>;
}

CodePudding user response:

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.

  • Related