将Php和Css结合在一起? [英] Combining Php and Css together?

查看:112
本文介绍了将Php和Css结合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php编程的新手......

我正在自学这门语言。



i create一个基本的PHP程序,现在我想要dd css风格。



我该怎么做?



我可以将css代码添加到php代码中吗?

或者我可以在php代码中定义单独的css文件来访问css文件吗?



 <?  php   

echo '< form id = form1 name = form1 方法 = post action = > '。
'< p > PASWORD < br >
'< 输入 type = text 名称 = name0 id = text {color:red; text- align:center;} / > < br > < br > '。
'< p > BACKLINK < br >
'< 输入 type = text 名称 = name0 id = text / > < br > < br > 的。
'< p > 您的姓名< br >
'< 输入 type = text 名称 = name id = text / > 的。
'< br > ;。
'< 输入 类型 = 提交 名称 = 输入 id = 输入 value = 输入 / > '。
'< / form > < /跨度>';
?>





i添加了这个CSS短代码,为文本着色并居中。



 {颜色   red;   text-align    center; } 

解决方案

也许您不太了解PHP或任何角色其他服务器端技术。它旨在提供任何内容,而不是特别是HTML或特别的东西。



首先,大多数情况下,你有静态CSS,并将其完全添加到同一个在静态HTML中,与PHP无关:

http://www.w3schools。 com / css / css_howto.asp [ ^ ]。



在这种情况下,无论是通过PHP生成的HTML文件还是完全静态的HTML文件,语法总是相同的。



也许您需要动态计算CSS元素。 in也可以在服务器端生成为PHP。然后,当您为CSS生成PHP标头时,您只需要使用内容类型text / css: http:// php.net/manual/en/function.header.php [ ^ ]。



可以这样做:

 < span class =code-pagedirective><?php  
// 我们会输出PDF
标头(' Content-type:text / css');

...你的CSS声明来自:
echo li {...};
...

?>





对于样式,最重要的是避免所有那些ad-hoc 样式属性,并始终在HTML文件中使用CSS类或单独使用CSS类在几个HTML文件中重复使用。



-SA


我的朋友,


我会带你到你居住的小巷,帮助你理解PHP,HTML,CSS和JavaScript的全部内容。我必须在这里提一下,我将简化SA Kryukov爵士的答案。



所以朋友,让我们来看看HTML:

1.标记语言(使用标签构建):标签在浏览器中解析,浏览器实际显示对象,格式化,颜色等等。这就是为什么每个浏览器显示的页面略有不同。



2. HTML用于网页的布局定义(不是网站:它是通过超链接链接在一起的网页集合,通常存储在一台机器上)。 />


3.通过HTML,您可以创建网站的前端。您可以通过HTML定义页眉,页脚,正文,导航,侧边栏等。



4. HTML支持添加非html内容也可通过某些标签添加,例如< script>标签用于javascript,< style>标签用于定义CSS



现在,我们将讨论CSS:

1. CSS(级联样式表) ):实际上你可以说语言,用于设置你通过HTML定义的布局。



