Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 26th, 2015, 03:22 PM
Authorized User
 
Join Date: May 2013
Posts: 59
Thanks: 10
Thanked 0 Times in 0 Posts
Default move code from CSS to a master page

Ok, I have this code in my css file that my master page uses:
header{background-color:white;width:100%;height:140px;background-image:url(Images/Logo.png);background-repeat:no-repeat;background-position:center;}
header a{width:100%;height:86px;display:block;}

I want to move this to my head section of my master page.
I use
<style> </style> and just put inside the code (above).Then I have at the body of my master page a <header> section ....but when I do this, the picture does not show!
Any tips what I am doing wrong?
 
Old June 27th, 2015, 01:46 AM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

is this at run time that your images are not rendering or at design time. resources such as CSS or images are relative to the execution path.
 
Old June 27th, 2015, 11:32 AM
Authorized User
 
Join Date: May 2013
Posts: 59
Thanks: 10
Thanked 0 Times in 0 Posts
Default

I don't understand what you are saying....
 
Old June 28th, 2015, 02:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The CSS you include in the Master Page eventually ends up in the page itself in the browser. If you have a page in the root, you'll end up with something like this:

background-image:url(Images/Logo.png);

which will look for the image in the Images folder in the root of the site.

However with a sub folder (such as /Products/Default.aspx) the image is searched for in a *sub folder of the Products folder* which won't work.

You need to use a root-based path instead:

background-image:url(/Images/Logo.png);

which will always look for the image in the Images folder in the root.

Chapter 7 has all the details.

Why are you adding this to the master page? It's much better to have it in the main CSS file as it can be cached and isn't downloaded with each page.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 28th, 2015, 03:29 PM
Authorized User
 
Join Date: May 2013
Posts: 59
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Hi Imar and thank you.
So, you mean if I put it in the master page I should do something like that?
background-image:url(../App_Themes/Monochrome/Images/Logo.png)

Thank you
 
Old June 28th, 2015, 03:44 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You should drop the two dots and use this instead:

/App_Themes/Monochrome/Images/Logo.png

so it always starts at the root of the site, regardless of the location of the page that uses the master page.

Can I ask again: why do you have this in you Master Page?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 28th, 2015, 04:03 PM
Authorized User
 
Join Date: May 2013
Posts: 59
Thanks: 10
Thanked 0 Times in 0 Posts
Default

ok the reason for trying to do this is probably stupid.
I checked my website at website speed test and it shows the logo.png takes 2,5 kb to load...I thought if I moved it in the master page and Not have it in CSS it would improve performance?
 
Old July 1st, 2015, 08:22 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It wouldn't make a difference. The logo is still downloaded from the same location and cached for subsequent requests.

However, by adding more code to the master, each page is now bigger as that CSS needs to be downloaded for each request, instead of being cached locally from the CSS file.

And 2.5KB isn't bad for a logo.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
dksellou (July 1st, 2015)





Similar Threads
Thread Thread Starter Forum Replies Last Post
CH6 - master page not applying css correctly mikeal_a BOOK: Beginning ASP.NET 4 : in C# and VB 4 May 19th, 2011 04:41 PM
Master Page Method: Code-Behind for Content Page kwilliams ASP.NET 2.0 Professional 3 June 2nd, 2008 12:57 PM
Creating a Master Page and Importing a CSS rubends BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 6 March 14th, 2008 03:56 AM
Add dynamic css to master/content page proj-How? VictorVictor ASP.NET 2.0 Basics 6 June 9th, 2006 12:09 PM
Creating a Master Page and Importing a CSS rubends BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 April 19th, 2006 03:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.