How can I achieve pixel-perfect positioning and spacing of textual elements across browsers?

家住魔仙堡 提交于 2019-12-03 22:22:36

Send the text to the server, have the server render an image, display the image. Voilà.

I would say this is nearly impossible.

I would also say that there is no reason to have pixel perfect across all browsers because the overwhelming majority of visitors only view your site with one browser. And those who do visit your site in more than one browser (say at work and at home) are unlikely to notice elements that are off a few pixels or have slightly different border colors.

What we should be concerned about is that the content looks good in each browser.

That said, here's a great list of textarea tricks: http://css-tricks.com/6841-textarea-tricks/

One main reason that PDF exists is that browsers are not about pixel-identical layout but PDF is. Among other things, not even typefaces are guaranteed to be the same from one OS/browser to the next.

Even, if you don't let the browser position anything and you do all your own pixel level positioning, you still won't necessarily have the same fonts to work with. If you let the browser position anything, then you can have variations.

Would one solution be to begin your css with a clean slate? Give everything a known default?

For example, I start my css files like this so I always know what to expect:

*{
margin:0;
padding:0;
}

Is that what you're looking for? Similarly, you could change '*' to 'textarea'.

I'm not sure if it is possible, however one thing you may want to look into is using the web developer toolbar for firefox or the web developer add-on for chrome. There is an option to disable browser default styles. Check this and then style everything. The borders, border type, all margins, paddings, background colors, etc. Then reenable browser default styles and make sure it looks the same. If not, wash, rinse and repeat.

Also, if fonts play a part, you will have to embed them into the page since some operating systems may not have a particular font installed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!