Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I make a div tag occupy the half of the right hand side of my Web page?

Tags:

html

It is a basic HTML question.

I have some div tags, which have some controls and occupy left half of my screem.

I Want to have a div tag to display some messages in the right side? I used somthings like:

float = right;

in my css class. It didn't seem to work. What other properties I need to set.

Here is the code sample

<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>
like image 324
KeenUser Avatar asked Oct 24 '11 09:10

KeenUser


People also ask

How do I make a div take half the page?

Using float and marginThe left div is styled with width:50% and float:left – this creates the green colored div that horizontally covers half of the screen. The right div is then set to margin-left:50% – this immediately places it to the right of the left div.

How do you make a div on the right side?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

How do you split a div in HTML?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.

How do you position an element on the right side?

If position: absolute; or position: fixed; - the right property sets the right edge of an element to a unit to the right of the right edge of its nearest positioned ancestor. If position: relative; - the right property sets the right edge of an element to a unit to the left/right of its normal position.


2 Answers

I didn't understand your question so much, but I'll try to answer. If you have some div on the left and you want another one on the right you have two choice:

1) The first one is to set one div on the right and another on the left:

<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) The second one is to set every div on the left

<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>
like image 163
Marco Pace Avatar answered Oct 09 '22 19:10

Marco Pace


  1. Are you sure that you named the div correctly?
  2. the correct way to your command is

    float : right;
    
  3. If you want your div to be half of your screen you should write something like:

    width : 50%;
    
like image 1
TGM Avatar answered Oct 09 '22 17:10

TGM