简体   繁体   English

如何在同一行上有两个DIV,一个不带HTML表格,一个左对齐,一个右对齐?

[英]How can I have two DIV s on the same line , one aligned to the left and one aligned to the right without an HTML table?

I want the votediv on the right, independent of the text size of the article with class name "note". 我想要的是表决分隔符,而与类别名称为“ note”的文章的文本大小无关。 what happens if I assign 如果我分配会发生什么

<div class="votediv" style="right:0; position:relative">

on css? 在CSS上?

<div class="opiniondiv">
        <article class="opinion"></article>
        <div class="opiniondetail">
          <article class="note"></article>
          <div class="votediv">
            <form method="POST">
              <button class="agreebutton" value="1">Agree</button>
              <button class="disagreebutton" value="0">Disagree</button>
            </form>
          </div>
        </div>
      </div>

also, I want to do it without using 另外,我想不用

display:table

For <div class="votediv" style="right:0"> to work you have to add position: absolute to the style. 为了使<div class="votediv" style="right:0">起作用,您必须在样式中添加position: absolute And after that you would probably want to add position: relative to div.opiniondiv . 然后,您可能需要添加position: relative对于div.opiniondiv

Edit 编辑

And if you are to float the divs as others suggests here, please do not forget to clear or you will have a total mess. 而且,如果您要像其他人建议的那样使div浮动,请不要忘记清除,否则您将一团糟。

http://www.positioniseverything.net/easyclearing.html http://www.positioniseverything.net/easyclearing.html

<style>
    .votediv{
       float: right;
       width: 50%;
    }

    .opiniondiv{  
       float: left;
       width: 50%;
    }
</style>

The 50% width is assuming they are both within the same parent container. 50%的宽度假定它们都在同一个父容器中。 They need to have a set width for this to work, and obviously, their combined widths must not be wider than their parent. 它们需要具有一个固定的宽度才能正常工作,并且显然,它们的组合宽度不得大于其父级。

You can use float: left and float: right to float an element to those sides respectively. 您可以使用float: leftfloat: right分别将元素浮动到那些边。

<style type='text/css'>
    .votediv { float: right; }
    .opiniondiv { float: left; }
</style>

Working Example 工作实例

暂无
暂无

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

相关问题 我该如何布置两个 <div> 在一行上,并且其中一个居中对齐(相对于整行),而另一个居右对齐? - How can I lay out two <div>s on one line, and have one centre-aligned (relative to the entire line) and the other right-aligned? 如何使两个对象水平对齐(一个在另一个的右侧)并居中放置一个? - How can I have two objects aligned horizontally (one to the right of the other) and center the left one? 如何在表格单元格(td)中定位元素,使得一个元素左对齐而另一个元素对齐? - How can I position elements within a table cell (td) such that one element is left aligned and the other right aligned? 如何将这两个放在同一行? (一个居中,一个右对齐) - how to put these two on the same line? (one centered, one right aligned) 如何让文本右对齐,但 div 居中对齐? - How can I have text aligned right, but the div aligned center? 材质用户界面。 网格内的 2 个项目; 一个左对齐,一个右对齐。 在同一行 - Material UI. 2 items inside a grid; one left-aligned, one right-aligned. In the same line HTML5在段落的同一行中具有左对齐文本和右对齐文本 - HTML5 Have left aligned text and right aligned text in same line within paragraph 同一行中的两个文本一个对齐,另一个对齐 - Two texts in the same line one aligned left the other centered 两个跨度,一个左对齐,一个右对齐,两个都底部对齐 - two spans, one left aligned, one right aligned, both bottom aligned 如何将 dd 和 dt 元素设置在同一行,dt 右对齐和 dd 左对齐? - How do I style dd and dt elements to be on the same line with dt right aligned and dd left aligned?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM