简体   繁体   中英

Obtaining Background-image from stylesheet using C#

I am trying to get the value of a "Background-image"-tag in a stylesheet which is used on my web-site. The style-sheets are referenced from the HTML file as follows:

<style media="all" type="text/css">
    @import "master.css";
</style>
<style media="all" type="text/css">
    @import "layout.css";
</style> 

The layout.css file contains:

#frontpage-main-features {
    background: url('../elms/frontpage-main-gradient.jpg') no-repeat left top;
    margin-bottom: 10px;
}
#frontpage-main-features-inner {
    width: 700px;
    padding: 20px 20px 10px 20px;
    background: url('../elms/frontpage-main-gradient-bottom.jpg') no-repeat left bottom;
}

In the master.css file a background image is referenced which is then overloaded in the layout.css file by the #frontpage-main-features-inner section. I would very much like to access the "background"-tag in order to see which background image is currently being shown in a specific part of the page. Any suggestions?

Best,

Michael

Why not just use FireBug / the IE8 dev console? load the page, open the console, find the piece of html you are looking for and inspect the css properties, it will give you all applied styles for that element, overridden properties will be striked through...

You're talking about looking at the markup of the page from C#, ie this is the markup that is not an ASP.Net server control and is not viewable by ASP.Net.

Sorry, that's not possible using ASP.Net. You can only view data that is marked for server to view.

Why do you need this? There could be another way to do whatever you are trying to do. Maybe you need to turn the problem around (get markup to get the class name from c#) which is easier.

The problem is that CSS rules are not applied or enforced on the server, they are applied by the client browser. You could perhaps create a parser that goes through the referenced CSS files and figures out what image should be displayed but you really can't know with certainty how the client browser will interpret and apply the CSS rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM