Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 13th Apr 2013, 02:15 PM   #1
Internet Marketing
War Room Member
 
moneychain's Avatar
 
Join Date: 2011
Location: Gulf Shores, AL
Posts: 52
Thanks: 31
Thanked 7 Times in 7 Posts
Blog Entries: 2
Default
What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

I want to center the widget (code) below. Where do I put the code to center it? Can someone put it in there and hi-lite it so I can see and be able to do it myself next time?

<a class="twitter-timeline" href="https://twitter.com/Domainvertize" data-widget-id="305574601449144320">Tweets by @Domainvertize</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);j s.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs); } } (document,"script","twitter-wjs");</script>

moneychain is offline  
Unread 13th Apr 2013, 02:58 PM   #2
Warrior Member
Registered Member
 
Join Date: 2013
Location: USA
Posts: 28
Thanks: 15
Thanked 7 Times in 6 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

You need to wrap it in a div & give that div a class, like this:

<div class="center">
<a class="twitter-timeline" href="https://twitter.com/Domainvertize" data-widget-id="305574601449144320">Tweets by @Domainvertize</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);j s.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs); } } (document,"script","twitter-wjs");</script>
</div>


then you need to add the rule to the CSS file as follows:

div.center {

width: (whatever the width of the element is);
margin: 0 auto; /*this is what centers the element*/
}


You need to specify a width or it won't center. This is the correct way of doing it using current standards. Now, if you want to add it directly to the html it is as follows .

<a align="center" class="twitter-timeline" href="https://twitter.com/Domainvertize" data-widget-id="305574601449144320">Tweets by @Domainvertize</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);j s.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs); } } (document,"script","twitter-wjs");</script>


or....


<a style="margin: 0 auto; width: 890px;" class="twitter-timeline" href="https://twitter.com/Domainvertize" data-widget-id="305574601449144320">Tweets by @Domainvertize</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);j s.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs); } } (document,"script","twitter-wjs");</script>

Modify the width in the second example to reflect how wide you need it to be.

Hope that helps,

Pandita

PanditaC is offline  
Unread 13th Apr 2013, 03:15 PM   #3
HyperActive Warrior
War Room Member
 
alistair's Avatar
 
Join Date: 2010
Location: England
Posts: 403
Thanks: 152
Thanked 386 Times in 269 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

I'd normally just do this:

<div align="center">
<a class="twitter-timeline" href="https://twitter.com/Domainvertize" data-widget-id="305574601449144320">Tweets by @Domainvertize</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);j s.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs); } } (document,"script","twitter-wjs");</script>
</div>
alistair is offline  
Unread 13th Apr 2013, 03:31 PM   #4
Senior Warrior Member
War Room Member
 
Robert Michael's Avatar
 
Join Date: 2011
Posts: 1,841
Thanks: 904
Thanked 846 Times in 581 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

Or you can skip all of the extra nonsense posted above, and use this:

<center> your widget stuff here </center>

LOL why do people like to make things harder than they actually are?

So for your specific example, this would be it centered:

<center><a class="twitter-timeline" href="https://twitter.com/Domainvertize" data-widget-id="305574601449144320">Tweets by @Domainvertize</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);j s.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs); } } (document,"script","twitter-wjs");</script></center>

Robert Michael is offline  
Unread 13th Apr 2013, 03:59 PM   #5
Warrior Member
Registered Member
 
Join Date: 2013
Location: USA
Posts: 28
Thanks: 15
Thanked 7 Times in 6 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

Originally Posted by Whos That Guru View Post

Or you can skip all of the extra nonsense posted above, and use this:

<center> your widget stuff here </center>

LOL why do people like to make things harder than they actually are?

So for your specific example, this would be it centered:

<center><a class="twitter-timeline" href="https://twitter.com/Domainvertize" data-widget-id="305574601449144320">Tweets by @Domainvertize</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);j s.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs); } } (document,"script","twitter-wjs");</script></center>
The <center> tag is not supported in HTML5, and is deprecated in HTML 4.01. ie. It is not up to current web standards. But yes, it would work. :-)

PanditaC is offline  
Unread 13th Apr 2013, 04:15 PM   #6
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

Originally Posted by Whos That Guru View Post

Or you can skip all of the extra nonsense posted above, and use this:

<center> your widget stuff here </center>
That would have been good advice 10+ years ago, but unfortunately it's pretty bad advice for today. The <center> tag has been deprecated for a long time.

Pandita gave a pretty good solution... the only thing I would add to it is 'text-align: center', to account for older IE browsers.

HTML Code:
.center {
width: (whatever the width of the element is);
margin: 0 auto; /*this is what centers the element*/
text-align: center;
}


Brandon Tanner is offline  
Unread 13th Apr 2013, 04:24 PM   #7
Mad For Money Making
 
Join Date: 2011
Location: UK
Posts: 454
Thanks: 11
Thanked 48 Times in 46 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

To center something in HTML the code is < center> </ center> (remove the spaces)

wlasikiewicz is offline  
Unread 13th Apr 2013, 04:28 PM   #8
Senior Warrior Member
War Room Member
 
Robert Michael's Avatar
 
Join Date: 2011
Posts: 1,841
Thanks: 904
Thanked 846 Times in 581 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

Originally Posted by PanditaC View Post

The <center> tag is not supported in HTML5, and is deprecated in HTML 4.01. ie. It is not up to current web standards. But yes, it would work. :-)
Originally Posted by Brandon Tanner View Post

That would have been good advice 10+ years ago, but unfortunately it's pretty bad advice for today. The <center> tag has been deprecated for a long time.
always works fine for me, lol

Robert Michael is offline  
Unread 14th Apr 2013, 08:03 AM   #9
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

Originally Posted by Whos That Guru View Post

always works fine for me, lol
Sounds like you haven't tested much deprecated code across a wide range of browsers! If you had, then you would understand why it's best to avoid it (it will work OK in some browsers, but completely fall apart in other browsers).


Brandon Tanner is offline  
Unread 14th Apr 2013, 09:12 AM   #10
HyperActive Warrior
War Room Member
 
Join Date: 2009
Posts: 178
Thanks: 60
Thanked 33 Times in 33 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

Why is this <center> tag still being forced in this thread? The first 2 replies posted by Pandita and Alistair should have settled the OP's problem.

Here comes the 'elders' who've been living in caves for the past 12 years or so who wants to flaunt their skills with the <center> tags. LOL!
moralde is offline  
Unread 14th Apr 2013, 07:11 PM   #11
Web Developer
War Room Member
 
Join Date: 2012
Posts: 299
Thanks: 30
Thanked 32 Times in 30 Posts
Default
Re: What is the code to center something in HTML?
Share on: 
fb share twitter share gplus share more share

Originally Posted by Whos That Guru View Post

always works fine for me, lol
I'm sure it does for now, but who knows for how much longer.

Qosso.com - Exceptional Branding At Affordable Prices
BillyW is offline  
Closed Thread


Bookmarks

Tags
center, code, html


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:18 AM.