0

In the site i'm developing i would like to have users set their own custom "css" on their profile pages.

For example, i give users the ability to select a background color for <body> with a js color picker.

Then with php i create a 'css-ready' string and save it on db.

What i am asking is: how i can make this css apply everytime a user enter another user profile?

Probably will be there a lot of thing a user can customize, so there will be a big css string and i need something that will be cross browser and if possible that work also without javascript..

Thank you.

4

3 に答える 3

1

これは、asp.netのハンドラーを使用して実行できます。PHPでも同様のソリューションが利用できると確信しています。まず、各ユーザーのスタイルプロパティをデータベースに保存する必要があります。スタイルの構文(セレクター名、中括弧、セミコロンなど)が正しいことを確認してください。セッションオブジェクトからユーザー情報を取得するか、クエリ文字列を含む変数をハンドラーに渡すことができます。

ハンドラーから受信した応答は、コンテンツタイプとしてタグ間に直接配置できます-次のようにtext /css:

そしてこれであなたは行く準備ができているはずです!

ただし、ページが読み込まれるたびにファイル全体が読み込まれるため、パフォーマンスが低下します(通常のcssファイルでは、一度だけ読み込まれます)。ユーザーに本当にカスタマイズしてもらいたいアイテムだけをデータベースに保存することをお勧めします。パフォーマンスを向上させるために、親のcssファイルとカスケードすることができます。

于 2012-05-29T06:14:44.050 に答える
1

You could try a php file with header for content-type text/css which echos the CSS according to one fetched from Database, you could add default CSS to your website and just create a last in list of link tags the path to that php files, this way you have a default CSS to fall back and customized CSS to be applied on top of default if defined any..

于 2012-05-28T21:16:26.333 に答える
0

you can use this is user-profile.tpl.php

<?php 
if(isset($account->user_css)){
?>
<style>
<?php echo $account->user_css; ?>
</style>
<?php
}
?>
于 2012-05-29T06:31:32.440 に答える