0

Помогите пожалуйста не могу разобрать в чем причина. При добавлении в hover простого border для кнопки, происходит выдавливание соседних элементов. Такое чувство что border-box не работает.

Обнуляюище стили reset.css

*,
*:before,
*:after {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

html,
body,
div,
span,{
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    vertical-align: baseline;
    text-decoration: none;
}

:focus {
    outline: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: inherit;
    font-size: inherit;
}

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;
}

input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
    -moz-appearance: none;
}

input[type="search"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    box-sizing: content-box;
}

textarea {
    overflow: auto;
    vertical-align: top;
    resize: vertical;
}

audio,
canvas,
video {
    display: inline-block;
    *display: inline;
    *zoom: 1;
    max-width: 100%;
}

audio:not([controls]) {
    display: none;
    height: 0;
}

[hidden] {
    display: none;
}

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

a:focus {
    outline: thin dotted;
}

a:active,
a:hover {
    outline: 0;
}

img {
    border: 0;
    -ms-interpolation-mode: bicubic;
}

figure {
    margin: 0;
}

form {
    margin: 0;
}

fieldset {
    border: 1px solid #c0c0c0;
    margin: 0 2px;
    padding: 0.35em 0.625em 0.75em;
}

legend {
    border: 0;
    padding: 0;
    white-space: normal;
    *margin-left: -7px;
}

button,
input,
select,
textarea {
    font-size: 100%;
    margin: 0;
    vertical-align: baseline;
    *vertical-align: middle;
}

button,
input {
    line-height: normal;
}

button,
select {
    text-transform: none;
}

button,
html input[type="button"],
input[type="reset"],
input[type="submit"] {
    -webkit-appearance: button;
    cursor: pointer;
    *overflow: visible;
}

button[disabled],
html input[disabled] {
    cursor: default;
}

input[type="checkbox"],
input[type="radio"] {
    box-sizing: border-box;
    padding: 0;
    *height: 13px;
    *width: 13px;
}

input[type="search"] {
    -webkit-appearance: textfield;
    -moz-box-sizing: content-box;
    -webkit-box-sizing: content-box;
    box-sizing: content-box;
}

input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
}

button::-moz-focus-inner,
input::-moz-focus-inner {
    border: 0;
    padding: 0;
}

textarea {
    overflow: auto;
    vertical-align: top;
}

table {
    border-collapse: collapse;
    border-spacing: 0;
}

html,
button,
input,
select,
textarea {
    color: #222;
}

::-moz-selection {
    background: #b3d4fc;
    text-shadow: none;
}

::selection {
    background: #b3d4fc;
    text-shadow: none;
}

img {
    vertical-align: middle;
}

fieldset {
    border: 0;
    margin: 0;
    padding: 0;
}

textarea {
    resize: vertical;
}

.chromeframe {
    margin: 0.2em 0;
    background: #ccc;
    color: #000;
    padding: 0.2em 0;
}

CSS для btn

a.btn {
  display: inline-block;
  background-color: #998675;
  border-radius: 3px;
  padding: 15px 20px;
  font-family: "Raleway", sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #ffff;
  text-transform: uppercase;
  -webkit-box-shadow: 0 -3px #736357 inset;
          box-shadow: 0 -3px #736357 inset;
  -webkit-transition: 0.2s;
  transition: 0.2s;
}
1
  • 1
    Отредактируйте вопрос, оформите код с помощью кнопки "вставить фрагмент кода". Добавьте html что бы было видно проблему
    – DemoS
    19 июн 2020 в 7:02

1 ответ 1

0

Если я правильно понимаю, изначально у кнопки нет border и при hover он появляется, то в этом случае размер элемента увеличивается на 1px с каждой стороны в результате чего перемещаются последующие элемент. Попробуй изначально выставить border, цвет которого совпадает с цветом фона элемента.

3
  • Этот вариант решает вопрос. Но я думаю должен быть еще способ что бы не прописывать два свойства border.
    – Артур
    19 июн 2020 в 8:01
  • @Артур, есть - костыли. Проще и ничего страшного - прописать два свойства бордер. Или так .el {border: 1px solid transparent;} .el:hover {border-color: red;}
    – De.Minov
    19 июн 2020 в 8:34
  • А лучше наверное сделать как в этом решении, по крайней мере вариант интересный: ru.stackoverflow.com/questions/858409/…
    – jared dan
    19 июн 2020 в 8:38

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.