CSS - Is THIS Possible?

  • Thread starter Roy Schestowitz
  • Start date
R

Roy Schestowitz

In my CSS I included the following:


#Div_png_top {
font-size: 40px;
text-align: center;
position:fixed;
top:10px;
right: 300px;
background:url(/IMG/blog_css/up.png) no-repeat top left;
width:50px;
height:50px;
}


My question is: can the line

right: 300px;

be replaced so that the object always appears in the _center_? I tried many
things to no avail.

Thanks in advance,
Roy
 
K

King of Red Lions

Roy said:
In my CSS I included the following:


#Div_png_top {
font-size: 40px;
text-align: center;
position:fixed;
top:10px;
right: 300px;
background:url(/IMG/blog_css/up.png) no-repeat top left;
width:50px;
height:50px;
}


My question is: can the line

right: 300px;

be replaced so that the object always appears in the _center_? I tried many
things to no avail.

Thanks in advance,
Roy

Try putting <center> and </center> tage before and after the div in your
markup!
 
S

Spartanicus

Roy Schestowitz said:
#Div_png_top {
font-size: 40px;
text-align: center;
position:fixed;
top:10px;
right: 300px;
background:url(/IMG/blog_css/up.png) no-repeat top left;
width:50px;
height:50px;
}

My question is: can the line

right: 300px;

be replaced so that the object always appears in the _center_? I tried many
things to no avail.

It can only be done properly if you set the width as a percentage of the
containing block's width, for example:

width:20%;right:40%;left:40%;

It needs to total to 100%.
 
D

David Dorward

Try putting <center> and </center> tage before and after the div in your
markup!

The center element is deprecated and should not used. It would have no
effect anyway given the CSS applied.
 
D

David Dorward

Roy said:
My question is: can the line
right: 300px;
be replaced so that the object always appears in the _center_?

right: 50%; /* Half the containing block */
margin-right: -25px; /* Half the width of the element */
 
R

Roy Schestowitz

Thank you David and Spartanicus for good suggestions. I didn't know
percentages were legal in CSS, but now I know they are...

Roy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top