Text with border

Hi,
In my game I want to put some text in the centre of the screen with a border around it, example; warning sign or notice.
But instead of wrapping around the text, it prints the border from margin to margin. There is probably something I'm missing.
Can anyone help.

<div style="border: solid red"><center>Warning</br>Danger</br>{b:Do Not Enter}</center></div>
Warning
Danger
Do Not Enter

<div style="text-align: center"><div style="text-align: center; border: solid red; display: inline-block; padding: 4px;">Warning</br>Danger</br>{b:Do Not Enter}</div></div>

Warning
Danger
Do Not Enter
  • text-align on the outer div controls the alignment of the red box relative to the page (you can omit the outer div if you don't want to centre the box)
  • text-align on the inner div aligns the text within the box.
  • display: inline-block makes the box shrink to fit its contents
  • padding controls the spacing between the box and contents

K.V.

Try this:

<center><div style=\"border:solid red;display:inline-block;padding:2px;\">Warning<br/>Danger<br/><b>Do Not Enter</b></div></center>

EDIT

This works, too:

PrintCentered ("<div style=\"border:solid red;display:inline-block;padding:2px;\">Warning<br/>Danger<br/><b>Do Not Enter</b></div>")

(The inline-block display setting is what does the trick. I learned that bit from mrangel.)


MrAngel pointed out that <center> was deprecated around 10 years ago, so I changed this code.

For more on why <center> was done away with, see:

https://stackoverflow.com/a/1799083


@KV:
<center> has been deprecated since HTML 4.0
Currently, different browsers treat it as a shorthand for either <div align="center"> (which is itself deprecated) or <div style="text-align: center;">, which are almost but not quite identical, and could lead to some odd rendering behaviour in edge cases.
In something like this, it probably works. But I try to avoid giving examples that teach bad habits.


K.V.

Doh!

I had this page on my screen for a few minutes before I posted (had a surprise guest). I just now saw that mrangel had already posted a fix.


Edit

...and I wrote this and didn't press post until after mrangel had responded to my other post (web surfing on my Android today)...


<center> is bad form?

Why the [expletive deleted] didn't somebody tell me?!?

Oh, right. Someone just did.

...and knowing is half the battle!

#TheMoreYouKnow


Also note that I'm American, guys and gals. Were it not for ignorance and bad habits, I wouldn't even exist!


Thanks all for the prompt response. Great.
<center> my bad. I keep wanting to write 'centre'. F#*@ing Americans can't spell properly. No sense of humor (Now I'm at it).


K.V.

EDITED

Does text-align:centre work?

Let's try...


1 minute later...

Nope.

Looks like we made it "center". "centre" has been deprecated.

#America
#F__kYeah!


10 minutes later...

Wait!

Does text-align:centre work in the UK? (I just realized it might be that it just doesn't work in my American browser.)


Nope, text-align:centre does not work in the UK.


K.V.

Nope, text-align:centre does not work in the UK.

Damn... That's just mean.

We should let you guys use "centre" or "center". Same goes for "colour".

(Any Colour You Like... That is a very good album!)

My mind wanders sometimes...


But you have to admit that it should be "aluminum", not "aluminium"!

#USA! #USA!


Of which there is now a 10% tariff on...

#F*!%ing Americans


But you have to admit that it should be "aluminum", not "aluminium"!

Yep; the discoverer of an element gets to name it, and we should stick to what he chose. Even if aluminum is already the name of another substance.


K.V.

Even if aluminum is already the name of another substance.

What the hell is logic? We don't need it! Take it back!!!


SIDENOTE

I've always thought aluminium sounds cooler anyway, so that's how I've always pronounced it in public.

You get awesome reactions in my city when you go into the grocery store and say, "pardon me, fine sirs and madams, but where might one acquire a roll of aluminium?"

... in fact, I wouldn't recommend it if you don't at least look like you'd put up a good fight. You'd be likely to get dealt wit'! (Nawmean? Represent!)


EDIT

If you want to know what my hometown is really like, no bulls__t, watch a movie called Hustle & Flow. There are parts of the city that aren't like that, but they are few and far between.


You should seriously watch it. That is where I have always lived. You won't wonder what the hell is wrong with me anymore once you've seen my environment. You'll be like, "no, you guys. That KV's really not so crazy; trust me on this."

Plus, I've seen commercials for Downton Abbey, and I own (and love) all the Monty Python stuff (Fawlty Towers included), so I already know all about you guys...


KV, you must be one of the most intelligent and articulate people in all of Memphis (and possibly Tennessee). And I say that as an ignorant American!


K.V.

one of the most intelligent and articulate people in all of Memphis

Nah. There are quite a few smart folks around here. They just all act real dumb so they don't get shot.


Intelligence is seriously frowned upon by at least half of the population, though. That's a sad fact.


NOTE

I just meant that I wasn't quite as crazy as my peers, by the way. I wasn't tooting a smart horn. I didn't even graduate from high school. (Due to attendance, which makes me even dumber than most of my fellow dropouts.)


But you have to admit that it should be "aluminum", not "aluminium"!

No, IUPAC have declared it should be aluminium. Just be glad you got sulfur.


K.V.

I've always written "sulphur"; never even noticed it spelled "sulfur" anywhere.

Researching...

Been "sulfur" since the 1920s, huh? I guess my chemistry teacher just let me slide since it was a grey area.

...or was it a "gray" area?


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums