Remove space above and below

tag HTML

前端 未结 7 1626
眼角桃花
眼角桃花 2020-11-30 07:10

Take this ul for example:

相关标签:
7条回答
  • 2020-11-30 07:46

    There are two ways:

    The best way is to remove the <p> altogether. It is acting according to specification when it adds space.

    Alternately, use CSS to style the <p>. Something like:

    ul li p {
        padding: 0;
        margin: 0;
        display: inline;
    }
    
    0 讨论(0)
  • 2020-11-30 07:53

    In case anyone wishes to do this with bootstrap, version 4 offers the following:

    The classes are named using the format {property}{sides}-{size} for xs and {property}{sides}-{breakpoint}-{size} for sm, md, lg, and xl.

    Where property is one of:

    m - for classes that set margin
    p - for classes that set padding
    

    Where sides is one of:

    t - for classes that set margin-top or padding-top
    b - for classes that set margin-bottom or padding-bottom
    l - for classes that set margin-left or padding-left
    r - for classes that set margin-right or padding-right
    x - for classes that set both *-left and *-right
    y - for classes that set both *-top and *-bottom
    blank - for classes that set a margin or padding on all 4 sides of the element
    

    Where size is one of:

    0 - for classes that eliminate the margin or padding by setting it to 0
    1 - (by default) for classes that set the margin or padding to $spacer * .25
    2 - (by default) for classes that set the margin or padding to $spacer * .5
    3 - (by default) for classes that set the margin or padding to $spacer
    4 - (by default) for classes that set the margin or padding to $spacer * 1.5
    5 - (by default) for classes that set the margin or padding to $spacer * 3
    auto - for classes that set the margin to auto
    

    For example:

    .mt-0 {
      margin-top: 0 !important;
    }
    
    .ml-1 {
      margin-left: ($spacer * .25) !important;
    }
    
    .px-2 {
      padding-left: ($spacer * .5) !important;
      padding-right: ($spacer * .5) !important;
    }
    
    .p-3 {
      padding: $spacer !important;
    }
    

    Reference: https://getbootstrap.com/docs/4.0/utilities/spacing/

    0 讨论(0)
  • 2020-11-30 07:57

    <p> elements generally have margins and / or padding. You can set those to zero in a stylesheet.

    li p {
        margin: 0;
        padding: 0;
    }
    

    Semantically speaking, however, it is fairly unusual to have a list of paragraphs.

    0 讨论(0)
  • 2020-11-30 08:00

    Look here: http://www.w3schools.com/tags/tag_p.asp

    The p element automatically creates some space before and after itself. The space is automatically applied by the browser, or you can specify it in a style sheet.

    you could remove the extra space by using css

    p {
       margin: 0px;
       padding: 0px;
    }
    

    or use the element <span> which has no default margins and is an inline element.

    0 讨论(0)
  • 2020-11-30 08:04

    CSS Reset is best way to use for this issue. Right now in reset we are using p and in need bases you can add any number of tags by come separated.

    p {
        margin:0;
        padding:0;
    }
    
    0 讨论(0)
  • 2020-11-30 08:11

    <p> tags have built in padding and margin. You could create a CSS selector combined with some javascript for instances when your <p> is empty. Probably overkill, but it should do what you need it to do.

    CSS example: .NoPaddingOrMargin {padding: 0px; margin:0px}

    0 讨论(0)
提交回复
热议问题