N
N
Nikolai Dobrynin2018-09-26 02:37:47
css
Nikolai Dobrynin, 2018-09-26 02:37:47

How to center the text on the slider in the center so that it does not move when the scale changes?

There is a slider:

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">
    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
  </ol>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src="img/mainscrin.jpg" alt="First slide">
      <div class="container slmax">
      <div class="carousel-caption d-none d-md-block">
        <div class="container slmax">
          <div class="row">
            <div class="col-md-5 text1">
              <h2>Заголовок<br>
                  Заголовок<br>
                  Заголовок</h2>
           </div>
           <div class="col-md-5 offset-md-2 text2"> 
              <p>текст текст текст текст текст текст текст <br>
                текст текст текст текст текст текст текст текст </p>
          <button class="btn pf1" type="submit">Кнопка Кнопка Кнопка </button>
          </div>
         </div>
        </div>
      </div>
    </div>
  </div>
</div>

and its css
.slmax {
    
    max-width: 1180px!important;
    padding: 0!important;
    margin: 0!important;
}
.text1 {
    padding: 0!important;
    text-align: left;
}
.text1 h2{
  font-family: "RobotoLight";
  font-size: 59px;  
}
.text2 {
    padding: 0!important;
    text-align: left;
    }
    .text2 p{
  font-family: "RobotoLight";
  font-size: 20px;  
}

.pf1 {
    width: 310px;
    height: 55px;
    font-size: 20px;
    background: #233f8a;
    color: #fff;
    border-radius: 10px;
    font-family: "RobotoLight";
}

When you change the scale of the page, the text slides down and to the left. Is it possible to somehow fix it exactly in the center so that it would remain there anyway? And is there any way to make the height of the slider fixed and not adaptive?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-09-26
@Stalker_RED

left: 50%; top: 50%;- we drive the left-upper corner to the center.
transform: translate(-50%, -50%);- shift to the left-higher so that not the corner is in the center, but the center of the block.
jsfiddle.net/nhm2scu4/show
(try resizing the window)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question