Retrieving Stylesheet information from a CSS file

N

Nathan Sokalski

I have an ASPX file in which there are properties that depend on the CSS
properties in a *.css file specified in a link tag, such as:

<link href="mystyles.css" rel="stylesheet" type="text/css"/>

Is there a way to get the classes/properties from this file for use in the
codebehind? In my specific case, I want to know the border-left-width and
border-right-width values, or if these properties are not specified, the
border-width. My reason for needing these is because I must specify the
width for a certain control, but in order to fit inside the containing
control, the sum of the width and the border must be less than a certain
amount. Any ideas? Thanks.
 
W

weston.jossey

I have an ASPX file in which there are properties that depend on the CSS
properties in a *.css file specified in a link tag, such as:

<link href="mystyles.css" rel="stylesheet" type="text/css"/>

Is there a way to get the classes/properties from this file for use in the
codebehind? In my specific case, I want to know the border-left-width and
border-right-width values, or if these properties are not specified, the
border-width. My reason for needing these is because I must specify the
width for a certain control, but in order to fit inside the containing
control, the sum of the width and the border must be less than a certain
amount. Any ideas? Thanks.

Not sure I fully understand your questions, but I'm guessing at what
you're asking... You are attempting to determine the numerical value
of some sort of property specified within the CSS profile, so that you
can replicate this value elsewhere.

Now, off the top of my head (and i'm not an ASP.NET wizard by any
stretch), other than grabbing a width value from an already drawn
object, I can't think of a way to grab that value without physically
reading the file. My suggestion would be to, if you can't find
another solution, pattern match that line in the CSS file. It's not
terribly efficient, nor elegant, but it may hack together what you
need till you get a better response on here.
 
N

Nathan Sokalski

I think that property would accomplish what I want, but unfortunately it
does not seem to be supported (or at least it doesn't seem to be working) in
IE6. I don't know about other browsers, but since IE6 is a relatively common
browser, I need it to work in it. Here is the section of HTML that I used:

<a
style="display:block;max-width:175px;width:500px;background-color:Blue;">Computers/Electronics</a>

The width was definitely more than 175px, so I think I'll have to keep
looking for a solution. But thanks for the suggestion, if CSS was fully
supported I think it would have worked.
 
R

RSH

Nathan,

Could you specify a dynamic width in the css? For example:
..ControlWidthClass
{
width:100%;
}

Then create a table for your control and specify the
class=ControlWidthClass.

Just a thought,
Ron
 
N

Nathan Sokalski

No, that would not work. The reason for this is that the full amount of
space that is taken up by the element is the width+padding+border+margin. As
I have stated, I want the total to be a fixed amount (200px). I know the
padding and margin (both of them are 0px), and in order to calculate the
width I must know the border. Using width:100%; would not leave the space
necessary for the border.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top