473,786 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSS/image/"alignment"

Hi,

what is the most elegent way to center an
image inside a web page.

The image is radomly chosen by a cgi script
may be 300x400 or 400x300.

Are there any alignment commands for images?

tia,

Oliver
Apr 27 '06 #1
9 3054
Deciding to do something for the good of humanity, Oliver Block
<ol**********@e post.de> declared in
comp.infosystem s.www.authoring.stylesheets:
Are there any alignment commands for images?


text-align, same as any other inline elements (yes, it probably should
have been called inline-align, but it's a bit late for that now).

--
Mark Parnell
My Usenet is improved; yours could be too:
http://blinkynet.net/comp/uip5.html
Apr 27 '06 #2
In article <4b************ *@news.dfncis.d e>,
Oliver Block <ol**********@e post.de> wrote:
what is the most elegent way to center an
image inside a web page.


"Most elegant" would be "simplest" to me -- but that also happens to
be non-compliant with HTML Strict and doesn't use CSS.

So the next best way is:

(CSS) .imgcenter { display: inline; text-align: center; border: 0; }

(HTML) <img class="imgcente r" src="...." ...>

The display:inline is needed so that the image gets treated like
text, which can then be centered with text-align:center.

-A
Apr 28 '06 #3
Deciding to do something for the good of humanity, axlq
<ax**@spamcop.n et> declared in
comp.infosystem s.www.authoring.stylesheets:
The display:inline is needed so that the image gets treated like
text, which can then be centered with text-align:center.


Images are inline by default.

--
Mark Parnell
My Usenet is improved; yours could be too:
http://blinkynet.net/comp/uip5.html
Apr 28 '06 #4
Mark Parnell <we*******@clar kecomputers.com .au> wrote:
The display:inline is needed so that the image gets treated like
text, which can then be centered with text-align:center.


Images are inline by default.


Plus 'text-align:center' would need to be specified on a container
element, not on the image itself.

--
Spartanicus
Apr 28 '06 #5
Deciding to do something for the good of humanity, Spartanicus
<in*****@invali d.invalid> declared in
comp.infosystem s.www.authoring.stylesheets:
Plus 'text-align:center' would need to be specified on a container
element, not on the image itself.


True. I assumed that's what axlq meant, though probably erroneously.
Then again I wasn't really clear about that in my reply to the OP
either. Whoops.

--
Mark Parnell
My Usenet is improved; yours could be too:
http://blinkynet.net/comp/uip5.html
Apr 28 '06 #6
In article <km************ *************** *****@news.spar tanicus.utvinte rnet.ie>,
Spartanicus <in*****@invali d.invalid> wrote:
Mark Parnell <we*******@clar kecomputers.com .au> wrote:
The display:inline is needed so that the image gets treated like
text, which can then be centered with text-align:center.
Images are inline by default.


Then why am I having problems centering images unless I force them
to be inline?
Plus 'text-align:center' would need to be specified on a container
element, not on the image itself.


Woops. You're right. That's what I meant.

-A
Apr 28 '06 #7
On Fri, 28 Apr 2006 00:27:31 +0000 (UTC) axlq <ax**@spamcop.n et> wrote:

| In article <4b************ *@news.dfncis.d e>,
| Oliver Block <ol**********@e post.de> wrote:
|>what is the most elegent way to center an
|>image inside a web page.
|
| "Most elegant" would be "simplest" to me -- but that also happens to
| be non-compliant with HTML Strict and doesn't use CSS.
|
| So the next best way is:
|
| (CSS) .imgcenter { display: inline; text-align: center; border: 0; }
|
| (HTML) <img class="imgcente r" src="...." ...>
|
| The display:inline is needed so that the image gets treated like
| text, which can then be centered with text-align:center.

In the principle of separation of content and style, the centering of the
images would be style. So of course specifying it in CSS would be right.
It's the class name that I would object to, because it implys the style
being coded in the HTML. Why not a class name like "randomimag e", instead?
Then you can later change the style and align it differently without any
conflict in implied naming semantics.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
Apr 29 '06 #8
axlq wrote:
So the next best way is:

(CSS) .imgcenter { display: inline; text-align: center; border: 0; }

(HTML) <img class="imgcente r" src="...." ...>

The display:inline is needed so that the image gets treated like
text, which can then be centered with text-align:center.


After reading all answers I come do the following conclusion:
I need to add style="text-align:center;" to the surrounding div tag.:-)

Thanks for your help.

Best Regards,

Oliver

Apr 30 '06 #9

"Oliver Block" <ol**********@e post.de> wrote in message
news:4b******** *****@news.dfnc is.de...
Hi,

what is the most elegent way to center an
image inside a web page.

The image is radomly chosen by a cgi script
may be 300x400 or 400x300.

Are there any alignment commands for images?

tia,

Oliver


img{display:blo ck;
margin-left:auto;
margin-right:auto;
}
May 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
4097
by: J. Campbell | last post by:
I posted a question some time back about accessing a char array as an array of words. In order not to overrun the char array, I padded it with enough 0x00 bytes to ensure that when accessed as words I wouldn't overrun the array. I was told that this is dangerous and that there could be alignment problems if, for example, I wanted to access the char array elements from non-even multiples of sizeof(int). For example, if I had the array: ...
3
20861
by: signuts | last post by:
I am wondering what it means when a pointer is aligned? Could someone perhaps enlighten me or point me in the right direction? Thank you in advance. -- Sig
11
8907
by: L. Chen | last post by:
The standard says that a char* or void* pointer has the least strict alignment. But I do not know what is a strict alignment. What does that mean?
12
8129
by: Olaf Baeyens | last post by:
I am porting some of my buffer class code for C++ to C#. This C++ class allocates a block of memory using m_pBuffer=new BYTE; But since the class is also used for pointers for funtions that uses raw MMX and SSE power, the starting pointer MUST be starting at a 16 byte memory boundary. In C++ I allocate more memory than needed, and in a second phase I search for the address that starts on a 16 byte boundary. And I then use that new...
5
3914
by: Hendrik Schober | last post by:
Hi, we just run into the problem, that "default" alignment in the project properies dialog seem to be different. We have a project that's a DLL, which is linked with a couple of LIBs. All are with the same solution. All had "Default" set in the "Struct Member Alignment" entry. After some assembler debugging we found out that a struct member that is a member function pointer in
0
1251
by: Jean-François Michaud | last post by:
Hello, I was wondering if there was a way around leader-alignment. XSF V3.4 from Antenna House seems to be a very powerful FO -> PDF converter, but it doesn't support this particular attribute from fo:leader. It doesn't support leader-pattern-width either but this can be bypassed by using leader-pattern="use-content" as such: <fo:leader leader-pattern="use-content"> . </fo:leader>
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.