简体   繁体   English

如何设置PHP生成标签的样式?

[英]How to style PHP generated tags?

Which is better inline styling or linking a redundant stylesheet? 哪种更好的内联样式或链接冗余样式表? What i mean by redundant is, when you want to generate different outputs for different results, that can mean many different styling for a specific tag in the css markup. 我的意思是多余的,当你想生成不同的结果不同的输出,这可能意味着在CSS标记特定的标签很多不同的造型。

Separating your styles into stylesheets is almost always preferable to inline style attributes. 将样式分成样式表几乎总是比内联style属性更可取。 You can assign classes to tags in your PHP output, which are then styled in your CSS stylesheets. 您可以将类分配给PHP输出中的标记,然后在CSS样式表中对其进行样式设置。 It is trivially easy to restyle all elements of a tag type or class by modifying the stylesheet then. 通过修改样式表来轻松更改标签类型或类的所有元素的样式非常容易。

Separate stylesheets are also crucially important if you wish to use the same HTML markup to produce different visual styles for different screen/device types such as mobile devices. 如果您希望使用相同的HTML标记为不同的屏幕/设备类型(例如移动设备)产生不同的视觉样式,那么单独的样式表也至关重要。

A tag is a tag is a tag. 标签是标签是标签。 It is on the client. 它在客户端上。 The client has no idea that the tag was created by PHP, .NET or someone typing on a keyboard on the moon. 客户不知道该标签是由PHP,.NET或在月球上的键盘上打字的人创建的。

Use a stylesheet and class names. 使用样式表和类名称。 It's better to use an external stylesheet so the browser can cache it on subsequent page loads. 最好使用外部样式表,以便浏览器可以在后续页面加载时将其缓存。

<div class="...."></div>

div.happy {
    color:#00ff00
}

div.sad {
    color:#ff0000
}

allways use linked styles, its usefull when you want to make templates and because it will go to cache your page will open faster , aslo you will score more on search bots (eg. googlebot) and you page can be higher ranked 始终使用链接样式,它在您要制作模板时很有用,并且因为它将去缓存您的页面,因此打开速度更快,也可以在搜索引擎(例如googlebot)上获得更高的评分,并且您的页面排名可以更高

for linking use something like 用于链接使用类似

<link type="text/css" rel="stylesheet" href="http://yourURL/css/styles.css" media="screen" />

php can output for you html and you can apply css to it php可以为您输出html,并且您可以将CSS应用于它

echo '<div id="something"><a class="link"><span><h1>text</h1></span></a></div>";

and you can use 你可以使用

#something {
 font-size:10px;
}
.link{
color:#333
}
a.class{
font-weight:bold;
}
a span {
 text-align:right;
}
h1{
 color:red
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM