Style class doesn't support margin or padding css properties

J

J055

Hi

I want to add some css rules to the this.Header.StyleSheet property. I need
to add margin and some other css properties but the Style class doesn't
support them. What is the best way or some other options to do this?

// Create a Style object for the body of the page.
Style style = new Style();
style.Width = val;
style.Margin-Left = 20px; // this is what i would like to add

// Add the style to the header of the current page.
this.Header.StyleSheet.CreateStyleRule(style, null, "#container");

Many thanks
Andrew
 
G

Guest

Hi

I want to add some css rules to the this.Header.StyleSheet property. I need
to add margin and some other css properties but the Style class doesn't
support them. What is the best way or some other options to do this?

// Create a Style object for the body of the page.
Style style = new Style();
style.Width = val;
style.Margin-Left = 20px; // this is what i would like to add

// Add the style to the header of the current page.
this.Header.StyleSheet.CreateStyleRule(style, null, "#container");

Many thanks
Andrew

class MyStyle : Style
{
protected override void FillStyleAttributes(CssStyleCollection
attributes, IUrlResolutionService urlResolver)
{
base.FillStyleAttributes(attributes, urlResolver);
attributes[HtmlTextWriterStyle.Margin] = "0 0 0 0";
attributes[HtmlTextWriterStyle.Padding] = "0 0 0 0";
}
}

this.Page.Header.StyleSheet.CreateStyleRule(new MyStyle(), this.Page,
".myRule");
 
G

Guest

I want to add some css rules to the this.Header.StyleSheet property. I need
to add margin and some other css properties but the Style class doesn't
support them. What is the best way or some other options to do this?
// Create a Style object for the body of the page.
Style style = new Style();
style.Width = val;
style.Margin-Left = 20px; // this is what i would like to add
// Add the style to the header of the current page.
this.Header.StyleSheet.CreateStyleRule(style, null, "#container");
Many thanks
Andrew

class MyStyle : Style
{
protected override void FillStyleAttributes(CssStyleCollection
attributes, IUrlResolutionService urlResolver)
{
base.FillStyleAttributes(attributes, urlResolver);
attributes[HtmlTextWriterStyle.Margin] = "0 0 0 0";
attributes[HtmlTextWriterStyle.Padding] = "0 0 0 0";
}
}

this.Page.Header.StyleSheet.CreateStyleRule(new MyStyle(), this.Page,
".myRule");- Hide quoted text -

- Show quoted text -

for Margin-Left rule simply add

attributes[HtmlTextWriterStyle.MarginLeft] = "20px";
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top