im new to PHP programming and im facing with a problem.
I want to add my css file to my php page. its in folder named css.
my fonts,pictures, etc. are on other folders.
my php page is in folder named beginer. when i want to link my css file to this page, i need to give every classes that i wrote the specific address to them. it should be change for a every folder.
for example:
body{
background-image:url(images/bg.jpg);
}
it works fine for my index.php file which is in root. but my other files which are in other folders, the address needs to be changed.
it will be like this:
body{
background-image:url(../images/bg.jpg);
}
whats the solution for this issue?
thanks in advanced.
You can add css in php like you do in any html page.
eg :
<?php
-------------------
-------------------
?>
<style type="text/css">
-------------------
---------
your css code here
</style>
You need to add html below your php codes in order to call your css files. And for the images files inside different folder, put it in the root directory where your index.php is so you don't need to use ../ on every css. It should be something like this;
<?php codes goes here ?>
<html>
<head>
<style type="text/css">
body{
background-image:url(/images/bg.jpg);
}
</style>
</head>
</html>
So your root directory will consists of the following files:
index.php
images folder
Related
like the public folder given by laravel default i tried to create something like that for easy make up of my css, js, picture and so on. I tried configuring it like this. In my application/helpers/utility_helpers.php
<?php
function asset_url()
{
return base_url().'assets/';
}
?>
I have my assests folder along with application, system, user_guide etc.
i confugured the autoload function of application/config as :
$autoload['helper'] = array('url','utility');
when i hit any url in browser now, it says
An Error Was Encountered
Unable to load the requested file: helpers/utility_helper.php
how can i make it and can you explain me if i need to specify root for that helpers also.And if not can i simply access the assets like this:
<img src="assets/base_components/build/banner.png">
in my view
In fact the answer is very simple, you only need to put ../ before every file that is under assets folder, because the root of the codeigniter is in application folder, but how you can't put the assets folder there and for the best practices, let the structure of the project like below and apply this solution to the path of the files:
Website Folder structure
|---|application\
|-------(CodeIgniter application folders...)
|---|assets\
|-------css\
|-------images\
|-------js\
|-------robots.txt
|---|system
|-----(CodeIgniter system folder...)
|index.php
Path of the files
ex.:
CSS
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
<link href="../assets/css/plugins/font-awesome.css" rel="stylesheet">
IMAGES and others
<img src="../assets/images/build/banner.png">
JAVASCRIPT
<script src="../assets/js/jquery-2.1.4.js"></script>
<script src="../assets/js/plugins/jquery.scrollSpeed.js"></script>
Note.:
Always remember to applay the best practices to the code too (this will help for the performance of the the page too), like below:
<html>
<head>
meta tags
favicons
css files styles
</head>
<body>
page structure code
javascript files
</body>
</html>
Yo can do this instead:
<img src="<?= base_url('assets/base_components/build/banner.png') ?>">
Your code looks ok, it should work.
According to the error
Unable to load the requested file: helpers/utility_helper.php
there is no utility_helper.php file in application/helpers/ folder. Check if the file exists in that folder or if you don't have a typo in the file name.
top.php
$smarty->assign('style_url',STORE_URL.'csscon.php?store='.STORE_ID);
$smarty->display(PATH.'top.tpl');
top.tpl
<link rel="stylesheet" href="{$style_url}">
csscon.php
include PATH.'css/'.STORE_ID.'/css/style.css';
If see the view source code, it shows all the CSS styles, but it's not applying the CSS. So how can I apply this style?
Thanks
if you put a blank page called index.html in the css folder, it won't show the directory structure if someone goes to http://url/css/.
I have included a _construct() function into my BaseController to include CSS and Javascript using the Asset::add command. However, the CSS doesn't seem to be loading in. The view is loading correctly (so I know there are no errors or exceptions being thrown), but the CSS is not being applied.
For one view, I have:
<html>
<body>
<div class="banner-image"></div>
</body>
</html>
In the CSS, banner-image is defined as:
.banner-image{background:transparent url(/assets/images/hires_080820-F-5957S-987c.jpg) no-repeat center center;-webkit-background-size:cover;-moz-background-size:cover;background-size:cover; height:800px; min-width: 1200px;}
I have the assets folder inside my public folder.
However, the image is not loading on the page (the page remains blank). Any ideas why this would be happening?
Have you dumped the assets in the header anywhere??
like this...
<head>
{{Asset::styles();}}
</head>
But I think that only works with Laravel 3....
It is my understanding that assets are called differently in L4
Anyway....
I just echo them directly into my header views...Like so...
echo asset('css/yourcssfile.css');
or, if you're using Blade templating..
{{asset('css/yourcssfile.css')}}
Also...assuming your css folder is directly in the public folder like public/css
Then the path to your image background would change to this...
.banner-image{background:transparent url('../assets/images/hires_080820-F-5957S-987c.jpg') no-repeat center center;-webkit-background-size:cover;-moz-background-size:cover;background-size:cover; height:800px; min-width: 1200px;}
Because you need to get out of the css folder, so you apply ../
Also it's good to put single quotes around paths
Place the css and js files in the public folder, then load in them as the name.blade.php files are in the public folder too.
I am able to automatically make a new webpage with user input, but there is only one problem: the css doesn't work on this. I know how to attach a css file to a HTML file, but this time, it just doesn't work. To help you visualize this, here is the code I have so far.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="/stylesheet.css">
</head>
<body>
<--content for webpage here-->
</body>
</html>
So, that is the relevant HTML to go with it, and the connection of the CSS to the HTML was literally copy and pasted from another page that worked. I also made sure not to use divs, but to use classes because it could've caused problems. There is also a problem, that when I try to add the header and footer file to my document using php, there is an error as follows: Warning: include(header.php) [function.include]: failed to open stream: No such file or directory in /home/content/55/10690555/html/words/tower.php on line 2
I have no idea as to why this is happening on this page but not any other ones, so any help would be greatly appreciated. By the way, the file with the errors, is the template for creating a new document using PHP if that helps at all.
If you are using php to include the CSS files, you might probably be using include(header.php). This might not work sometimes. Use the absolute path instead.
To get the root location, include $root = realpath($_SERVER['DOCUMENT_ROOT']); at the top and append$root variable before the filename inside the include() function.
You need to properly specify the header.php file in relevance to your webpage file. So depending on your folder structure the correct line of code will vary.
ie. if this is your folder structure:
/folderone/header.php
/foldertwo/webpage.php
This is what you need to use: include('/folderone/header.php');. If header.php is in your root folder you only need to use include('/header.php');
The point is, include('header.php') tells php to look for the file header.php on the same folder as the webpage.
It is a clear indication of file path problem. Please check the new which you are creating by script have in the same path or directory of other files. I also observe that in your css file inclusion you are using '/' this mean respect to the root of the server. So, be sure your css file is on the document root otherwise use relative url.
I have an PHP/HTML main page, in which I include different other PHP files (I include them within the body of the main page).
What if I want to include a CSS stylesheet into only ONE of the included file?
What if that included file is a PHP-only file? (that is, it doesn't have those <head> tags, where the stylesheet reference is supposed to be)
What happens if I put "head" tags into a PHP file that is included in the body of the main page? I am wondering if putting head tags in the middle of the HTML body tags could cause problems at all, or at least with certain browsers.
Think of it this way, after all of you includes you still get one html file at the end of it. If you are including files in the body of your document, it should only contain tags that fit within the body, not html, head, title, body, etc. Your css file should be loaded in the of the main doc. Something like this
<html>
<head>
<title>Title</title>
<!--
css and js here
-->
</head>
<body>
<!-- php include here ---->
<div>content</div>
</body>
</html>
So after your includes the html should still be valid. you can check that here http://validator.w3.org/
EDIT:
You can included as many css files as you want anywhere in the document but the overall structure should still be as above. But try to consolidate your css files as much as possible. Every external file is one more request the browser has to make, and can slow the load time if you have a lot.
You can add style tags in the middle of your html, it's bad behaviour, but you can and it'll work. So, you can only import css you need depending on what you include to your main php. But, you don't have to put head tags for that.
It is ok if you will put you link your css file in any of your files, also if your file is php, you can put your css before or after the php tag. But for me its better to include your css file on your main page as long as you have a unique design or style for a unique element or id on the file that you want to design.
<link href="style.css" type="text/css" rel="stylesheet">
<?php
Content of your php file here
?>