如何使div标签占据我网页右侧的一半?

时间:2011-10-24 09:52:09

标签: html

这是一个基本的HTML问题。

我有一些div标签,它有一些控制并占据我的左半部分。

我想要一个div标签来显示右侧的一些消息? 我用过像somthings这样的东西:

float = right;

在我的css课程中。它似乎没有用。我需要设置哪些其他属性。

以下是代码示例

<div class ="header_label">
@Html.GetLocalizedString("program_snapshotRecipientAdress")&nbsp; @Html.TextBox("txtRcpntAdress")
</div>

   <div class ="header_label">
@Html.GetLocalizedString("program_snapshotUsertype1") &nbsp; @Html.RadioButton("Usertype", "One", new { id="rb1"})
 &nbsp; &nbsp;
@Html.GetLocalizedString("program_snapshotUsertype2") &nbsp; @Html.RadioButton("Usertype", "Two", new { id = "rb2" })
<div class ="commentsHeight"></div>
 </div>
   <div class ="header_label">
@Html.GetLocalizedString("program_snapshotDate") &nbsp; @Html.TextBox("SnapshotDate")
</div>

  <div id ="CMSContent">
<div class ="CMS-message">
@Html.Raw("S=This is the div I need to place in the right hand side")
</div>
</div>

4 个答案:

答案 0 :(得分:10)

我不太了解你的问题,但我会尽力回答。 如果你左边有一个div而右边你想要另一个div你有两个选择:

1)第一个是在右边设置一个div而在左边设置另一个div:

<div>
    <div style="float: left; width: 50%">I'm on the left</div>
    <div style="float: right; width: 50%">I'm on the right</div>
</div>

2)第二个是设置左边的每个div

<div>
    <div style="float: left; width: 50%">I'm on the left</div>
    <div style="float: left; width: 50%">I'm on the second on the left</div>
</div>

答案 1 :(得分:1)

  1. 您确定是否正确命名了div?
  2. 正确的命令方式是

    float : right;
    
  3. 如果你想让你的div成为你屏幕的一半,你应该写下这样的东西:

    width : 50%;
    

答案 2 :(得分:0)

你可以通过多种方式使div占据屏幕的右侧,其中一种方式是你发现的“浮动”。

这会使元素脱离文档的正常“流”,并允许它根据父元素等占据屏幕的不同区域。

您需要写一下:

float: right;

在你的CSS中,而不是=,但如果你能以更完整的形式发布一些html和css,可以提供一些更好的建议。

答案 3 :(得分:0)

如果你想用两半或网格显示你的表格或东西,请使用: 漂浮:对; 宽度:50%;