I've 4 boxes of text like in this example here:
html, body {
height: 100%;
margin: 0;
}
.grid2x2 {
min-height: 100%;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.grid2x2 > div {
display: flex;
flex-basis: calc(50% - 70px);
justify-content: center;
flex-direction: column;
}
.grid2x2 > div > div {
display: flex;
justify-content: center;
flex-direction: row;
}
.box { margin: 20px; padding: 15px; }
.box1 { background-color: red; }
.box2 { background-color: orange; }
.box3 { background-color: purple; }
.box4 { background-color: grey; }
<div class="grid2x2">
<div class="box box1"><div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div></div>
<div class="box box2"><div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div></div>
<div class="box box3"><div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div></div>
<div class="box box4"><div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div></div>
</div>
What I want to do now is that when I start selecting text inside box one, I want to only allow the selection of every text inside this box including child elements but not outside of it.
So with other words, selecting text inside a box should only work if the selection started inside it and should not go out of the box.
Is this possible? If yes, whats the best way to deal with this?
Update
I've posted a minimal example above. The problem is that I can't get it working on my page so I've took some time to build a 1:1 example:
#wrapper {
margin-top: 15px;
margin-bottom: 15px;
padding-top: 20px;
padding-bottom: 20px;
max-height: 200px;
border: 1px solid;
overflow-y: scroll;
outline: 0;
user-select: none;
background: lightgray;
}
#wrapper:active,
#wrapper:focus {
user-select: initial;
color: red; //For debugging
}
#wrapper .message {
padding-left: 15px;
padding-right: 15px;
margin-bottom: 12px;
-webkit-box-flex: 0;
-ms-flex: 0 0 auto;
flex: 0 0 auto;
}
#wrapper .message .content {
background: #ffffff;
}
#wrapper .message .content-header {
margin-bottom: 2px;
}
#wrapper .message .content-header,
#wrapper .message .content-footer {
user-select: none; //Should be always not selectable
}
<div id="outer">
<div>I should not get marked when marking started inside the wrapper.</div>
<div id="wrapper" tabindex="-1">
<div class="message">
<div class="container">
<div class="content">
<div class="content-header">
<span class="title">I'm a test title</span>
</div>
<div class="content-text">Hello, I'm the content of the message</div>
<div class="content-footer">
<span class="time">02:20</span>
</div>
</div>
</div>
</div>
<div class="message">
<div class="container">
<div class="content">
<div class="content-header">
<span class="title">I'm a test title</span>
</div>
<div class="content-text">Hello, I'm the content of the message</div>
<div class="content-footer">
<span class="time">02:20</span>
</div>
</div>
</div>
</div>
<div class="message">
<div class="container">
<div class="content">
<div class="content-header">
<span class="title">I'm a test title</span>
</div>
<div class="content-text">Hello, I'm the content of the message</div>
<div class="content-footer">
<span class="time">02:20</span>
</div>
</div>
</div>
</div>
<div class="message">
<div class="container">
<div class="content">
<div class="content-header">
<span class="title">I'm a test title</span>
</div>
<div class="content-text">Hello, I'm the content of the message</div>
<div class="content-footer">
<span class="time">02:20</span>
</div>
</div>
</div>
</div>
<div class="message">
<div class="container">
<div class="content">
<div class="content-header">
<span class="title">I'm a test title</span>
</div>
<div class="content-text">Hello, I'm the content of the message</div>
<div class="content-footer">
<span class="time">02:20</span>
</div>
</div>
</div>
</div>
<div class="message">
<div class="container">
<div class="content">
<div class="content-header">
<span class="title">I'm a test title</span>
</div>
<div class="content-text">Hello, I'm the content of the message</div>
<div class="content-footer">
<span class="time">02:20</span>
</div>
</div>
</div>
</div>
<div class="message">
<div class="container">
<div class="content">
<div class="content-header">
<span class="title">I'm a test title</span>
</div>
<div class="content-text">Hello, I'm the content of the message</div>
<div class="content-footer">
<span class="time">02:20</span>
</div>
</div>
</div>
</div>
</div>
<div>I should not get marked when marking started inside the wrapper.</div>
</div>