Why is vertical-align:text-top; not working in CSS

后端 未结 9 1961
灰色年华
灰色年华 2020-12-25 09:16

I want to align some text to the top of a div. It seems that vertical-align: text-top; should do the trick, but it doesn\'t work. The other things that I have d

相关标签:
9条回答
  • 2020-12-25 09:48

    You can use margin-top: -50% to move the text all the way to the top of the div.

    margin-top: -50%;
    
    0 讨论(0)
  • 2020-12-25 09:53

    The problem I had can't be made out from the info I have provided:

    • I had the text enclosed in old school <p> tags.

    I changed the <p> to <span> and it works fine.

    0 讨论(0)
  • 2020-12-25 10:01

    You could apply position: relative; to the div and then position: absolute; top: 0; to a paragraph or span inside of it containing the text.

    0 讨论(0)
  • 2020-12-25 10:03

    something like

      position:relative;
      top:-5px;
    

    just on the inline element itself works for me. Have to play with the top to get it centered vertically...

    0 讨论(0)
  • 2020-12-25 10:05
    position:absolute;
    top:0px; 
    margin:5px;
    

    Solved my problem.

    0 讨论(0)
  • 2020-12-25 10:06

    You can use contextual selectors and move the vertical-align there. This would work with the p tag, then. Take this snippet below as an example. Any p tags within your class will respect the vertical-align control:

    #header_selecttxt {
        font-family: Arial;
        font-size: 12px;
        font-weight: bold;
    }
    
    #header_selecttxt p {
        vertical-align: text-top;
    }
    

    You could also keep the vertical-align in both sections so that other, inline elements would use this.

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