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

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : 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 April 22nd, 2017, 11:30 PM
Authorized User
 
Join Date: Mar 2017
Posts: 55
Thanks: 12
Thanked 0 Times in 0 Posts
Default CSS Question

I'm reading an example of CSS where 2 selectors are separated by a "space" which would indicate an AND relationship, correct?

For example, if we see:

h2 .special {color: white;}

That would indicate that only h2 elements with a class of special get a white color.

So: <h2 class="special">Hello there.</h2>
Should show white text for the "Hello There", am I correct?

I tried to do this and it did not work. Here is my full code:

Code:
     <style>
      body {
        background-color: black;
        color: red;
        font-size: 20px;
        font-weight: 800;
      }
      h1 {
        color: greenyellow;
        font-size: 26px;
      }

      h2 .special {
        color: white;
      }
    </style>
</head>  
<body>
    <h1>Good News Productions!</h1>
    <h2 class="special">Hello there.</h2>
    <h3>Level 3 Header</h3>
    I am test text.
    <div >
      <h2>I am a header within a div</h2>
      And I am div text!    
    </div>
</body>
The result in the browser is:

The h2 element is still red.
Now...if I use:

h2.special {color:white;}

Then it works.

What am I doing wrong?

Revision: Okay, I think I figured this one out. It's inheritance.
Question: would there ever be any elements that are within a header element? A <span>?
Or is h2 .special a bad example whereas p .special would make more sense?

Last edited by papadan; April 22nd, 2017 at 11:41 PM.. Reason: Figured it out.
 
Old April 26th, 2017, 02:39 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
an example of CSS where 2 selectors are separated by a "space" which would indicate an AND relationship, correct?
A space would indicate an element that contains a nested element with that class applied. Without a space (i.e. p.SomeClass) implies a p element with that class directly.

>> Question: would there ever be any elements that are within a header element? A <span>?

Yep, that's certainly common.

>> Or is h2 .special a bad example whereas p .special would make more sense?

Nope, that could be an option if you needed to highlight specific content within that h2.

Hope this helps.

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:
papadan (April 26th, 2017)





Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS Question papadan BOOK: Beginning ASP.NET for Visual Studio 2015 1 November 20th, 2017 12:40 AM
CSS Question papadan BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 1 April 2nd, 2017 03:24 PM
3-Column CSS Question kwilliams CSS Cascading Style Sheets 2 April 8th, 2008 02:33 PM
Question on First CSS savoym CSS Cascading Style Sheets 2 February 1st, 2007 10:02 AM
CSS question Edward King CSS Cascading Style Sheets 1 September 16th, 2005 01:02 PM





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