简体   繁体   English

HTML / CSS - 左右对齐在同一行?

[英]HTML/CSS - Right and left align on the same line?

First off, I know there are ways to make it so that text can be on the same line. 首先,我知道有办法使文本可以在同一行。 But I am not sure how to extend on this. 但我不知道如何延伸这一点。 This is what I have so far: 这是我到目前为止:

应该一路走来

How would I be able to make it so it goes all the way across without using tables? 如何在不使用表格的情况下完成所有操作?

This is the HTML portion: 这是HTML部分:

<p style="float: left;" class="details"><a href="#Top">To Top</a></p>
<p style="float: right" class="details">Latest Version:  0.3.6.17 | Downloads: 12 | <a href="#">Download</a></p>

This is the CSS portion: 这是CSS部分:

.details {
padding: 7px 15px;
margin: 20px 15px 15px 15px;
background: #111111;    
}

I would really hate to have to resort to tables for this. 我真的很讨厌不得不求助于此。 Is there an easier way. 有更容易的方法吗。 Thank you anyone who can help me. 谢谢任何可以帮助我的人。

This diverges a bit from what you started with, but has been how I've done this in the past: 这与你的开始有点不同,但过去我是如何做到这一点的:

CSS: CSS:

.details {
  clear: both;
  padding: 7px 15px;
  margin: 20px 15px 15px 15px;
  background: #111111;
  text-align: right;
}

.toplink {
  float: left;
}

HTML: HTML:

<div class="details">
  <span class="toplink">To Top</span>
  Latest Version:  0.3.6.17 | Downloads: 12 | Download
</div>

Add display:inline; 添加display:inline; to your .details class and make sure the containing div is a block element and its background is set to gray. 到你的.details类,并确保包含div是一个块元素,其背景设置为灰色。

Sinan. 思南。

I did it this way: 我是这样做的:

<style type="text/css">
#right {
    float: right;
}

.details {
    margin: 0 auto;
    line-height: 0;
}
</style>

<p class="details"><a href="#Top">To Top</a></p>
<p id="right" class="details">Latest Version:  0.3.6.17 | Downloads: 12 | <a href="#">Download</a></p>

The tricky part is that you have to zero out the top and bottom margins for both AND the line-height. 棘手的部分是你必须将两个和行高的顶部和底部边距归零。 If you do this, then floating right on the bottom element lines up. 如果你这样做,那么浮在右边的元素就行了。

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

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