473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Centering a single line in a div

Hi everyone,

Me again! I'm having a problem centering a single line in a div.

I have a news section that is a block of it's own, and centered. The text in the news section is left aligned of course, but I want the "Latest News" line at the top to be centered within that block. Mimicing the News Section at the bottom of my page here:
http://www.workmenforChrist.org/

I cannot seem to get it at all! I managed to get it to be red, but not centered!

The code I presently have is this (I've tried all sorts of code, but nothing I tried, worked):
CSS:
Expand|Select|Wrap|Line Numbers
  1. /*News section on Index Page*/
  2. .news {
  3. margin-left:    auto;
  4. margin-right:    auto;
  5. width:        500px;
  6. border-left:    1px solid;
  7. border-right:    1px solid;
  8. }
  9. .newshead {
  10. text-align:    center;
  11. color:        red;
  12. }
  13. .news em {
  14. font-weight:    bold;
  15. }
HTML:
Expand|Select|Wrap|Line Numbers
  1. <div class="news">
  2. <span class="newshead">Latest News:</span><br>
  3. <em>9-18-07</em><br>
  4.  . . . Cut out regular text . . .
  5. </div>
  6.  
It has to be possible to simply center the "Latest News:" text! I can't use something like "p.newshead" that which will add space after the line.

Thank you all for the continued help!
Sep 25 '07 #1
6 2354
drhowarddrfine
7,435 Expert 4TB
Have you fixed this? Looks centered to me.
Sep 25 '07 #2
Have you fixed this? Looks centered to me.
It does? It's not appearing centered on any of the browsers I've looked in. I know the block of text is, but I want the single line with the words: "Latest News" to be centered in that block.

The link I had provided wasn't the page I'm working on, but is what I am trying to mimic because right now it's all done through tables and such, instead of the CSS.
Sep 25 '07 #3
drhowarddrfine
7,435 Expert 4TB
The link I had provided wasn't the page I'm working on
That's my mistake. The problem is that <span> is for inline styling and inline elements cannot be moved unless you change them to block: {display:block;text-align:center}.

However, the thing nowadays is to create mark-up that is "semantically" correct, ie, the tag matches what the content is. In other words, "Latest News" is a headline for the rest of the column so it should be a <hx>, such as <h3>. Doing so then allows you to just do:
.news h3{text-align:center}
Sep 25 '07 #4
That's my mistake. The problem is that <span> is for inline styling and inline elements cannot be moved unless you change them to block: {display:block;text-align:center}.

However, the thing nowadays is to create mark-up that is "semantically" correct, ie, the tag matches what the content is. In other words, "Latest News" is a headline for the rest of the column so it should be a <hx>, such as <h3>. Doing so then allows you to just do:
.news h3{text-align:center}
Oh okay, I was wondering a bit of the <span> tag. Thanks :)

As for putting the "Latest News" in a heading tag, I had thought about that, but it also puts that extra space (not sure how else to decribe it) after it. I was looking for a way to not have that "skipped line" that comes with the heading tags, paragraph tags, and other things.

Is there no other way to do this correctly?

EDITED:
. . . Well . . . I guess I will just made it a Header. The space isn't too too bad if one isn't so used to seeing it without it. Besides, I suppose it would made it more correct to do it this way, right? Thanks for the help, I was trying to use the <span> to position, when the only way to position something like that would be as a block of it's own. Thanks again!

~Michael
Sep 25 '07 #5
drhowarddrfine
7,435 Expert 4TB
h3{margin:0} .
Sep 25 '07 #6
Wow, thanks! I didn't realize the spacing for those elements (<h#>, <p>, et al.) was done by the margin! Sheesh, it makes sense, afterall, thinking about the list elements that I had to deal with!

Sorry about that, and thanks so much!
Sep 25 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Erik Schulp | last post by:
Hi all, I am trying to get a CSS defined layout to center on the page, have tried doing this with the <center></center> tags but than everything is centered, including text etc etc. What...
3
by: yawnmoth | last post by:
I'm trying to center list elements in a webpage I'm working on, and setting margin-left to auto for ol (or ul) seems to prevent the number (or bullet) from displaying in IE6 (strict mode) and...
2
by: Gnolen | last post by:
Hi again, Last time my server was down(as for many others I have heard), but now it is online again! I would be really really happy if someone could take a look at my problem a bit. I now...
13
by: Raffi | last post by:
Hi, We have an application that requires IE. We recently incorporated CSS scroll areas. The scroll fields are supposed to be centered. They are except for IE5 for the Mac. I have tried various...
4
by: Lance Hoffmeyer | last post by:
Hey all, Having problems centering a column Can someone explain how to center a column using python? import win32com.client import re import codecs
3
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a...
5
by: Markus Ernst | last post by:
Hello This is a test example: http://www.markusernst.ch/anthracite/ http://www.markusernst.ch/anthracite/living_divani.html After googling and experimenting for several hours, I ended up...
2
by: rudicheow | last post by:
SHORT VERSION ============= I have a bunch of identical fixed-size single-celled tables that rest against each other horizontally thanks to "float:left". These tables are dynamically generated...
1
by: =?Utf-8?B?ZnJhbmt5?= | last post by:
Hello, I've created a table that has two rows that are span across three columns. The third row has three columns, each with an image. The last row is also span accross three columns. The span...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.