How to achieve clean text selection with Safari?
Asked Answered
A

4

8

See the behavior of text selection on one of Sam Harris' blog posts. Compare that to this post on the Bear app blog. On Firefox, there's no difference. However, on Safari the text selection on the Bloomberg article is all over the place, while the blog post on Sam Harris still manages to be concise.

How can text selection behavior be controlled to always just cover actual text and not overflow?

Demonstration

Apprehension answered 29/5, 2020 at 19:4 Comment(3)
Did you check my answer? it worked?Corselet
I commented on your answer @ꜱᴏʜᴇʟʟApprehension
Does this help ? #13912323Islamite
P
2

Make the parent element flex container by setting display: flex on the parent element.

::selection {
  background: #888;
  color: #eee;
}

div {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  background: #f8f8f8;
}

p {
  max-width: 350px;
}
<div>
  <p>
    Next to the top-level Notes section in the Sidebar is what professionals in the industry refer to as a disclosure triangle. Give it a tap-a-roo and you’ll see some handy custom sections like Todo, Today, and Locked (for Bear Pro users). For today, the
    section we want is Untagged, and you get three guesses as to which kinds of notes it collects
  </p>
  <p>
    Next to the top-level Notes section in the Sidebar is what professionals in the industry refer to as a disclosure triangle. Give it a tap-a-roo and you’ll see some handy custom sections like Todo, Today, and Locked (for Bear Pro users). For today, the
    section we want is Untagged, and you get three guesses as to which kinds of notes it collects
  </p>
</div>

Alternatively, you can make the p elements inline-block elements.

::selection {
  background: #888;
  color: #eee;
}

div {
  background: #f8f8f8;
  text-align: center;
}

p {
  display: inline-block;
  max-width: 350px;
  text-align: left;
}
<div>
  <p>
    Next to the top-level Notes section in the Sidebar is what professionals in the industry refer to as a disclosure triangle. Give it a tap-a-roo and you’ll see some handy custom sections like Todo, Today, and Locked (for Bear Pro users). For today, the
    section we want is Untagged, and you get three guesses as to which kinds of notes it collects
  </p>
  <p>
    Next to the top-level Notes section in the Sidebar is what professionals in the industry refer to as a disclosure triangle. Give it a tap-a-roo and you’ll see some handy custom sections like Todo, Today, and Locked (for Bear Pro users). For today, the
    section we want is Untagged, and you get three guesses as to which kinds of notes it collects
  </p>
</div>
Polychrome answered 13/6, 2020 at 11:28 Comment(0)
N
1

This is due to the way the element is wrapped. You can reproduce this effect by displaying your container with "flex", or by hiding the overflow. But the easies and the less impacting way to reproduce is to force the rendering of your container differently. Try this:

.entry-content{
    transform: translateY(0);
}

Example here :

.wrapper{
  width:300px;
  margin:0 auto;
  transform: translateY(0);
}
<div class="wrapper">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, </p>
<p>quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
Niveous answered 13/6, 2020 at 11:25 Comment(0)
B
0

Try adding some reset styles before your own CSS. Something like this from https://meyerweb.com/eric/tools/css/reset/ :

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
Berner answered 7/6, 2020 at 6:57 Comment(1)
No luck with this one. Will try some more reset styles.Apprehension
C
-2

Please ONLY add to your .entry-content these styles : max-width: 47rem; margin: 0 auto; after adding them check the page again and let me know if something changed or not? :)

Corselet answered 8/6, 2020 at 21:25 Comment(1)
I don't have any .entry-content classes. I've seen some change when adding your styles to everything (*), but that breaks things.Apprehension

© 2022 - 2024 — McMap. All rights reserved.