如何在不使用float的情况下将div左右对齐? [英] How do you align left / right a div without using float?

查看:80
本文介绍了如何在不使用float的情况下将div左右对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行以下操作时:

<div style="float: left;">Left Div</div>
<div style="float: right;">Right Div</div>

我必须在

clear: both;

对我来说很肮脏.

那么,有没有一种方法可以不使用浮点数进行对齐?

So, is there a way to align without the use of float?

这是我的代码:

.action_buttons_header a.green_button{
 
}

<div class="change_requests_container" style="width:950px !important">
    <div class="sidebar">
        
            
                <a href="/view/preview_unpublished_revision/422?klass=Proposal" class="preview sidebar_button_large action_button" name="preview" onclick="window.open(this.href);return false;">Preview New Version</a>
            
        
        
    </div>
    <div class="content_container">
        <div class="content">
                        
                <div class="action_buttons_header">
                    <a href="/changes/merge_changes/422" class="re_publish publish green_button" style="
    margin: 5px 0px 5px auto;
">Apply Changes</a>
                </div>
            
            


            <div id="change_list_container">    

<div class="changes_table">
    
        
            
            <style type="text/css">
                #original_492 .rl_inline_added {
                    display: none;
                }
                
                #492.change_container .actial_suggested_text_container{
                    display: none;
                }
            </style>
            <div class="content_section_header_container">
                <div class="content_section_header">
                    <a href="#" class="collapse" name="492"></a>
                    The Zerg | 
                    Overview
                    <div class="status" id="492_status">
                        <div id="492_status_placeholder">
                            
                        </div>
                    </div>
                </div>
            </div>
            <div class="change_container" id="492">
                
            </div>
        </div>
    </div>
</div>

我希望它位于横条右边的绿色按钮,但要尽可能干净.

I want the green button on the right of the horizontal bar that it's in but in the cleanest way possible.

只需尝试学习如何优雅,简洁地做CSS.

Just trying to learn how to do CSS elegantly, cleanly, etc.

推荐答案

在这种情况下,如果要右对齐该绿色按钮,只需更改一个div以使所有内容右对齐:

In you case here, if you want to right-align that green button, just change the one div to have everything right-aligned:

<div class="action_buttons_header" style="text-align: right;">

div已经占用了该部分的全部宽度,因此只需右对齐文本即可向右移动绿色按钮.

The div is already taking up the full width of that section, so just shift the green button the right by right-aligning the text.

这篇关于如何在不使用float的情况下将div左右对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