d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Css
Add Reply New Topic New Poll
Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 16 2016 11:30am
I need some example code of one .css file holding the style information of multiple pages.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 16 2016 12:14pm
can you explain what you're trying to gain from it? it sounds like you already know about external css files. here's an example to answer your question, but i dont think it's really gonna give you whatever you're looking for.

this could be your css page:
Code
body {
background-color: lightblue;
}


you can have each html page reference the css page like so:
Code
<link rel="stylesheet" type="text/css" href="mystyle.css">

Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 16 2016 12:33pm
Thanks that will give me the same layout and etc for all my pages right? But if id like a different layout for one or more pages but all on the same .css file rather then having a new file for every different layout.
Code
body {
background-color: lightblue;
}

body (page 2) {
background-color: green;
}
body (page 3) {
background-color: red;
}


So I believe I need the code to reference a html file from the .css rather then the other way around? Maybe I am just organizing things poorly <_<
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jan 16 2016 12:37pm
Quote (SikGod @ Jan 16 2016 01:33pm)
Thanks that will give me the same layout and etc for all my pages right? But if id like a different layout for one or more pages but all on the same .css file rather then having a new file for every different layout.
Code
body {
background-color: lightblue;
}

body (page 2) {
background-color: green;
}
body (page 3) {
background-color: red;
}


So I believe I need the code to reference a html file from the .css rather then the other way around? Maybe I am just organizing things poorly <_<


if you want it all in the same css file, you'll have to use classes


.body-pg2{
background-color: green;
}

then in your html file:
<body class='body-pg2'>

name it whatever makes sense for you.


/edit:
I'm not an expert in CSS. but with that said, i prefer having multiple css files because they're much easier to manage than a single file with thousands of lines. if your concern is performance, you can always use a script that combines them at build time.

i dont have much experience with them, but one of these days i'm going to look into options like sass or LESS to help make managing them easier

http://sass-lang.com/guide
http://lesscss.org/

This post was edited by carteblanche on Jan 16 2016 12:47pm
Member
Posts: 3,439
Joined: Jan 1 2007
Gold: 128,248.52
Jan 16 2016 01:28pm
Perfect thank yeah I may try and do multiple css for now and look into the programs that merge later, like you said should be easier to manage one at a time. Shouldn't be an issue unless I get a great many pages I am thinking
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll