0

i want to apply the following class to my image element :

.laptopimage {
    width: 115px;
    height: 93px;
    display: block;
    margin-left: auto;
    margin-right: auto;
    border: 10px solid black;
} 

my code in aspx.cs file :

Image image=new Image();
image.ImageUrl="~/Images/"+p.ImagePath;
image.CssClass = "laptopimage";

the resulted html code :

<img class="laptopimage" src="../Images/Laptop1.jpg"></img>

I can't understand why it doesn't apply css. The image is still displayed 1700x1700; Can someone explain why this is happening ?

8
  • 1
    Hard to debug with so little code- it may be a specificity issue, ie. another CSS rule is overriding the styles set in laptopimage Commented Jun 13, 2014 at 10:18
  • 1
    have you added reference of the css file ? Commented Jun 13, 2014 at 10:18
  • did you include your css file for sure? Commented Jun 13, 2014 at 10:18
  • you can try !important property Commented Jun 13, 2014 at 10:18
  • 1
    first order of business, never reference an image that has a larger resolution than the size it will be displayed on the web. one reason is it'll load slower. very unnecessary if it's just a thumbnail Commented Jun 13, 2014 at 10:18

1 Answer 1

2

modify your css and try with this. Some other css might be overiding your laptopimage class

.laptopimage {
    width: 115px !important;
    height: 93px !important;
    display: block;
    margin-left: auto;
    margin-right: auto;
    border: 10px solid black;
} 
Sign up to request clarification or add additional context in comments.

6 Comments

Its generally recommended to avoid !important in place of improving your code and addressing the underlying conflict...developer.mozilla.org/en-US/docs/Web/CSS/…
Not a good idea to just add !important willy nilly without first understanding the root cause of why your style is not being applied.
so i tried it in google chrome, and it works in google chrome. I can't understand why it doesn't work in mozzila firefox
@StefanP : In mozila press Ctrl + shift + delete to clear cache
and yes its not recommended to use !important. But atleast it will give you some hints about css that is overiding your current class
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.