How to remove div backgrounds?


Tags: asp.net,html,css

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;
        margin-top:40px;
        height:500px;
        background:url("../img/bgimg.png")no-repeat;
    }

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 ASP.net 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 Can I use CSS to Add an Element Below another Element?

    How to determine the exact 'font-family' CSS value of an uploaded TrueType font?

    How do change CSS Class from Code Behind?

    Hide / show element if text is / isn't to long in jQuery

    How to use css control to focus on div background when href link clicked

    How to CSS two vertical cylinders

    How to make contents vertical align inside div

    how to make an ul lay out horizontally?

    CSS How to set div height 100% minus nPx

    Showing a large amount of HTML alternative content with swfobject & swffit flash site

    How to add a second border around a CSS circle

    How can I use jQuery to add a fade in hover effect to my nav items?

    How to use not css selector with * in stylesheet

    How to use bootstrap grid system overlaying a map

    how to center a div in a td cell and a link inside of it ?both vertically and horizontally?

    How can I send a Jquery var to be used in a CSS property

    Browser sizing Ctrl +/- :: How to manipulate settings?

    How to line up images in a horizontal row with CSS?

    How to finish my modal ajax code to work correctly?

    How to center an image in an img tag using CSS background position

    How to inject javascript var into css

    How can I align unsorted list horizontly ?

    How to reset parent child relationship between nested div

    Hide/Show menu with increase/decrease of width

    how to write .html with .css to custom color text

    How to define CSS anchor text decoration for anchors in a specific container

    How to use jQuery and CSS to write vertical drawer

    CSS:How to properly remove border using CSS when border-radius is used?

    How to assign custom CSS class to arbitrary arbitrary rows of h:dataTable?

    How to create an email template from a responsive website?