简体   繁体   English

对齐 <div> 父母的右下角 <div> ?

[英]Align <div> with bottom-right of parent <div>?

I have a couple groups of links at the top of a layout page for an MVC app, and I'm having trouble getting these links positioned properly. 我在MVC应用的布局页面顶部有几组链接,但是在正确放置这些链接时遇到了麻烦。

Here's what they SHOULD look like (I'm making some huge changes to this site, but keeping the layout intact): 这是他们应该的样子(我正在对该网站进行一些重大更改,但请保持布局不变):

在此处输入图片说明

Keep in mind that this photo is at the center-right of my page, that is to say, the page extends further to the right, but there's no content in that area. 请记住,这张照片在我页面的右上角,也就是说,页面向右延伸得更远,但是该区域没有任何内容。

After altering these image-based links to text-based, they lose their styling integrity and scramble. 将这些基于图像的链接更改为基于文本的链接后,它们将失去样式完整性并变得混乱。

Here's some code from my current links to give an idea of how they're contained: 这是我当前链接中的一些代码,以了解它们的包含方式:

<div class="top-links">
    <div id="top-nav">
        <a class="top-link" href="#" title="My Profile">
            <span>MY PROFILE</span>
        </a>
        <a class="top-link" href="#" title="Account Profile">
            <span>ACCOUNT PROFILE</span>
        </a>
        <a class="top-link" href="#" title="Sign Out">
            <span>SIGN OUT</span>
        </a>
    </div>
</div>
<div class="links">
    <div id="nav">
        <a class="home-link home-link-left" href="#" title="My Component Books">
            <span>MY COMPONENT BOOKS</span>
        </a>
        <a class="home-link" href="#" title="New Component Book">
            <span>NEW COMPONENT BOOK</span>
        </a>
        <a class="home-link" href="#" title="System Logs">
            <span>SYSTEM LOGS</span>
        </a>
    </div>
</div>

I left out pieces of the tags themselves for readability. 为了便于阅读,我自己遗漏了一些标签。

And finally, the relevant CSS: 最后,相关的CSS:

/*----------- TOP NAVIGATION -----------*/
.top-links {
    float: right;
    height: 31px;
    margin: 0 0 0 0;
    width: auto
}

.top-link {
    font: 7pt Georgia, serif;
    color: #E1915C;
    text-align:center;
    text-decoration: none;
    line-height: 34px;
    padding: 10px;
}

#top-nav {
    float: right;
    margin: 0 0 0 0;
    overflow: hidden;
}

/*----------- NAVIGATION -----------*/
.links {
    float: right;
    width: auto;
    height: 36px;
    overflow: hidden;
    bottom: 0;
    right: 0;
}

.home-link {
    font: 7.25pt Georgia, serif;
    color: #E1915C;
    text-decoration: none;
    font-weight: bold;
    border-right: 1px solid #E1E1E1;
    text-align: center;
    line-height: 36px;
    width: auto;
    padding: 10px;
}

    .home-link:hover {
        color: #369AAA;
    }

.home-link-left {
    border-left: 1px solid #E1E1E1;
}

.home-link-right {
    border-right: 1px solid #E1E1E1;
}

#nav {
    position: absolute;
    float: right;
    overflow: hidden;
}

Sorry if it seems like a bit much, some of it isn't my original code and I'm not sure what I should/shouldn't include. 抱歉,如果看起来有点多,其中有些不是我的原始代码,而且我不确定应该/不应该包含什么。

I'm not the best with CSS, so could any styling gurus give me some insight on how I can make the links lay out as they are in the screenshot? 我不是使用CSS的最佳人选,所以任何样式专家都可以让我对如何使链接在屏幕截图中一样布局有一些见解吗?

See if this is what you were going for: http://jsfiddle.net/derekstory/cHnXx/ 看看这是否是您想要的: http : //jsfiddle.net/derekstory/cHnXx/

/*----------- TOP NAVIGATION -----------*/

.top-links {
    height: 31px;
    margin: 0 0 0 0;
    width: auto;

}
.top-link {
    font: 7pt Georgia, serif;
    color: #E1915C;
    text-align:center;
    text-decoration: none;
    line-height: 34px;
    padding: 10px;
}
#top-nav {
    float: right;
    margin: 0 0 0 0;
    overflow: hidden;
}
/*----------- NAVIGATION -----------*/
 .links {
    whitespace: nowrap;
    min-width:  120px;
    float: right;   
    height: 36px;
}
.home-link {
    font: 7.25pt Georgia, serif;
    color: #E1915C;
    text-decoration: none;
    font-weight: bold;
    border-right: 1px solid #E1E1E1;
    text-align: center;
    line-height: 36px;
    width: auto;
    padding: 10px;
}
.home-link:hover {
    color: #369AAA;
}
.home-link-left {
    border-left: 1px solid #E1E1E1;
}
.home-link-right {
    border-right: 1px solid #E1E1E1;
}
#nav {
    position: absolute;
    float: right;
    overflow: hidden;
}

Here is the jsFiddle: http://jsfiddle.net/FVjhQ/2/ 这是jsFiddle: http : //jsfiddle.net/FVjhQ/2/

CSS CSS

#profile-nav {
     margin-bottom: 25px;
}
.nav-container,
.nav-container li {
     margin: 0;
     padding: 0;
}
.nav-container {
     clear: right;
     float: right;
}
.nav-container li {
     border-left: 1px solid #E1E1E1;
     float: left;
     list-style: none;
     line-height: 36px;
}
.nav-container a {
     font: 7.25pt Georgia, serif;
     color: #E1915C;
     text-decoration: none;
     font-weight: bold;
     padding: 10px;
     text-transform: uppercase;
}
.nav-container a:hover {
     color: #369AAA;
}
.nav-container .last-link {
     border-right: 1px solid #E1E1E1;
}
.no-border li {
     border: 0;
}

HTML HTML

<ul id="profile-nav" class="nav-container no-border">
    <li>
        <a href="#" title="My Profile">My Profile</a>
    </li>
    <li>
        <a href="#" title="Account Profile">Account Profile</a>
    </li>
    <li>
        <a href="#" title="Sign Out">Sign Out</a>
    </li>
</ul>

<ul id="component-nav" class="nav-container">
    <li>
        <a href="#" title="My Component Books">My Component Books</a>
    </li>
    <li>
        <a href="#" title="New Component Books">New Component Books</a>
    </li>
    <li>
        <a href="#" title="Notifications">Notifications</a>
    </li>
    <li class="last-link">
        <a href="#" title="System Logs">System Logs</a>
    </li>
</ul>

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

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