Can you do this HTML layout without using tables?

前端 未结 10 1113
心在旅途
心在旅途 2020-12-04 06:23

Ok, I had a simple layout problem a week or two ago. Namely sections of a page needed a header:

+------------------         


        
10条回答
  •  自闭症患者
    2020-12-04 07:07

    I would recommend not using a table in this instance, because that is not tabular data; it's purely presentational to have the button located at the far right. This is what I'd do to duplicate your table structure (change to a different H# to suit where you are in your site's hierarchy):

    
    
    

    This is my title

    If you want true vertical alignment in the middle (ie, if the text wraps the button is still middle-aligned with respect to both lines of text), then you either need to do a table or work something with position: absolute and margins. You can add position: relative to your drop-down menu (or more likely its parent) in order to pull it into the same ordering level as the buttons, allowing you to bump it above them with z-index, if it comes to that.

    Note that you don't need width: 100% on the div because it's a block-level element, and zoom: 1 makes the div behave like it has a clearfix in IE (other browsers pick up the actual clearfix). You also don't need all those extraneous classes if you're targeting things a bit more specifically, although you might need a wrapper div or span on the button to make positioning easier.

提交回复
热议问题