Блог → Программирование

Про border-style: dotted

По интернету уже довольно давно ходит картинка, показывающая как разные браузеры обрабатывают толстые границы с точками. С тех пор ничего не изменилось. Но, как выяснилось, чтобы поймать баги, достаточно границы в один пиксель! Во время создания сайта у меня был код, похожий на этот:

<!DOCTYPE html>
<html><head><title>Test page</title>
<style>
hr {
  border: 0;
  width: 20px;
  height: 1px;
  border-bottom: 1px black dotted;
  display: inline-block;
}
div.test {
  width: 10px;
  height: 10px;
  border-left: 1px black dotted;
  border-bottom: 1px black dotted;
}
</style>
</head><body><hr><div class="test"></div></body></html>

Посмотрим, как ведут себя браузеры (изображения я увеличил):

Изображение

Firefox и IE отрисовывают всё как надо. А вот с остальными дела обстоят хуже:

Chrome добавляет лишнюю точку к прямой линии. Если поиграться с размерами «уголка», то двойные точки будут и там. Поразительно, браузер может запускать трёхмерные игры, но не может нормально нарисовать линию с точками. Аналогично и в Safari — видимо, баг в движке Webkit. Возникает только если размер элемента в пикселях — чётное число. Для исправления предлагается добавить к элементу лишние отступы или границы, но это бесполезно, если размеры непостоянные.

У «Оперы» же расстояние между точками совершенно не такое, как у остальных. Вообще, в стандарте это не оговорено, но другие браузеры всё же стремятся к тому, чтобы там был один пиксель. В «уголке» расстояние и вовсе огромное. Двойная точка тоже присутствует, но связи с чётностью расстояния я не выявил.

Самое простое решение — вообще отказаться встроенного свойства и использовать фоновые изображения. Чтобы лишний раз не дёргать сервер, картинки можно закодировать в Base64 и поместить прямо в CSS. Таблица стилей в этом случае выглядит вот так:

hr {
  border: 0;
  width: 20px;
  height: 1px;
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAA9JREFUGFdjYGBg+A8EDAAN+wP9OcJBJQAAAABJRU5ErkJggg==);
  display: inline-block;
}
div.test {
  width: 10px;
  height: 10px;
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAABhJREFUKFNj+I8XMAABlIkNDHfd2Mn//wFkNg//vXu49gAAAABJRU5ErkJggg==);
  background-repeat: no-repeat;
}

У такого решения есть недостатки, легко менять размеры «уголка» уже не получится, а линии будут слегка размытые на Retina дисплеях — для них нужно отдельно отдавать изображения с удвоенным разрешением.

6 января 2013 21:31 

Комментарии


https://glassiindia.Wordpress.com
https://glassiindia.Wordpress.com — 2 месяца назад
What's up colleagues, how is all, andd what you woulod like to say regarding this piece of writing, in my vikew
its really amazing in favor of me. https://glassiindia.Wordpress.com

https://Www.bridgewaystaffing.com/employer/tonybet/
https://Www.bridgewaystaffing.com/employer/tonybet/ — 2 месяца назад
Thanks for finally writing about >Про border-style: dotyed — DuMOHsmol's page
<Loved it! https://Www.bridgewaystaffing....ployer/tonybet/

https://Nrlplayers.Wordpress.com
https://Nrlplayers.Wordpress.com — 2 месяца назад
Howdy, i read your blog occasionally and i own a similar onne and i was jut curious if you get a
lot of spzm comments? If so how do you stolp it, any plugin or
anything yyou can suggest? I get so much lately it's driving me insane so any assistance is
very much appreciated. https://Nrlplayers.Wordpress.com

https://www.04637.com.ua/list/530660
https://www.04637.com.ua/list/530660 — 2 месяца назад
Wonderful blog! I found it wwhile browsinhg on Yahoo News.

Do you have any tips onn how tto get listed in Yahoo News?
I've been trying for a while but I never seem to get there!

Many thanks https://www.04637.com.ua/list/530660

