ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Before I would post the problem here, I did some googling but could not find an example to address my problem.
Here is the problem statement:
(Look at the above two emoticons. The second one is right-aligned and first one is center-aligned. However, the center image looks okay because the Monk is not on the same line. It is on the second line. How would the center-image get aligned if both the images were on the same line?)
I have two inline images, <img /> tags, just after the <body> tag. The first image (Logo.jpg) is aligned right using CSS "float:right". I want other one (Welcome.jpg) to be center-aligned. HTML's "align=center" or CSS' "float:center" and even HTML's <center> tags do not seem to work properly because I want the second image to sit in the middle (horizontally, of course) at the top of the page irrespective of the other image's location. What is happening is the second image is getting aligned with proportion to the gap between the left edge of the page and the left side/border, the point from where the Logo image begins, of the right-aligned image.
I have used "margin-left: 200px;" intentionally so that the Welcome Image can move some more spaces towards the right side so as to look to be sitting in the center of the top of the page.
But that is not desirable. There has to be a proper solution using CSS. I could not find one by Googling on it.
Well, I should have mentioned that that also would not work. It is not working. It is giving the same identical result as center tag and other such techniques I described above.
Note that I put both images in the div, which puts them in same line
I tested and it works in firefox 8...
edit: I added clear:both in hr, though
PHP Code:
<hr style="clear:both" />
It is just for testing, ideally all those inline style should be in CSS sheet
edit2, maybe I did not understand the requirement
If you want the center image to be in absolute center, there are several ways
For example add negative right margin, with same size as right image width
Make sure the container has position:relative; and put the tallest item into it normally. This makes sure the container will get the desired height. Then, use position:absolute;top:0;left:0;width:100%;height:100% sub-container to overlay another container on top of it.
PHP Code:
<div style="position:relative;"> <div align="center"> center </div> <div align="right" style="position:absolute;top:0;left:0;width:100%;height:100%;"> right </div> </div>
You can use the z-index:level; property to pick the layering order, higher values are on top, and negative values are in the background. If the window happens to be very narrow, the elements will go on top of each other; the layering order is important then.
what I do sometimes is use the CSS magic with positioning (NominalAnimal)
like this (a working tested copy/paste code)
Code:
<body>
<div id="wrapper" style="width:962px; height:auto; text-align:center; margin:0 auto; background-color:#ddd;">
<!-- the above line makes a 'frame' for page to the center and align all text to center -->
<div id="page" style="width:762px; height:366px; background-color:#fff; margin:30px auto;">
<!-- the page line makes a page 'frame' box to the center -->
<div style="position:relative; left:0px; top:0px; margin:0 auto; width:700px; height:120px; border:1px dotted red; z-index:1;">
<img src='linux-monk.gif' width='100px' style='border: 0px; float:right;' />
</div>
<div style="position:relative; left:0px; top:-120px; margin:0 auto; width:700px; height:120px; border:1px dotted green; z-index:2;">
<img src='cool_smiley.gif' width='100px' style='border: 0px;' />
</div>
<hr />
Blah! Blah! Blah! Blah! Blah!
</div>
</div>
</body>
just remove that "border's" in your real code when used, there are just for an illustration .
good luck
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.