2.你可以直接在全球范围内设置特定标签的样式例如: a {background:#00eeee; } 将使网页的所有超链接都具有黄色背景。



3.您还可以为自己设置特定标签的样式被封装在另一个标签内。例如:如果您要使所有< p> 标记的字体系列为Verdana,它们位于< ; span> tag;你可以写 span p {font-family:Verdana}



4.你也可以定位一个使用类(用于组)和ID(用于唯一个体)的特定组或完全唯一的元素,并独立地设置它们。



现在,足够关于HTML和CSS。两者都是静态的,但是,当你想要生成一个页面,这个页面实际上是在用户请求时生成的,就像搜索结果或博客上的特定帖子一样。那么?



好​​朋友,这里有脚本语言世界。脚本语言就像C,C ++等其他任何语言一样,但区别在于它们是Web开发语言。



基本上有两种类型的脚本。它们是:

1.服务器端脚本:示例PHP,ASP,ASP.Net,JSP等

2.客户端脚本:示例Javascript



现在,我们来谈谈PHP。



PHP是一种服务器端脚本语言。通过脚本语言,我的意思是您可以使用这种语言来定义自己的逻辑。因此,您可以根据满足的条件做一些工作。例如: if-else switch-case 等;或者,您可以循环遍历特定的代码块,以实现重复性工作而无需太多代码。例如:,而 do-while foreach



作为服务器端脚本语言,它只在服务器端运行。这意味着,在客户端没有执行任何代码,整个脚本在服务器端执行,结果通过Web服务器传输到客户端。



现在,这种技术的好处是你可以根据某些条件生成HTML代码或使用Loop等生成重复的HTML块。因此,我可以生成搜索结果页面。其中,我有一个存储了所有搜索结果的变量,我可以遍历它并显示所有内容。此外,我还将添加HTML标记以及响应,因此在服务器上解析整个脚本的结果将只生成纯HTML(实际上是纯二进制文件。您可以设置它的mime类型,使其行为像任何东西一样让它传递任何内容甚至图像或视频都可以传输,而不仅仅是HTML酷吧?)。



现在,您的问题:您想在页面中添加样式表你是通过PHP生成的。现在,您知道,PHP是如何工作的以及它实际上在做什么,您知道,与普通的HTML页面类似,您必须编写

< link rel =stylesheethref =global.csstype =text / css/> 在你回显< head>的部分内的php echo中; 标记,因为< link> 标记放在< head> 标记中。



这是一个简单的代码:

我也可以混用HTML和PHP。 PHP部分总是放在<?php?> 标记块中,而HTML可以放在任何地方。如果必须将HTML放在<?php?> 标记块中。然后你实际上必须使用print或echo函数打印它。

 <   html  >  
< head >
< title > 测试< / title >
< style type = text / css >
p {
font-face Verdana;
}
< / 样式 >
< / head >
< body >
//这是一个评论


message =Hello World; //这是PHP中的一个变量。它的值是Hello World
echo'< p >

I'm new to the php programming...
and i'm doing self learning about the language.

i create a basic php program and now i want to dd css style into it.

how can i do that?

can i add css codes into php code?
or else can i define separate css file in php code to access the css file?

<?php

 echo '<form id="form1" name="form1" method="post" action="">'.
'<p>PASWORD<br>'.
'<input type="text" name="name0" id="text" {color:red;text-align:center;} /><br><br>'.
'<p>BACKLINK<br>'.
'<input type="text" name="name0" id="text" /><br><br>'.
'<p>Your Name<br>'.
'<input type="text" name="name" id="text" />'.
'<br>;'.
'<input type="submit" name="Enter" id="Enter" value="Enter" />'.
'</form>';
?>



i added this CSS short code to colour the text and center it.

{color:red;text-align:center;}

解决方案

Perhaps you don't quite understand the role of PHP or any other server-side technology. It's designed to deliver any content, not specifically HTML or something in particular.

First of all, most often you have static CSS and add it exactly in the same was as in static HTML, which has nothing to do with PHP:
http://www.w3schools.com/css/css_howto.asp[^].

In this case, it does not matter if the HTML file generated via PHP or if it is completely static, the syntax is always the same.

Perhaps you need to calculate CSS elements on the fly. The in could also be generated as PHP on the server side. Then you simply need to use content type "text/css" when you generate a PHP header for CSS: http://php.net/manual/en/function.header.php[^].

It could be done this way:

<?php
// We'll be outputting a PDF
header('Content-type: text/css');

... your CSS declarations come here:
echo "li { ... }";
...

?>



With styles, the most important thing is to avoid all those ad-hoc style attributes and always use CSS classes, in the HTML files or separate, to be re-used in several HTML files.

—SA


My Friend,

I will take you down the alley where you live and help you understand what PHP, HTML, CSS and JavaScript are all about. I must mention here though that I will be simplifying the answer of Sir SA Kryukov.

So friend, Let's have a look at HTML :
1. A Markup Language (Built using tags): The tags are parsed in the browser and browser actually displays the objects, format it, color it etc. (That's Why each browser displays the same page slightly different.

2. HTML is used for layout definition of a webpage (not a website: its a collection of webpages linked together via hyperlinks and are stored on a single machine (generally)).

3. Via HTML you create the front-end of your website. You define, the header, footer, body, navigation, sidebar etc via HTML.

4. HTML support addition of non-html content to be added also via some tags like <script> tag is used for javascript, <style> tag is used to define CSS

Now, We will talk about CSS :
1. CSS (Cascading Stylesheet): It is actually you can say language, for styling the layout that you have defined via HTML.

2. You can directly style a particular tag globally For example : a { background: #00eeee; } will make all the hyperlinks of the webpage to have a background of yellow.

3. You can also style a particular tag that itself is encapsulated inside another tag. For example: If you want to make all the <p> tags to have a font-family of "Verdana" which are lying inside a <span> tag; you can write span p { font-family: "Verdana" }

4. You can also target a particular group or a completely unique element using class (for group) and ID (for unique individual) and style them independently.

Now, enough about HTML and CSS. Both are Static to themselves but, when you want to generate a page which is actually generated at the time a user has requested it like a search result or a particular post on a blog. Then?

Well Friend, here comes the world of scripting languages. Scripting languages are like any other language like C, C++ etc but the difference is that these are web development languages.

There are basically two types of scripting. These are :
1. Server-Side Scripting : Example PHP, ASP, ASP.Net, JSP etc
2. Client-Side Scripting: Example Javascript

Now, let us talk about PHP.

PHP is a server-side scripting language. By scripting language, I mean that you can use this language to define your own logic. Thus, you can do some work based on the condition that satisfies. Examples are : if-else, switch-case etc; or, you can loop through a particular block of code to realize a repetitive work without much code. Examples are : while, do-while, for, foreach.

Being, a server -side scripting language, it is run only on server side. That implies that, No part of code is executed on client side, the whole script is executed on server side and it's result is transferred via a web server to client side.

Now, the benefit of this technique is that you can generate HTML codes based on some conditions or generate a repetitive HTML block using Loop etc. Thus, I can generate a search result page. Wherein, I have a variable that has stored all the search result and I can loop through it and display all the content. Moreover, I will also add HTML tags along with the response, so the result of the whole script parsing at server will generate simply a pure HTML (in fact a pure binary. You can set it's mime-type to make it behave like anything thereby making it deliver any content even images or videos can be transmitted not just HTML Cool right?).

Now, Your question: You wanted to add stylesheet to your page that you had generated via PHP. Now, that you know, how PHP is working and what actually is it doing, you know, that similar to a normal HTML page, you have to write the
<link rel="stylesheet" href="global.css" type="text/css" /> in the php echo inside the part where you have echoed the <head> tag since <link> tag is put in the <head> tag.

this is a simple code :
I can mix HTML and PHP too. The PHP part is always put inside a <?php ?> tag block while HTML can be put anywhere. If you have to put HTML inside the <?php ?> tag block. Then you actually have to print it using either print or echo function.

<html>
<head>
  <title>Test</title>
  <style type="text/css">
  p {
      font-face: "Verdana";
  }
  </style>
</head>
<body>
   // This is a comment


message = "Hello World"; // This is a variable in PHP. Its value is Hello World echo '<p>'.


这篇关于将Php和Css结合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