How to remove div backgrounds?


Problem :

I have an div element in website markup as follows.

<div id="mainContainer" class="container" runat="server">

I have assigned it a css class as follows.

div#mainContainer.container {
        width: 100%;
        margin: 0 auto;

Now after a button click I want to remove only the background of that div and don't want to tamper any positioning of elements inside it. And btw I am using to create this website. How can I do that ?

Solution :

If you want to achieve this in a server-side event, you'll need to add the runat="server" attribute to your <div> element, and it will need an id attribute. This will make it easy to alter server-side.

You'll need an event-handler method in your code-behind for the button click.

In this event handler, do something like (this assumes the id of your <div> is "container")

container.Style["background"] = String.Empty;

However, in your question, you say you've assigned your element a class. If this is the case, the above might not work. It might be easiest to define another CSS class without this background image rule, and then in the code-behind do this:

container.Attributes["class"] = "newClass";

    CSS Howto..

    how to prevent transformation of text inherited from a skewed parent

    How to use metro ui css sidebar and compact classes

    How slow are CSS media-queries?

    How to remove string that dosn't have an html tag using CSS

    How to set css style dynamically with angularjs?

    How can I create a DIV that expands UP TO a height and then shows a scrollbar?

    How to keep Div rotated with css after flip?

    How can I make a div height automatically fit screen and expands if the content exceeds height

    how to place last div into right top corner of parent div? (css)

    How to change navbar background color after page has scrolled down

    How to Change CSS Styling on a Checkbox on Hover with JQuery

    How to make the same distance between tags with only CSS?

    How to create an overlay to be used under a pop up

    How can I make LIs push their siblings to the same height?

    How to get position of div inside td

    How to make a CSS button work correctly?

    How to insert CSS code into a page if I can't insert it into head tag? Only inline mode?

    how to center horizontally div and span elements using css

    CSS - HTML how to make the anchor image go to a specific spot

    Bootstrap: How to obtain plain border in input field?

    How to make rollover images in CSS using multiple image backgrounds and :hover pseudo

    How to get rid of spaces with CSS

    How do I center bootstrap's carousel? Not the images, the carousel itself

    How to get CSS background property to work with toggleClass() in jQuery?

    How could I achieve the same navigation using CSS3? (currently flash AS3)

    jQuery toggle slides DIV up and down, but UL content animates left to right. How can I make the content slide up and down?

    How to fix width of DIV that contains floated elements?

    How to draw realistic smooth slit shadow with Pure CSS3?

    How do I display content in a way like UICollectionView on the web?

    my website not worked in Ipad and how I can fix some small issue? [closed]