how to style the html contents inside a php include file?
how do i style the html contents inside a php include file, using css?
For example, I have a basic webpage like this (note, the code is fly-by one.. not the actual code..just wanted to illustrate the scenario) -
<html>
<head>
<title><title>
<link rel="stylesheet" href="mainstyle.css" />
</head>
<body>
<div id="header">
<?php include("header.php"); ?>
</div>
<div id="menu">
<?php include("menu.php"); ?>
</div>
<div id="body"> blah blah blah </div>
<div id="footer">
<?php include("footer.php"); ?>
</div>
</body>
</html>
Now the php include files for the above -
menu.php:
<a href="#" class="menulink">link1</a>
<a href="#" class="menulink">link2</a>
<a href="#" class="menulink">link3</a>
<a href="#" class="menulink">link4</a>
header.php:
<p><span id="hugesize">this text is in huge size </span></p>
Question is, how do i style the menulink and hugesize class/id present in the php include files - menu.php and header.php...? should these styling be 开发者_如何学Cincluded in the stylesheet of the page where these include codes will be 'embeded'.. as in the stylesheet referenced by
<link rel="stylesheet" href="mainstyle.css" />
Thanks.
The PHP include basically just appends the text to the file, so you will have a one big file once PHP processes the base page.
So there are two ways to style those classes, either include a block in the header, or just include it in the main link.
You answered your own question :). When those files are included, they will be sent as a single unit of output to the browser. Any CSS rules you have in stylesheets included on the same page will affect all html on that page.
Thats right. If you link to a css stylesheet in the main page then the styles apply to everything. Because css is only applied on the client side, that is, the browser. The browser is not aware of the includes etc, all that is handled on the server before anything is sent to the browser.
Any time I deal with combining PHP and HTML I always create myself a prototype HTML page with bogus values so I can be sure that the HTML/CSS works before I work on the backend. When the HMTL looks nice, I then take whatever sections I need for output in PHP and use those accordingly. This method also addresses fundamental concerns about your interface, and might actually help you when structuring your code. It might seem like a longer way to go about it at first, but it certainly saves me a lot of time and frustration to not have to deal with output styles when using PHP.
精彩评论