Текст накладывается друг на друга css как исправить

Суть всей проблемы в том, когда ширина браузера уменьшается до того размера, когда надпись не влезает в размеченную область, то вместо переноса на новую строку, он просто накладывается друг на друга. Данная ситуация повторяется и при принудительном переносе на новую строку тегом <br>.

HTML

<article class="back_coupling" id="contacts">
    <p class="title">
        <span class="number_title">03</span> Связь <br>со мной
    </p>
    <div class="form_feedback">
        <form class="feedback">
            <input class="data" type="text" placeholder="Имя" required/>
            <input class="data" type="text" placeholder="Email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$" required/>
            <input class="subject" type="text" placeholder="Тема" required/>
            <textarea class="message" placeholder="Сообщение"></textarea>
            <input title="Сообщение будет отправлено получателю" class="sub" type="submit" value="Отправить" />
            <div class="social">
                <picture>
                    <a href="#" title="Vkontakte"><img class="icon-social" src="/img/icons/icon-vk.png" /></a>
                    <a href="#" title="Skype"><img class="icon-social" src="/img/icons/icon-skype.png" /></a>
                    <a href="#" title="GitHub"><img class="icon-social" src="/img/icons/icon-github.png" /></a>
                </picture>
            </div>
        </form>
    </div>
</article>

CSS

     :root {
    --main_color: #C000CD;
    --main_color_light: #DB30E6;
    --main_cont: Montserrat-Regular;
    --main_title_color: silver;
    --margin_ability: 10px;
    --load_body: #444444;
    --padding_between_sections: 200px 0px 200px 0px;
}
.title {
        font-size: 48px;
        letter-spacing: 0.1em;
        /*color: var(--main_title_color);*/
        text-align: center;
        font-weight: bold;
        color: #fff;
        line-height: 0px;
        transition: 1s;
        -o-transition: 1s;
        -moz-transition: 1s;
        -webkit-transition: 1s;
        display: block;
        position: relative;
        white-space: normal;
    }    
    .back_coupling {
            background: url('/img/endfon.jpg') no-repeat center fixed;
            background-size: cover;
            width: 100%;
            background-color: #464646;
            padding: var(--padding_between_sections);
            z-index: 1;
            box-shadow: 0px 0px 7px 3px #323747 inset;
        }

        .form_feedback {
            display: flex;
            justify-content: center;
            -webkit-justify-content: center;
            padding: 50px 0px 0px;
        }

        .feedback {
            background-color: var(--main_title_color);
            padding: 50px;
            width: 480px;
            background-color: #4D5366;
            box-shadow: 0px 0px 5px 5px #323747;
            border-radius: 15px;
            text-align: center
        }

        .feedback .data,
        .feedback .subject,
        .feedback .message {
            border: 0px;
            padding: 10px;
            margin: 5px 0px;
            width: 163px;
            display: inline-block;
            border-radius: 2px;
        }

        .feedback .subject,
        .feedback .message {
            width: 350px;
        }

        .feedback .message {
            height: 100px;
            font-family: var(--main_cont);
            font-size: 12px;
            font-style: normal;
        }

        .feedback .sub {
            width: 372px;
            margin-top: 5px;
            text-align: center;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            height: 40px;
            cursor: pointer;
            color: #fff;
            background-color: #323747;
            box-shadow: 0px 0px 4px 1px var(--main_color);
            border: 0px;
            transition: all ease 1s;
            -o-transition: all ease 1s;
            -moz-transition: all ease 1s;
            -ms-transition: all ease 1s;
            -webkit-transition: all ease 1s;
            border-radius: 2px;
        }

        .feedback .sub:hover {
            box-shadow: 0px 0px 4px 1px var(--main_color_light);
        }

        .feedback>input {
            display: flex;
        }

введите сюда описание изображения

По результатам ответов выделил решения, которые работают

1) метод, предложенный Air

использование свойства flex: https://jsfiddle.net/7py3hg7u/

