0

Текст вылезает за рамки кнопки, помогите исправить пожалуйста

* {
  margin: 0px;
  padding: 0px;
}

body{
    display: flex;
    justify-content: center;
}

.image_box{
    margin-top: 10%;
    display: flex;
}

.images{
    height: 450px;
}

.previous{
    margin-right: 20px;
}

.next{
    margin-left: 20px;
}

button{
    height: 20px;
    margin-top: 25%;
    background-color: white;
    font-weight: bold;
    font-size: 25pt;
    border-radius: 100%;
}
<!DOCTYPE html>

<html>

    <head>
        <title>IMG Changer</title>
        <link rel="stylesheet" href="styles.css">
    </head>

    <body>
        <div class="image_box">
            <button class="previous">&#60;</button> <!-- Кнопка слева --> 

            <img src="images/img1.jpg" class="images" alt="Тут должна быть картинка"> <!-- Картинка -->

            <button class="next">&#62;</button> <!-- Кнопка справа --> 
        </div>

        <script src="script.js"></script>
    </body>

</html>

3 ответа 3

3

Старайтесь явно указывать высоту и ширину элементов:

* { margin: 0; padding: 0; }

body { display: flex; justify-content: center; }

.image_box { margin-top: 10%; display: flex; }

.images { height: 450px; }

.previous { margin-right: 20px; }

.next { margin-left: 20px; }

button {
  margin-top: 25%;
  height: 25px;
  width: 25px;
  border-radius: 50%;
  font-weight: bold;
  font-size: 20px;
  line-height: 25px;
  text-align: center;
  background-color: white;
}
<div class="image_box">
  <!-- Кнопка слева -->
  <button class="previous">&#60;</button>
  <!-- Картинка -->
  <img src="images/img1.jpg" class="images" alt="Тут должна быть картинка">
  <!-- Кнопка справа -->
  <button class="next">&#62;</button>
</div>

1

* { margin: 0px; padding: 0px; }
body { display: flex; justify-content: center; }

.image_box { margin-top: 10%; display: flex; }
.images { height: 450px; }
.previous { margin-right: 20px;}
.next { margin-left: 20px; padding-left: 0.05em; }

button {
  width: 1em; height: 1em;
  margin-top: 25%;
  padding: 0;
  font: bold 25pt/0.85 sans-serif; 
  border-radius: 50%;
  background-color: white;
}
<div class="image_box">
  <button class="previous">&#60;</button>
  <img src="images/img1.jpg" class="images" alt="Тут должна быть картинка">
  <button class="next">&#62;</button>
</div>

  • width и height для фиксации размеров кнопок по кеглю их шрифта
  • пониженный line-height (и небольшой padding-right у правой кнопки) для учета особенностей метрик символов < и >
  • исправлен border-radius

Написано/проверено с планшетника - если в десктопных браузерах отображается некорректно из-за различий шрифтов, советую попробовать другой подход: разместить содержимое кнопок в псевдоэлементах, и центрировать их обеим осям через популярный прием с relative>absolute и transform: translate.

1

* {
  margin: 0px;
  padding: 0px;
}

body {
  display: flex;
  justify-content: center;
}

.image_box {
  margin-top: 10%;
  display: flex;
  align-items: center;
  border: 1px dashed purple;
}

.images {
  height: 450px;
}

.previous {
  margin-right: 20px;
}

.next {
  margin-left: 20px;
}

button {
  width: 40px;
  height: 40px;
  background-color: white;
  font-weight: bold;
  font-size: 25pt;
  border-radius: 100%;
}
<div class="image_box">
  <button class="previous">&#60;</button>
  <img src="https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg" class="images" alt="Тут должна быть картинка">
  <button class="next">&#62;</button>
</div>

Ваш ответ

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

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