How do I align spans or divs horizontally?

后端 未结 10 918
礼貌的吻别
礼貌的吻别 2020-12-04 10:33

My only problem is making them line up three-across and have equal spacing. Apparently, spans can not have width and divs (and spans with display:block) don\'t appear horizo

相关标签:
10条回答
  • 2020-12-04 11:17
        <!-- CSS -->
    <style rel="stylesheet" type="text/css">
    .all { display: table; }
    .menu { float: left; width: 30%; }
    .content { margin-left: 35%; }
    </style>
    
    <!-- HTML -->
    <div class="all">
    <div class="menu">Menu</div>
    <div class="content">Content</div>
    </div>
    

    another... try to use float: left; or right;, change the width for other values... it shoul work... also note that the 10% that arent used by the div its betwen them... sorry for bad english :)

    0 讨论(0)
  • 2020-12-04 11:21

    I would use:

    <style>
    .all {
    display: table;
    }
    .maincontent {
    float: left;
    width: 60%; 
    }
    .sidebox { 
    float: right;
    width: 30%; 
    }
    <div class="all">
       <div class="maincontent">
           MainContent
       </div>
       <div class="sidebox"> 
           SideboxContent
       </div>
    </div>
    

    It's the first time I use this 'code tool' from overflow... but shoul do it by now...

    0 讨论(0)
  • 2020-12-04 11:22

    I would try to give them all display: block; attribute and using float: left;.

    You can then set width and/or height as you like. You can even specify some vertical-alignment rules.

    0 讨论(0)
  • 2020-12-04 11:25

    I would do it something like this as it gives you 3 even sized columns, even spacing and (even) scales. Note: This is not tested so it might need tweaking for older browsers.

    <style>
    html, body {
        margin: 0;
        padding: 0;
    }
    
    .content {
        float: left;
        width: 30%;
        border:none;
    }
    
    .rightcontent {
        float: right;
        width: 30%;
        border:none
    }
    
    .hspacer {
        width:5%;
        float:left;
    }
    
    .clear {
        clear:both;
    }
    </style>
    
    <div class="content">content</div>
    <div class="hspacer">&nbsp;</div>
    <div class="content">content</div>
    <div class="hspacer">&nbsp;</div>
    <div class="rightcontent">content</div>
    <div class="clear"></div>
    
    0 讨论(0)
提交回复
热议问题