.line {
display:flex;
flex-direction:row;

  width: 500px;
  min-height: 27px;
  height: auto;
  margin: 5px 0px 0px 0px;

  font-size: 18px;
  background: orange;
  border: 1px solid black;
  /*padding чтобы ты видел что родитель растягивается*/
  padding:5px;
}

.line>div:first-child{
  width: 150px;
  background: red;
}

.line>div:last-child {
  width: calc(100% - 150px);
  background: lime;
}

недостаток метода:

  • дочерние элементы занимают 100% высоты от родительского элемента
  • свойство flex не полностью поддерживается браузером IE (только 11 версией и то не до конца)

2) метод, предложенный DaemonHK:

использование в дочерних div свойства font-size, position, vertical-align, использование в родительском свойства font-size: 0px: https://jsfiddle.net/o88pfdqr/

.line {
  position: relative;
  width: 500px;
  min-height: 27px;
  margin: 5px 0px 0px 0px;
  padding: 0px;
  font-size: 0;
  background: orange;
  border: 1px solid black;
}

.line>div:first-child:not(:only-child) {
  position: relative;
  left: 0px;
  width: 150px;
  background: red;
  display:inline-block;
  font-size:18px;
  vertical-align:top;
}

.line>div:last-child {
  position: relative;
  right: 0px;
  width: calc(100% - 150px);
  background: lime;
  display:inline-block;
  font-size:18px;
  vertical-align:top;
}

недостаток метода:

  • перестало работать выравнивание справа для одного элемента (https://jsfiddle.net/o88pfdqr/1/)
  • использование font-size для дочерних элементов и обнуление его для родительского элемента

3) метод, предложенный Дмитрием Поляниным:

использование в дочерних элементах flex, а в родительском clear: https://jsfiddle.net/o88pfdqr/4/

.line {
  width: 500px;
  margin: 5px 0px 0px 0px;
  padding: 0px;
  font-size: 18px;
  background: orange;
  border: 1px solid black;
  clear:both;
}

.line>div:first-child:not(:only-child) {
  width: 150px;
  background: red;
  float: left;
  margin-bottom: 5px;
}

.line>div:last-child {
  width: calc(100% - 150px);
  background: lime;
  float: right;
  margin-bottom: 5px;
}

Недостаток метода:

  • теряется высота родительского элемента, т.е. дочерний элемент может
    стать больше родительского по высоте

Общий вывод:

Наилучший способ, как мне кажется, у AIR, но меня пугает flex своей несовместимостью (надо протестировать), при том, что я реально взаимодействую с людьми у которых чуть ли не IE6 стоит :) (утрирую немного)

Есть еще одна проблема-вопрос

Дополнительно я хотел бы обеспечить следующий функционал (тоже только листами стилей без привлечения дополнительных тегов):

если высота дочерних блоков меньше 27px, то выполняется выравнивать дочерних элементов по вертикали (middle) в родительском блоке, который 27px, а если хотя бы 1 дочерний элемент больше по высоте 27px, то выравнивание выполняется по top

I know that I can stack elements in separate layers by creating new stacking contexts with relative/absolute positioning (Demo) or opacity (Demo)

However I was under the impression that by default an element further down in the html will be painted above previous elements.

Apparently, this is so for the element’s background, but I just noticed that text works differently.

So with simple markup like:

<div class="div1">text1</div>
<div class="div2">text2</div>

The background of the 2nd div will be above the first, but the text overlaps.

Demo

enter image description here

Must I create a new stacking context to prevent the text overlapping here?

asked Jul 31, 2014 at 9:24

Danield's user avatar

DanieldDanield

121k36 gold badges224 silver badges250 bronze badges

Why does text on the same layer overlap — even when it has an opaque background?

The spec says (emphases mine):