https://azurslotgames.bcz.com/azurslot-games/
https://azurslotgames.bcz.com/azurslot-games/ — 2 месяца назад
Its like you learn my thoughts! You seem to understand so much
about this, such as you wrote the ebook in it or something.
I believe that you can do with some percent to pressure the message home
a little bit, however otther than that, this is fantastic
blog. An excellent read. I'll definitely be back. https://azurslotgames.bcz.com/...azurslot-games/

https://groups.Google.com/g/azurslotcom/c/uGip7Z_xu0o
https://groups.Google.com/g/azurslotcom/c/uGip7Z_xu0o — 2 месяца назад
I really like yoour blog.. very nice colors & theme.
Didd yyou make thus website yourself or did you hire someone to do it for you?
Pllz reply as I'm looking to create my own blog and
would likme to find out where u got this from.

many thanks https://groups.Google.com/g/az...m/c/uGip7Z_xu0o

https://writeablog.net/sp344ovahs
https://writeablog.net/sp344ovahs — 2 месяца назад
Appreciation to myy fathe who stated to me concerning this webpage, this website is in fact amazing. https://writeablog.net/sp344ovahs

https://sites.Google.com/view/top-ratedonlineslots/top-rated-online-slots
https://sites.Google.com/view/top-ratedonlineslots/top-rated-online-slots — 2 месяца назад
wonderful post, very informative. I ponder why
the opposite specialists of this sector do not realize this.
Youu must continue your writing. I'm confident, you have a huge readers' base already! https://sites.Google.com/view/...ed-online-slots

https://Telegra.ph/Discover-Azurslot-09-02
https://Telegra.ph/Discover-Azurslot-09-02 — 2 месяца назад
Magnificent weeb site. A lot off useful ingo here. I'm sending it to some buddies
ans also sharing in delicious. And obviously, thank you on your effort! https://Telegra.ph/Discover-Azurslot-09-02

https://Avcorrealty.com/agent/nereidabaron2/
https://Avcorrealty.com/agent/nereidabaron2/ — 2 месяца назад
Aw, his waas an extremely goo post. Finding the time andd actual effort too produce a superb article… but what
can I say… I procrastinate a lot and don't manage tto get nearly anything done. https://Avcorrealty.com/agent/nereidabaron2/

https://realty-jp.com/author/britneycardone/
https://realty-jp.com/author/britneycardone/ — 1 месяц назад
you are really a excellent webmaster. The website loading speed is amazing.

It sort of feels that you are doing any unique trick. In addition, The
contents are masterwork. you've performed a
wonderful activity on this subject! https://realty-jp.com/author/britneycardone/

https://Aaronguglani.com/author/colleenchampli/
https://Aaronguglani.com/author/colleenchampli/ — 1 месяц назад
What's Going down i am new to this, I stumbled upon this I've found It absolutely useful and it has
aided me out loads. I'm hoping to contribute & aid other
users like its helped me. Good job. https://Aaronguglani.com/autho...colleenchampli/

https://ariaqa.com/employer/euro-girls-escort/
https://ariaqa.com/employer/euro-girls-escort/ — 1 месяц назад
Incredible! This blog looks exactly like my old one!
It's on a totally different subject but it has pretty much
the same page layout and design. Great choice of colors! https://ariaqa.com/employer/eu...o-girls-escort/

https://Sunnyvibes.mx/author/randymccue162/
https://Sunnyvibes.mx/author/randymccue162/ — 1 месяц назад
I'm more than happy to discover this web site. I need to to thank you for ones time just for this fantastic read!!
I definitely appreciated every part of it and I have you
book-marked to see new stuff in your web site. https://Sunnyvibes.mx/author/randymccue162/

https://landlinkconnect.com/author/ncjselina97941/
https://landlinkconnect.com/author/ncjselina97941/ — 1 месяц назад
Very good post. I am facing a few of these issues as well.. https://landlinkconnect.com/au...ncjselina97941/

https://Dominicarealestate767.com/author/eviezox927536/
https://Dominicarealestate767.com/author/eviezox927536/ — 1 месяц назад
Hi colleagues, how is everything, and what you desire to say regarding this paragraph,
in my view its really amazing in support of me. https://Dominicarealestate767..../eviezox927536/

