如何在引导程序中的div内部居中

时间:2019-02-16 20:13:51

标签: jquery html css bootstrap-4

我创建了一些卡片,其中文本位于this:等图标旁边的行内居中

现在很久以后,我被告知我必须将引导程序导入到项目中并重新设计所有内容,但是通过导入bs,它已使所有卡的对齐方式脱离了。现在,我正在展示它们并展示内容的内容,但这似乎并没有太大帮助。 here is a codepen snippet of what I have. `

#slider,
.wrap,
.slide-content {
  margin: 0;
  padding: 0;
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
  height: 100%;
}

.wrap {
  position: relative;
  grid-row-start: 1;
  grid-row-end: 5;
}

.slide {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  height: 100%;
}

.slide1 {
  background-image: url("pics/purple_jerseys.jpg");
}
.slide2 {
  background-image: url("pics/soccer_boys.jpg");
}
.slide3 {
  background-image: url("pics/soccer girl.jpg");
}

.slide-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.slide-content span {
  font-size: 4rem;
  color: #fff;
  position: absolute;
  top: 8px;
  right: 45px;
  left: 8px;
  text-shadow: 2px 2px 4px #000000;
}

.arrow {
  cursor: pointer;
  position: absolute;
  top: 50%;
  margin-top: -35px;
  width: 0;
  height: 0;
  border-style: solid;
}

#arrow-left {
  border-width: 30px 40px 30px 0;
  border-color: transparent #fff transparent transparent;
  left: 0;
  margin-left: 30px;
}

#arrow-right {
  border-width: 30px 0 30px 40px;
  border-color: transparent transparent transparent #fff;
  right: 0;
  margin-right: 30px;
}

.container {
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-template-rows: repeat(5, 20%);
  grid-gap: 1em;
  margin-top: 1em;
  margin-right: 1em;
  margin-left: 1em;

}

.footer {
  border: 2px solid #FFBB3F;
  background-color: white;
}

.card-container {
  display: grid;
  grid-gap: 20px;
}

.card {
  display: flex;
  flex-wrap: wrap;
  border: 2px solid #FFBB3F;
  background: white;
  color: black;
  justify-content: center;
}
.card h1 {
  width: 100%;
  font-size: 1rem;
  text-transform: uppercase;
  text-align: center;
  background-color: #002664;
  color: #FFBB3F;
  margin-top: 0px;
}

.ref-icon {
  height: 23px;
  color: #FFBB3F;
  margin-top: 4px;
}

.card p {
  width: 80%;
}

.card img {
  margin: auto;
}

.card * {
  margin-top: 0;
}

.socials {
  display: flex;
  justify-content: space-between;
  margin: 7px;
  padding: 7px;

}

.donate-button {
  font-size: 20px;
  background-color: #002664;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  margin: 4px 2px;
  cursor: pointer;
}

.donate-button:hover {
  box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}

.fa fa-facebook-official:hover {
  box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}

.fa fa-facebook-official {
  color: #002664;
}
<head> <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link rel="stylesheet" href="styles.css" class="">
  <link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"></head>

<div class="container">
  <div class="wrap">
    <div id="arrow-left" class="arrow"></div>
    <div id="slider">
      <div class="slide slide1">
        <div class="slide-content">
          <span>VOLUNTEER: BECOME A COACH</span>
        </div>
      </div>
      <div class="slide slide2">
        <div class="slide-content">
          <span>VOLUNTEER: BECOME A COACH</span>
        </div>
      </div>
      <div class="slide slide3">
        <div class="slide-content">
          <span>VOLUNTEER: BECOME A COACH</span>
        </div>
      </div>
    </div>
    <div id="arrow-right" class="arrow"></div>
  </div>
<div class="card-container">
    <div class="card">
        <h1>Spring Registration Open</h1>
        <i class="fa fa-pencil-square-o fa-3x" aria-hidden="true"></i>
      <p>Core registration for Spring 2019 is now open. <a href="#">Register here</a></p>
    </div>
    <div class="card">
      <h1>CORE WINTER SCHEDULE</h1>
      <i class="fa fa-list-ol fa-3x" aria-hidden="true"></i>
      <p>Core winter schedule has been published and is available <a href="#">here</a></p>
    </div>
    <div class="card">
      <h1>BECOME A COACH/REFEREE</h1>
      <img src="pics/whistle.svg" height="40px">
      <p>Registration for the youth winter referee course is now open. <a href="#">Register here</a></p>
    </div>
    <div class="card">
      <h1>FIELD STATUS</h1>
      <i class="fa fa-sun-o fa-3x" aria-hidden="true"></i>
      <p>Winter Mon, Wed, Sat DA sessions have openings <a href="#">Register here</a></p>
    </div>

    <div class="socials">
      <button class="donate-button ">DONATE</button>
      <a href="#"><i class="fa fa-facebook-official fa-4x" aria-hidden="true"></i></a>
      <a href="#"><i class="fa fa-instagram fa-4x" aria-hidden="true"></i></a>
    </div>
  </div>
</div>
<script src="https://use.fontawesome.com/3ddfd35ac9.js"></script>
<script>
let sliderImages = document.querySelectorAll(".slide"),
  arrowLeft = document.querySelector("#arrow-left"),
  arrowRight = document.querySelector("#arrow-right"),
  current = 0;

// Clear all images
function reset() {
  for (let i = 0; i < sliderImages.length; i++) {
    sliderImages[i].style.display = "none";
  }
}

// Init slider
function startSlide() {
  reset();
  sliderImages[0].style.display = "block";
}

// Show prev
function slideLeft() {
  reset();
  sliderImages[current - 1].style.display = "block";
  current--;
}

// Show next
function slideRight() {
  reset();
  sliderImages[current + 1].style.display = "block";
  current++;
}

// Left arrow click
arrowLeft.addEventListener("click", function() {
  if (current === 0) {
    current = sliderImages.length;
  }
  slideLeft();
});

// Right arrow click
arrowRight.addEventListener("click", function() {
  if (current === sliderImages.length - 1) {
    current = -1;
  }
  slideRight();
});

startSlide();

</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

`非常简单,我只需要帮助正确对齐内容即可。

2 个答案:

答案 0 :(得分:0)

你可以试试这个吗..

 <div class="card">
         <h1>Spring Registration Open</h1>
         <div class="flx">
            <div> 
               <i class="fa fa-pencil-square-o fa-3x" aria-hidden="true"></i>
            </div>
            <div>
               <p>Core registration for Spring 2019 is now open. <a href="#">Register here</a></p>
            </div>
         </div>
      </div>

和CSS

.flx {
    display: flex;
    align-items: center;
}

.flx>div {
    padding: 1rem;
}

答案 1 :(得分:0)

使用Grid系统的Bootstrap,在这里我们定义了两列,第一列为col-lg-2,第二列为col-lg-10

enter image description here

  <div class='row'>
      <h1>CORE WINTER SCHEDULE</h1>
       <div class='col-lg-2'>
           <i class="fa fa-list-ol fa-3x" aria-hidden="true"></i>
       </div>
       <div class='col-lg-10'>
           <p>Lorem Ipsum</p>
       </div>
  </div>

codepen中检查