Within each stacking context, the following layers are painted in back-to-front order:

  1. the background and borders of the element forming the stacking context.
  2. the child stacking contexts with negative stack levels (most negative first).
  3. the in-flow, non-inline-level, non-positioned descendants.
  4. the non-positioned floats.
  5. the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks.
  6. the child stacking contexts with stack level 0 and the positioned descendants with stack level 0.
  7. the child stacking contexts with positive stack levels (least positive first).

The backgrounds and the text are considered separately in the painting order: the backgrounds are represented by #3, and the text is represented by #5. The second element appears later in the source, so it is painted over the first, but the text still needs to be painted over the backgrounds, because the two elements are participating in the same stacking context.

Must I create a new stacking context to prevent the text overlapping here?

Yes, the best way to deal with this is by positioning the elements or by having them establish their own stacking contexts. A stacking context is always self-contained, so having each element establish its own stacking context will always ensure that the backgrounds and text of the two elements don’t overlap one another.

Community's user avatar

answered Aug 3, 2014 at 8:43

BoltClock's user avatar

BoltClockBoltClock

695k159 gold badges1384 silver badges1352 bronze badges

1

If you add position: relative; to the divs it fixes it. At the moment they have the default position: static; which is causing this effect.

answered Jul 31, 2014 at 9:30

