SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to cancel a CSS Declaration?

    It seemed a good idea at the time to define a width for the <p> element:

    #content p { width: 450px; }

    But now after building 80 pages into my CMS, I need <p> to act like normal with no width on certain pages.

    #content .myclass p { width: "not-set"; }

    auto doesn't work, 100% doesn't work. I've considered a javascript solution that messes with class names, but would prefer a css rescue of seven or eight characters!

    tx

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,657
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    If you have the class on the p then it should look like #content p.myclass {}

  3. #3
    Non-Member
    Join Date
    Jun 2010
    Location
    4727′35″N 2618′0″E
    Posts
    1,789
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Switch them. Sort of.

    #content .specialPageThatNeedsWidthOnParagraphs p { width: 450px; }

    #content p { /*width: "not-set";*/ }

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by noonnope View Post
    Switch them. Sort of.

    #content .specialPageThatNeedsWidthOnParagraphs p { width: 450px; }

    #content p { /*width: "not-set";*/ }
    Yes, that would work, but, I have 25 pages of little used old newsletters that require p to be normal and 80 pages of much used info that use the width. I am building this into a CMS that I want non coders to be able to enter content into. I am afraid adding a div to the page would blow their minds.

    The 25 pages are old code that employ inline style declarations in tables.

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess you can't cancel, only replace, so I am going to use php to make it happen. Something like putting in the body tag:
    PHP Code:
    $class ="article alias from db";
    if (
    $class != "myclass"){
     class =
    "regularcontent";
    }
    echo 
    "class=\"".$class."\""
    Hopefully that will do it. Thank you everyone for your help!

  6. #6
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Not 100% if that will work. Is everything in the same directory?
    Ryan B | My Blog | Twitter

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rguy84 View Post
    Not 100% if that will work. Is everything in the same directory?
    No, but "everything" is in a db.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,834
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Gregster606 View Post
    Yes, that would work, but, I have 25 pages of little used old newsletters that require p to be normal and 80 pages of much used info that use the width. I am building this into a CMS that I want non coders to be able to enter content into. I am afraid adding a div to the page would blow their minds.

    The 25 pages are old code that employ inline style declarations in tables.
    Can you distinguish between the pages (a class or id on the body tag or similar)? If so then you could set up the fixed width to only apply for the class or id used by the new pages.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    Quote Originally Posted by Gregster606 View Post
    #content p { width: 450px; }

    But now after building 80 pages into my CMS, I need <p> to act like normal with no width on certain pages.

    #content .myclass p { width: "not-set"; }

    auto doesn't work, [...]
    There is no CSS reason for that not to work (if no other related declarations):
    Code:
    #content p { width: 450px; }
    #content .myclass p { width:auto; }
    - The second selector set back the default value auto
    - The second selector is more specific then the first one

    Have you check the first assumption that you may not target the right element with your second selector ?
    Quote Originally Posted by EricWatson View Post
    If you have the class on the p then it should look like #content p.myclass {}
    Could we have a look to the HTML code ?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •