简体   繁体   English

右浮动div…与底部对齐?

[英]right floated div…align to bottom?

I've got html like so: 我有这样的html:

<div class="content-wrapper">
            <div class="float-left">
                <img alt="Track System" src="Images/myimage.png" />
            </div>
            <div class="float-right">
                <nav>
                    <ul id="menu">
                        <li class="tab"><a runat="server" href="~/">Home</a></li>
                        <li class="tab"><a runat="server" href="11Models2.aspx">Models</a></li>
                        <li class="tab"><a runat="server" href="Lease.aspx">Lease </a></li>
                        <li class="tab"><a runat="server" href="Help.aspx">Help</a></li>
                    </ul>
                </nav>
            </div>
        </div>

The first div (The one float-left) is just an image that has some length to it... The second div (the float-right) are tabs that I want to align on the bottom. 第一个div(左浮动)只是一个具有一定长度的图像...第二个div(右浮动)是我想在底部对齐的标签。 Right now they are too high up... 现在他们太高了...

the css classes simply are: CSS类只是:

.float-left{
float:left;
}

.float-right{
float:right;
}

I tried changing to absolute and relative positioning but it did not help... 我尝试更改为绝对定位和相对定位,但这没有帮助... 在此处输入图片说明

Here's what it looks like with the logo correctly being displayed on the left but the tabs on the right floating...I'd like to get those aligned to the bottom. 这是徽标正确显示在左侧,但右侧的选项卡浮动的外观……我想将其对齐到底部。

Is this what you want? 这是你想要的吗? http://jsfiddle.net/86Pr2/4/ http://jsfiddle.net/86Pr2/4/

I added a div with a class of "clear" and the following CSS: (I added !important to all of them cause I didn't feel like looking through all your code.) 我添加了一个带有“ clear”类和以下CSS的div :(我对所有它们都添加了!important,因为我不想遍历所有代码。)

.float-right {
position:absolute !important;
bottom:0 !important;
right:0 !important;
}
.content-wrapper {
   position:Relative !important;
}
.clear {
    clear:both !important;
}

And the changed HTML: 以及更改后的HTML:

<div class="content-wrapper">
        <div class="float-left">
            <img alt="Track System" src="http://i.imgur.com/2M3DyCv.png" />
        </div>
        <div class="float-right">
            <nav>
                <ul id="menu">
                    <li class="tab"><a runat="server" href="~/">Home</a></li>
                    <li class="tab"><a runat="server" href="11Models2.aspx">Models</a></li>
                    <li class="tab"><a runat="server" href="Lease.aspx">Lease </a></li>
                    <li class="tab"><a runat="server" href="Help.aspx">Help</a></li>
                </ul>
            </nav>
        </div>    
<div class="clear"><!--This makes the wrapper have a height--></div>

    </div>
    <div id="body">
    <section class="content-wrapper main-content clear-fix">
        hi
        </section>
    </div>

Not that @codedude didn't create something that would work but you wouldn't ever want to use the !important tag in your CSS. 并不是说@codedude不会创建某些行之有效的东西,但您永远也不想在CSS中使用!important标记。

Here's what I was working on: http://jsfiddle.net/dancameron/86Pr2/7/ 这是我正在研究的内容: http : //jsfiddle.net/dancameron/86Pr2/7/

It doesn't require any additional markup either (an empty div to clear!) and cleans up the class names to be more semantic. 它也不需要任何额外的标记(清除一个空的div!),并清理类名称以使其更具语义。

HTML: HTML:

 <div class="content-wrapper clear-fix">
        <div class="float-left">
            <img alt="Track System" src="http://i.imgur.com/2M3DyCv.png" />
        </div>
        <div class="nav-wrap">
            <nav>
                <ul id="menu">
                    <li class="tab"><a runat="server" href="~/">Home</a></li>
                    <li class="tab"><a runat="server" href="11Models2.aspx">Models</a></li>
                    <li class="tab"><a runat="server" href="Lease.aspx">Lease </a></li>
                    <li class="tab"><a runat="server" href="Help.aspx">Help</a></li>
                </ul>
            </nav>
        </div>
    </div>

    <div id="body">
        <section class="content-wrapper main-content clear-fix">
            hi
        </section>
    </div>

CSS: CSS:

.content-wrapper {
    margin: 0 auto;
    max-width: 100%;
    position: relative;
}
.nav-wrap nav {
    position: absolute;
    bottom: 5px;
    right: 5px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM