1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Insert <br> tag correctly

Discussion in 'HTML & Website Design' started by dabidovic123, Jul 30, 2022.

  1. #1
    Hi,

    I inserted this code:
    
      echo '<h2 style="display: inline;">Payment Type:</h2><p style="display: inline;"> ' . $order->get_payment_method_title() . '</p>';
    
    PHP:
    And I want to break a line at the end of the paragraph.
    I tried to add <br> tag in several ways, but it doesn't work!

    Like this :
    
      echo '<h2 style="display: inline;">Payment Type:</h2><p style="display: inline;"> ' . $order->get_payment_method_title() . '</p>' . '<br>';
    
    PHP:
    Or like this:
    
      echo '<h2 style="display: inline;">Payment Type:</h2><p style="display: inline;"> ' . $order->get_payment_method_title() . ',<br> ' . '</p>';
    
    PHP:

    What is the correct way to insert the <br> tag in the first code?

    Thank you,
    SEMrush
     
    Last edited: Jul 30, 2022
    dabidovic123, Jul 30, 2022 IP
    SEMrush
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,022
    Likes Received:
    1,599
    Best Answers:
    27
    Trophy Points:
    475
    #2
    Is this some assignment or something? Why can't you just put it right after </p>? Put two for good measure.

    echo '<h2 style="display: inline;">Payment Type:</h2><p style="display: inline;"> ' . $order->get_payment_method_title() . '</p><br><br>';
    Code (markup):
     
    qwikad.com, Jul 30, 2022 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    27,948
    Likes Received:
    4,333
    Best Answers:
    123
    Trophy Points:
    665
    #3
    If all you really want is some white space after the paragraph try adding margin-bottom

    echo '<h2 style="display: inline;">Payment Type:</h2><p style="display: inline; margin-bottom: .25em;"> ' . $order->get_payment_method_title() . '</p>';
    Code (markup):
    or it might just be that the <br> needs to be <br /> but the right way is to use the style (or even better a class).

    Does the display: inline make sense to you? paragraphs are inline already.
     
    sarahk, Jul 30, 2022 IP
  4. dabidovic123

    dabidovic123 Greenhorn

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Thank you @ qwikad.com & @ sarahk for your replies,
    Yes, the display: inline makes sense, because I want to display the information in one row.

    I set '</p><br><br>'
    And it seems to work properly.

    Thanks for your help,
     
    dabidovic123, Jul 30, 2022 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    27,948
    Likes Received:
    4,333
    Best Answers:
    123
    Trophy Points:
    665
    #5
    except that paragraphs are already inline. What have you got in the method title that would stop that from happening?
     
    sarahk, Jul 30, 2022 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,635
    Likes Received:
    1,971
    Best Answers:
    249
    Trophy Points:
    515
    #6
    1) why are you crapping style into the markup violating the separation of concerns?

    2) why would you use a BR to do margin's job? There's no thematic break in flow there.

    3) if they're inline the margin should be ignored, try inline-block.

    4) Float might be better here too. float:left; the heading and let the paragraph just do its thing. No extra code needed.

    5) this almost looks like tabular data or a candidate for definition lists, not a heading and paragraph. The paragraph in particular since "payment type" is highly unlikely to be one or more complete sentences forming a singular thought.

    Remember, P is for grammatical paragraph. Not a snippet of text, not something you just want a line break after, but a PARAGRAPH. 3rd grade English, PARAGRAPH!
     
    deathshadow, Aug 1, 2022 IP
  7. dabidovic123

    dabidovic123 Greenhorn

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    Hi @deathshadow,
    The "inline-block" worked too.
    But "float:left;" did not work in this case.

    Thank you very much,
     
    Last edited: Aug 3, 2022
    dabidovic123, Aug 3, 2022 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,635
    Likes Received:
    1,971
    Best Answers:
    249
    Trophy Points:
    515
    #8
    crapping inline styles in (which should NEVER be done) this doesn't fly?

    
    echo '
    	<h2 style="float:left;">Payment Type:</h2>
    	<p style="margin-bottom:1.5rem;">', $order->get_payment_method_title(), '</p>';
    
    Code (markup):
    Also killing off the garbage string addition, adding whitespace to make output debugging easier, etc, etm.

    So long as something else in your existing styles isn't interfering, that should do the job as good if not better.

    NOT that this looks like a heading and a paragraph.
     
    deathshadow, Aug 3, 2022 IP