Cleaning up the <br> tags and replacing with CSS

Discussion in 'CSS' started by forumposters, Mar 23, 2007.

  1. #1
    I have a page with about 20 or so <br> tags scattered throughout. I'd like to take all these out and make the same formatting happen without cluttering up my code. How can I do this with CSS?
     
    forumposters, Mar 23, 2007 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    Why are the <br>s there? Are they simulating paragraphs, in lieu of proper markup? Are they acting as padding or margins? How about giving us something to work with? A link would be nice.

    cheers,

    gary
     
    kk5st, Mar 23, 2007 IP
  3. grg

    grg Guest

    Messages:
    2,692
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What a question? Use div's.
     
    grg, Mar 23, 2007 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    What an answer. The div element is for grouping other elements; it has no semantic value and is not a substitute for proper semantic markup or for padding or margins.

    gary
     
    kk5st, Mar 23, 2007 IP
  5. grg

    grg Guest

    Messages:
    2,692
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok, you have right. It depends of the context.
     
    grg, Mar 23, 2007 IP
  6. sp111

    sp111 Guest

    Messages:
    22
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There is nothing wrong with the div tag. YOu can use it or you can use css case depending.
     
    sp111, Mar 23, 2007 IP
  7. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #7
    There is nothing wrong with the <br /> tag either. Or is it?
    Would love to hear that.
     
    Clive, Mar 23, 2007 IP
  8. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #8
    No, the br element is perfectly valid with a specific purpose:
    The br element forcibly breaks (ends) the current line of text.

    An example of proper usage:
    
    <p>Please respond by mail to:</p>
    <p>XYZ Co.<br>
    1000 Main St.<br>
    Sometown, Anystate </p>
    Code (markup):
    Using the br to simulate a paragraph, or to create spacing is a misuse, structurally and semantically wrong. eg.
    
    <br><br>Please respond by mail to:<br><br>
    XYZ Co.<br>
    1000 Main St.<br>
    Sometown, Anystate <br><br>
    Code (markup):
    cheers,

    gary
     
    kk5st, Mar 23, 2007 IP
  9. Crimsonc

    Crimsonc Peon

    Messages:
    616
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I was going to ask...why would you want to get rid of it?
     
    Crimsonc, Mar 26, 2007 IP
  10. crazybjörn

    crazybjörn Peon

    Messages:
    270
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #10
    div tags are pretty much useless without CSS, so they go hand in hand, not separately :p
     
    crazybjörn, Mar 27, 2007 IP
  11. forumposters

    forumposters Peon

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #11
    So, tell me if this sounds right. Instead of using brs, I can assign a div element for all my blocks of text and put something like this inside of each selector that needs line breaks below it:

    padding-bottom:15px;

    Is that correct?
    Is this good form?
    What are the other common ways to do this sort of thing?
     
    forumposters, Mar 27, 2007 IP
  12. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #12
    No. The div element is an aggregating element. It's job is to group other elements to form a new styling context. Text is marked up with the p or blockquote or another block level container that describes what the content is.

    Post your content with the markup you're using. We'll show you just how it should be marked up.

    cheers,

    gary
     
    kk5st, Mar 27, 2007 IP
  13. forumposters

    forumposters Peon

    Messages:
    270
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I have this in my .css file:

    .thumbtable {
    margin-left:9px;
    }
    .photodesc {
    padding-bottom:15px;
    }
    .job {
    padding-bottom:15px;
    }

    And, now I have this in my HTML page:
    <p class="job">yada yada</p>
    <p class="photodesc">yada yada</p>
    <p class="thumbtable">yada yada</p>
     
    forumposters, Mar 29, 2007 IP
  14. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #14
    That's better.

    Why duplicate the padding rule? Give both a single class or combine the rules.
    
    
    .caption {
      padding-bottom: 15px;
      }
    =======
    <p class="caption">yada yada</p>
    <p class="caption">yada yada</p>
    <p class="thumbtable">yada yada</p>
    Code (markup):
    Just the snippet alone does not convey the actual semantics or structure, so there may be better ways to do this.

    Until you have advanced enough to combine operations, it is a good idea to start with bare nekkid html (no tables, no fonts, no nuthin' but descriptions of what the content is) markup with no regard to presentation. Just get the structure and semantics right before trying to dress it up. If your content and its markup don't make sense, or if it's hard to use, you haven't yet got it right.

    cheers,

    gary
     
    kk5st, Mar 29, 2007 IP