https://Brokernetwork.in/author/sophie88748436/
https://Brokernetwork.in/author/sophie88748436/ — 1 месяц назад
I am curious to find out what blog system you happen to be working with?
I'm experiencing some small security problems with my latest site and
I'd like to find something more secure. Do you have any solutions? https://Brokernetwork.in/autho...sophie88748436/

https://northwaveasia.com/author/xiomaradaves19/
https://northwaveasia.com/author/xiomaradaves19/ — 1 месяц назад
What a material of un-ambiguity and preserveness of precious know-how on the topic of unpredicted emotions. https://northwaveasia.com/auth...xiomaradaves19/

https://Assigncircle.com/author/kathleendarby/
https://Assigncircle.com/author/kathleendarby/ — 1 месяц назад
There's definately a great deal to find out
about this issue. I love all the points you made. https://Assigncircle.com/autho.../kathleendarby/

https://craftsmansearch.com/employer/euro-escort/
https://craftsmansearch.com/employer/euro-escort/ — 1 месяц назад
That is really fascinating, You are a very professional blogger.
I've joined your feed and sit up for seeking more of your magnificent post.
Additionally, I've shared your web site in my social networks https://craftsmansearch.com/em...er/euro-escort/

https://Nujob.ch/companies/tonybet1/
https://Nujob.ch/companies/tonybet1/ — 3 недели назад
Quality articles or reviews is the crucial to be a focus for the viewers to pay a visit the web site, that's what this
web site is providing. https://Nujob.ch/companies/tonybet1/

https://buyrentvilla.com/author/tabithaa878368/
https://buyrentvilla.com/author/tabithaa878368/ — 3 недели назад
I want to to thank you for this excellent read!!
I certainly enjoyed every little bit of it.
I have you book marked to check out new stuff you post… https://buyrentvilla.com/autho...tabithaa878368/

https://pracaeuropa.pl/companies/tonybet/
https://pracaeuropa.pl/companies/tonybet/ — 3 недели назад
First of all I would like to say superb blog! I had a quick question which
I'd like to ask if you don't mind. I was curious to find
out how you center yourself and clear your head prior to writing.
I've had difficulty clearing my thoughts in getting my
ideas out there. I do enjoy writing however it just seems like the first 10
to 15 minutes are usually lost simply just trying to figure out how to begin. Any ideas or tips?
Appreciate it! https://pracaeuropa.pl/companies/tonybet/

https://realty-jp.com/author/adrianna24j954/
https://realty-jp.com/author/adrianna24j954/ — 3 недели назад
Hey! This is kind of off topic but I need some advice from
an established blog. Is it difficult to set up your own blog?
I'm not very techincal but I can figure things out pretty quick.
I'm thinking about making my own but I'm not sure
where to begin. Do you have any tips or suggestions?

Thank you https://realty-jp.com/author/adrianna24j954/

https://Avcorrealty.com/agent/eric29w9917214/
https://Avcorrealty.com/agent/eric29w9917214/ — 3 недели назад
Great information. Lucky me I came across
your blog by chance (stumbleupon). I've bookmarked it for
later! https://Avcorrealty.com/agent/...eric29w9917214/

Ваше имя Сайт или блог (опционально) Аватар (опционально, e-mail для Gravatar или ссылка на картинку с ipic.su) Текст комментария

Справка по написанию комментария

  • Для вставки аватара зарегиструйтесь на сервисе Gravatar и укажите ваш e-mail. Вы также можете загрузить аватар на http://ipic.su и скопировать текст с поля «прямая ссылка». Другие сервисы или хостинги изображений не поддерживаются. Большие изображения будут уменьшены автоматически. Пример:

    http://ipic.su/img/img7/fs/user4.1358962896.png
  • Имя, адрес и аватар сохраняются, второй раз вводить не придётся
  • Кликните на аватар, чтобы вставить имя пользователя
  • Слово обрамлённое «звёздочками» становится *жирным*
  • Адрес ссылки автоматически становится ссылкой — http://anothersite.ru
  • Ссылки на текст с http://pastebin.com автоматически разворачиваются в тексте комментария
  • Цитату следует начинать со знака «больше»:
    > пример многострочной
    > цитаты