469,270 Members | 1,793 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

CSS - Replace coded values with data from a database

Hello - I tried posting this to the CSS Forum, but was told to come here instead.
I want to code a CSS file so that I can replace the values for font, size, and color with values that have been derived from a database and put in variables.
I use this approach throughout my application to let users setup various options so I don't have to modify code. (ASP )

Example: <font face='arial'> is coded as
<font face=' " & HD1 & " '> (HD1 is set by reading a "global" table with the font face in it.)

Works great in asp/html, but I have a CSS-driven menu & I want to do the same type of replacement, but I can't get the syntax right. Is this even possible?

Thanks . . . Breck Cogdill
Oct 8 '07 #1
4 1766
jhardman
3,406 Expert 2GB
Breck,

Yes, this should be perfectly doable, but realize that if your css is on a separate file, the web server will not execute any script on that file unless it has file extension .asp. Give an example of what you have tried, and we can try to help you make it work.

Jared
Oct 9 '07 #2
Breck,

Yes, this should be perfectly doable, but realize that if your css is on a separate file, the web server will not execute any script on that file unless it has file extension .asp. Give an example of what you have tried, and we can try to help you make it work.

Jared

Jared - Thank you for you reply, I'm including the CSS info below & sections of other ASP code that relates to the issue.

Quick overview:

I have sites that allow users to set various options, fonts/sizes/colors, etc.

An ASP program - Get Global.asp reads from a d/b table & gets data to be "replaced" in HTML tags.

GetGlobal.asp code:

SQL = "SELECT * FROM GLOBALTABLE "
Set GLB = Server.CreateObject("ADODB.Recordset")
GLB.Open sql,conn
dFont = glb.fields("DefaultFont")
dSize = glb.fields("DefaultFontSize")
-------------------------------------------------------------------------------
Font tags in ASP code:

<font face=' " & dFont & " ' size=' " & dSize & " '>
-------------------------------------------------------------------------------

CSS code in Menu program:

/* defines the format of menu items when the mouse is not over them */
.menuitem_normal
{font: 7pt Arial, sans serif;
color: #5A9ECE;
background-color: #FFFFFF;
line-height: 110%
}

I want to be able to let the users set the font values using values derived from the d/b just like it works in the ASP code.

I know controlling page colors, etc. from a d/b sort of defeats the purpose of CSS, but I don't want to have to modify code to change the values. (Plus, I don't know how to code CSS, or I wouldn't be here in the first place.)

I inherited most of this code, including the Menu which uses the CSS, & I've retrofitted the font tag replacements throughout the application, this is the last place I need to make database-driven & then I won't have to do a thing to change layout colors, fonts, etc. in my package.

Thanks again for helping me with this . . . .Breck Cogdill
Oct 9 '07 #3
Jared - Thank you for you reply, I'm including the CSS info below & sections of other ASP code that relates to the issue.

Quick overview:

I have sites that allow users to set various options, fonts/sizes/colors, etc.

An ASP program - Get Global.asp reads from a d/b table & gets data to be "replaced" in HTML tags.

GetGlobal.asp code:

SQL = "SELECT * FROM GLOBALTABLE "
Set GLB = Server.CreateObject("ADODB.Recordset")
GLB.Open sql,conn
dFont = glb.fields("DefaultFont")
dSize = glb.fields("DefaultFontSize")
-------------------------------------------------------------------------------
Font tags in ASP code:

<font face=' " & dFont & " ' size=' " & dSize & " '>
-------------------------------------------------------------------------------

CSS code in Menu program:

/* defines the format of menu items when the mouse is not over them */
.menuitem_normal
{font: 7pt Arial, sans serif;
color: #5A9ECE;
background-color: #FFFFFF;
line-height: 110%
}

I want to be able to let the users set the font values using values derived from the d/b just like it works in the ASP code.

I know controlling page colors, etc. from a d/b sort of defeats the purpose of CSS, but I don't want to have to modify code to change the values. (Plus, I don't know how to code CSS, or I wouldn't be here in the first place.)

I inherited most of this code, including the Menu which uses the CSS, & I've retrofitted the font tag replacements throughout the application, this is the last place I need to make database-driven & then I won't have to do a thing to change layout colors, fonts, etc. in my package.

Thanks again for helping me with this . . . .Breck Cogdill

Jared - I'm sorry, I neglected to mention that the CSS is in a separate CSS file that is referenced in each ASP program:

<link rel="stylesheet" href="simplemenu2.css" type="text/css">
Oct 9 '07 #4
jhardman
3,406 Expert 2GB
Beck,

1- change the simplemenu2.css to simplemenu2.asp (i think this will work. I've never tried it before, but I belive it should work)

2- Put your db connection code in the simplemenu2.asp

3- List the font code as:
Expand|Select|Wrap|Line Numbers
  1. {font: <%=dSize & " " & dFont%>, sans serif;
That should solve the whole problem (except the "sans serif" part. Css allows for a backup font if the font chosen isn't available on the user's computer. In this case, the css says to use the systems default sans serif font, Arial on most computers, if the chosen font isn't available. It is up to you whether this is good enough.) Let me know if it gives you any more problems.

Jared
Oct 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.