/    Sign up×
Community /Pin to ProfileBookmark

how to center an element (with a twist)

Hi people

I am trying to cause an element to be centered inside a cell with a little twist
The element is actually composed of text followed by another element (let’s call it A)
When I tell the browser to center them, it takes them as a single unit and centers them together (can be seen in the attached snapshot called current.png)

I would like the browser to center the content according to the A element, and simply render the text before it (can be seen in the attached snapshot called wanted.png)

Is what I want possible?
Here is my code so far:

[code=php]
<html>
<body>
<div style=”text-align:center; width:300px; height:50px; border:1px solid black; background-color:white; padding:5px;”>
text
<span style=”width:100px; height:50px; border:1px solid black; background-color:lightblue”><span>
</div>
</body>
</html>
[/code]

I would appreciate it if anyone could help me with this

[upl-file uuid=3465642a-c3aa-47f5-819c-099ea760ef1b size=2kB]images.zip[/upl-file]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Willy_DuittMar 22.2005 — I recall this same question being anwered on another forum...

I'm not sure where but I think it was one of these...

http://forums.devshed.com/t238601/sacb361588d1830bffe4a3c1f41f0bab2.html

http://www.htmlforums.com/showthread.php?postid=367868

Please don't forget to update ALL of your threads to reflect that you have found a solution...

Thanks;

.....Willy
Copy linkTweet thisAlerts:
@jasongrauthorMar 22.2005 — Thanks Willy

Here is a possible solution that I got:
[code=php]
<html>
<body>
<div style="width:300px; height:50px;border:1px solid black;
background-color:white; padding:5px;">
<div style="text-align:right;padding-right:50%">text<span
style="width:100px; height:50px; border:1px solid
black;background-color:lightblue;margin-right:-50px"></span></div>
</div>
</body>
</html>
[/code]
×

Success!

Help @jasongr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...