theleebriggs's user avatar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
@font-face {
  font-family: "OpenSans";
  src: url("https://netology-code.github.io/html-2-diploma/sources/fonts/OpenSans-Regular.woff")
      format("woff2"),
    url("https://netology-code.github.io/html-2-diploma/sources/fonts/OpenSans-Regular.woff")
      format("woff");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
 
@font-face {
  font-family: "OpenSans";
  src: url("https://netology-code.github.io/html-2-diploma/sources/fonts/OpenSans-Bold.woff")
      format("woff2"),
    url("https://netology-code.github.io/html-2-diploma/sources/fonts/OpenSans-Bold.woff")
      format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
 
body {
  margin: 0;
}
 
.banner {
  position: relative;
  width: 1170px;
  height: 450px;
  background-image: url(https://netology-code.github.io/html-2-diploma/sources/images/banner-bg.jpg);
  background-color: rgba(0, 0, 0, 0.6);
  background-repeat: no-repeat;
  background-size: auto;
  background-position: top right 50%;
  margin-left: auto;
  margin-right: auto;
  z-index: 1;
}
 
.banner:before {
  content: "";
  width: 100%;
  height: 100%;
  position: absolute;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 2;
}
 
.banner_logo {
  position: absolute;
  width: 179px;
  height: 41px;
  left: 3px;
  top: 20px;
  z-index: 3;
}
 
.banner-title {
  position: absolute;
  margin-left: auto;
  margin-right: auto;
  left: 0;
  right: 0;
  top: 193px;
  text-align: center;
  width: 715px;
  font-family: OpenSans, Arial, sans-serif;
  font-weight: bold;
  text-transform: uppercase;
  line-height: 74.97 px;
  font-size: 45px;
  color: #fff;
  z-index: 3;
}
 
.menu-list {
  position: absolute;
  right: -2px;
  top: 0;
  display: flex;
  z-index: 3;
}
 
.menu-list-item {
  font-family: OpenSans, Arial, sans-serif;
  text-transform: uppercase;
  line-height: 36px;
  font-size: 13px;
  list-style-type: none; 
  margin-left: 35px;
}
 
.menu-item {
  color: #fff;
  text-decoration: none;
}
 
.menu-item:hover {
    text-decoration: underline;
   }
 
.content {
  margin: 64px 0;
  width: 1170px;
  height: 2420px;
  margin-left: auto;
  margin-right: auto; 
}
 
.post-list {
  position: relative;
  width: 748px;
  margin-bottom: 59px;
}
 
.frame-post {
  position: absolute;
  margin-left: 30px;
  top: -11px;
  left: 381px;
  width: 367px;
  height: 294px;
}
 
.category-post {
  font-family: OpenSans, Arial, sans-serif;
  font-weight: bold;
  text-transform: uppercase;
  line-height: 39.98px;
  font-size: 14px;
  word-spacing: 19px;
}
 
.category-post-item {
  text-decoration: none;
  color: #b59f5b;
}
 
.category-post-item:hover {
  text-decoration: underline;
}
 
.title-post {
  font-family: OpenSans, Arial, sans-serif;
  font-weight: bold;
  text-transform: uppercase;
  line-height: 23.99px;
  font-size: 20px;
  margin-bottom: 10px;
  
}
 
.title-post-item {
  color: #000;
  text-decoration: none;
}
 
.title-post-item:hover {
  color: #b59f5b;
}
 
.date-author-post {
  font-family: OpenSans, Arial, sans-serif;
  font-weight: bold;
  line-height: 39.98px;
  font-size: 12px;
  margin-bottom: 35px;
}
 
.post-date {
  font-family: OpenSans, Arial, sans-serif;
  font-weight: normal;
  color: #888888;
  line-height: 39.98px;
  font-size: 12px;
  margin-right: 11px;
  text-transform: none;
}
 
.text-post {
  font-family: OpenSans, Arial, sans-serif;
  font-weight: normal;
  line-height: 22px;
  font-size: 15px;
  color: #000;
}
 
.picture{
  width: 381px;
  height: 294px;
}
 
.picture-post {
  position: absolute;
}
 
.laters-posts-content {
  position: relative;
  margin-bottom: 22px;
}
 
.laters-posts {
  position: absolute;
  margin-left: 150px;
  top: -10px;
  left: 748px;
  width: 272px;
  height: 602px;
}
 
.last-posts-title {
  text-align: center;
  font-family: OpenSans, Arial, sans-serif;
  font-weight: bold;
  line-height: 29.15px;
  text-transform: uppercase;
  font-size: 14px;
  color: #000;
}
 
.outline {
  width: 66px;
  height: 3px;
  background-color: rgba(181, 159, 92, 0.4);
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 29px;
}
 
.new-posts{
  position: absolute;
}
 
.later-post {
  font-family: OpenSans, Arial, sans-serif;
  font-weight: bold;
  text-transform: uppercase;
  line-height: 17.99px;
  font-size: 14px;
  margin-left: 90px;
  margin-top: -15px;
}
 
.later-post-item {
  color: #000;
  text-decoration: none; 
}
 
.later-post-item:hover {
  color: #b59f5b;
}

Проблема была тут: line-height: 1.5px;. Вы указали 1.5px, а это очень мало, вот и еффект как-будто текст сам на себя наложился.

Возможно, Вы хотели указать line-height: 1.5, 1.5 означает размер 1.5 * размер текущего шрифта font-size

body {
  margin: 0;
  background: url("../images/pattern.png");
  font-family: Tahoma;
  font-size: 18px;
}

.card {
  width: 400px;
  margin: 30px auto;
  padding: 20px;
  background-color: #fff;
  box-shadow: 0 5px 10px;
  border-radius: 10px;
  overflow-wrap: break-word;
}

.card-photo {
  display: block;
  width: 200px;
  height: 200px;
  margin: 0 auto;
  border-radius: 50%;
}

.card-title {
  font-size: 20px;
  text-align: center;
  color: #098e00;
}

.card-text {
  font-size: 15px;
}
<div class="card">
  <img class="card-photo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/VAN_CAT.png/1200px-VAN_CAT.png" alt="No name">
  <h1 class="card-title"> Сантехник </h1>
  <p>Текст выходитыфафыафышарфыаршфыхарфыхрахфырахфырахфырахфырахфыа</p>
</div>

Понравилась статья? Поделить с друзьями:
  • Как найти мой логин в яндексе
  • Как составить резюме футболисту
  • Как найти облако в телефоне андроид ксиоми
  • Как в инстаграмме найти понравившиеся мне публикации
  • Как составить химическую формулу учитывая значения электроотрицательности элемента