0

I would like to know if there is a way to use a particular css page as styling for a tag. For example, instead of

<div class="header" style="position: absolute; text-align:left; right: auto; margin: 0 auto 20px; z-index: 1; width: 60%; height: auto; left:9%">

Is there a way to specify style.css for the div tag?

For example,
This style.css must ONLY apply to the div tag above. Also, is it possible for all tags contained within that div tag to follow the same specified css page?

Prajeeth Emanuel
  • 647
  • 1
  • 12
  • 24

4 Answers4

0

Put this in the header of your page

<head>
     <link rel="stylesheet" href="/styles.css" type="text/css">
</head>
Pastor Bones
  • 7,183
  • 3
  • 36
  • 56
  • That's not the answer I was looking for. I meant a stylesheet for just the tag or preferably all tags within those. – Prajeeth Emanuel Oct 31 '13 at 17:41
  • Then your answer is NO. You cannot specify a certain file specifically and only for one tag and it's children. However, you can give the div a specific id and use that to differentiate within your stylesheet – Pastor Bones Oct 31 '13 at 17:44
  • 1
    I've actually been reading about http://www.w3.org/TR/2002/WD-css-style-attr-20020515. 2.4 states that a css file can be used but it doesn't seem to be working. – Prajeeth Emanuel Oct 31 '13 at 17:48
  • 1
    @Prajeeth Emanuel: *sigh* http://stackoverflow.com/questions/9884182/why-dont-we-import-css-in-a-div/9884214#9884214 http://www.w3.org/TR/css-style-attr/ – BoltClock Oct 31 '13 at 17:56
  • @Pastor Bones: That is anything but new. It's 11 years old. – BoltClock Oct 31 '13 at 17:56
  • Thanks for that info, I googled my question and it led me there. – Prajeeth Emanuel Oct 31 '13 at 17:59
0

If you want to specify style for a page, include that CSS when you render the page.

If you want to have multiple ways of rendering a particular tag, differentiate the tags.

I'm not aware of conditional logic you can apply to the CSS directly.

John
  • 15,990
  • 10
  • 70
  • 110
  • Again this isn't the answer I was looking for. Please read the question again. – Prajeeth Emanuel Oct 31 '13 at 17:44
  • If you have two people trying to answer your question, and neither one is giving the answer you're looking for, might not it be the case that you need to ask your question more clearly? – John Oct 31 '13 at 17:46
  • I understand it's not a common question. I'll edit it to give more clarity. – Prajeeth Emanuel Oct 31 '13 at 17:51
  • Thank you for doing that. For future reference, the less that potential answerers need to discover what you really need, the better. (And welcome to Stack Overflow.) – John Oct 31 '13 at 17:54
0

HTML: (include this in the head)

<link href='style.css' rel='stylesheet' type='text/css'/>

CSS: (in the style.css file)

div.header{
    //your style here
}

or without the class:

div{
    //your style here
}

but without the class it will get all div tags so I recommend the first code

123
  • 515
  • 1
  • 5
  • 20
  • I was looking for a way to include the css page as styling for a tag but apparently it is obsolete and no longer being used. I'd settle for this answer but technically can't accept it. – Prajeeth Emanuel Nov 07 '13 at 13:04
0

You can create the CSS page you want and then create the styling you want inside something like this

div > table {

padding: 5px;

} 

That would make the div have a padding of five as well as it's child the table a padding of 5

jmespinosa
  • 245
  • 1
  • 6
  • 9