Создание градиентов - PullRequest
0 голосов
/ 20 мая 2018

У меня есть изображение .hero, которое я хотел бы занять на 100% от области просмотра, оставаясь отзывчивым на небольших устройствах.Тем не менее, изображение на самом деле обрезается, когда оно в мобильном представлении.Что еще хуже, по какой-то причине мой текст не центрирован по центру изображения .hero.Мне просто нужна была помощь с этими двумя вещами.Я работал над этим в течение часа безрезультатно.Спасибо

  * {
  box-sizing: border-box;
}

body,
html {
  margin: 0;
  width: 100%;
}

header {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  display: block;
  margin-top: -10px: width: 100%;
  border-radius: 5px;
  background-color: white;
  border-color: black;
  height: 30%;
  padding-right: 0px;
}

.hero {
  display: flex;
  height: 100vh;
  width: 100%;
  background: rgba(76, 76, 76, 1);
  background: url(https://images.pexels.com/photos/7094/wood-coffee-laptop-hero-7094.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940);
  background-size: auto;
  background-repeat: no-repeat;
  background-position: center;
  padding-bottom: 20px;
}

nav {
  display: block;
}

nav li {
  font-weight: 700;
  list-style-type: none;
  text-align: center;
  font-size: 25px;
  font-weight: bold;
  font-family: Roboto, sans-serif;
}

li {
  border-top: grey solid 1px;
}

nav a {
  text-decoration: none;
  color: grey;
  display: inline-block;
  line-height: 45px;
}

li:nth-child(1) {
  border-top: none;
  padding-bottom: 10px;
  margin: 0px;
}

li:nth-child(2) {
  padding-top: 10px;
  margin: 0px;
}

li:nth-child(3) {
  margin: 0px;
  padding-top: 10px;
}

li:nth-child(4) {
  margin: 0px;
  padding-top: 10px;
}

.container {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: space-between;
  font-family: Roboto, sans-serif;
  line-height: 1.6;
}

.side1 {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  width: 100%;
  background: white;
  border-color: black;
  text-align: center;
  margin-bottom: 10px;
}

.main-content {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  width: 100%;
  background: white;
  border-color: black;
  text-align: center;
  margin-bottom: 10px;
}

.side2 {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  width: 100%;
  background: white;
  border-color: black;
  text-align: center;
  margin-bottom: 10px;
}

@media screen and (min-width: 726px) {
  @media screen and (min-width: 900px) {
    .header {
      display:flex;
    }
    header {
      -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
      -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
      box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
      width: 100%;
      align-items: center;
      border-radius: 5px;
      background-color: white;
      border-color: black;
      height: 30%;
      padding: 10px;
    }
    nav {
      display: flex;
      flex-direction: row;
      justify-content: space-around;
    }
    li:nth-child(1) {
      border-top: grey solid 1px;
      padding-top: 10px;
      margin: 0px;
    }
    .container {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-around;
      flex-wrap: wrap;
    }
    .hero {
      margin-bottom: 3%;
      width: 100%;
    }
    .main-content {
      border-left: lightgrey 1px solid;
      border-right: lightgrey 1px solid;
      width: 33.3%;
    }
    .side1 {
      width: 30%;
    }
    .side2 {
      width: 30%;
    }
  }
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title></title>
  <link rel="stylesheet" href="styles.css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:300i" rel="stylesheet">


</head>

<body>
  <header>
    <nav>
      <li><a href="#"> Home</a></li>
      <li><a href="#"> Heading1</a></li>
      <li><a href="#"> Heading2</a></li>
      <li><a href="#"> Heading3</a></li>
    </nav>
  </header>

  <div class="hero">
    <div class="text">
      <h1>Anna Gibson</h1>
      <h2>Web Dev. Writer. Thinker</h2>
    </div>
  </div>


  <div class="container">
    <div class="side1">
      <h2>Column 1</h2>
      <p>
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
        in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </div>

    <div class="main-content">
      <h2>Main-content</h2>
      <p>
        "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human
        happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves
        or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical
        exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
      </p>
    </div>

    <div class="side2">
      <h2>Column 2</h2>
      <p>
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
        in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </div>
  </div>
</body>

</html>

Ответы [ 2 ]

0 голосов
/ 21 мая 2018

Так вот что я и сделал.(Я опубликую только то, что имеет отношение к рассматриваемому вопросу.)

Это HTML ...

 <div class="hero">
    <div class="text">
      <h1>Anna Gibson</h1>
      <h2>Web Dev. Writer. Thinker.</h2>
    </div>
  </div>

Это CSS ...

hero {
   height: 100vh;
  width: 100%;
  filter:brightness(20%);
background:
 url(https://images.pexels.com/photos/7094/wood-coffee-laptop-hero-7094.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940);
    position:relative;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    padding-bottom: 20px;
    text-align: center;
    z-index:-1;
}

.text {
  flex-wrap: wrap;
  width: 100%;
  height: 100vh;
  align-self: : center;
  padding-top: 200px;
  color: white;
  line-height: 50px;
  font-size: 30px;
  font-family: Oswald, serif;
}

Чтобы отцентрировать текст, я просто поместил центр 'align-self' и добавил 20 пикселей отступа к верхней части контейнера и ширину 100%, чтобы он постоянно оставался в центре.контейнер героя.

0 голосов
/ 20 мая 2018

Ты этого хочешь?

Я центрировал текст по вертикали и по горизонтали.

Что касается изображения в режиме альбомной ориентации, вы используете полную высоту экрана в альбомной ориентации.

Такна мобильном экране, который находится в портретном режиме, изображение будет пытаться занять всю высоту экрана, что приведет к отсечению изображения

* {
  box-sizing: border-box;
}

body,
html {
  margin: 0;
  width: 100%;
}

header {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  display: block;
  margin-top: -10px: width: 100%;
  border-radius: 5px;
  background-color: white;
  border-color: black;
  height: 30%;
  padding-right: 0px;
}

.hero {
  display: flex;
  height: 100vh;
  width: 100%;
  background: rgba(76, 76, 76, 1);
  background: url(https://images.pexels.com/photos/7094/wood-coffee-laptop-hero-7094.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940);
  background-size: auto;
  background-repeat: no-repeat;
  background-position: center;
  padding-bottom: 20px;
}

nav {
  display: block;
}

nav li {
  font-weight: 700;
  list-style-type: none;
  text-align: center;
  font-size: 25px;
  font-weight: bold;
  font-family: Roboto, sans-serif;
}

li {
  border-top: grey solid 1px;
}

nav a {
  text-decoration: none;
  color: grey;
  display: inline-block;
  line-height: 45px;
}

li:nth-child(1) {
  border-top: none;
  padding-bottom: 10px;
  margin: 0px;
}

li:nth-child(2) {
  padding-top: 10px;
  margin: 0px;
}

li:nth-child(3) {
  margin: 0px;
  padding-top: 10px;
}

li:nth-child(4) {
  margin: 0px;
  padding-top: 10px;
}

.container {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: space-between;
  font-family: Roboto, sans-serif;
  line-height: 1.6;
}

.side1 {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  width: 100%;
  background: white;
  border-color: black;
  text-align: center;
  margin-bottom: 10px;
}

.main-content {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  width: 100%;
  background: white;
  border-color: black;
  text-align: center;
  margin-bottom: 10px;
}

.side2 {
  -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
  width: 100%;
  background: white;
  border-color: black;
  text-align: center;
  margin-bottom: 10px;
}

@media screen and (min-width: 726px) {
  @media screen and (min-width: 900px) {
    .header {
      display:flex;
    }
    header {
      -webkit-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
      -moz-box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
      box-shadow: -1px 2px 17px 0px rgba(0, 0, 0, 0.75);
      width: 100%;
      align-items: center;
      border-radius: 5px;
      background-color: white;
      border-color: black;
      height: 30%;
      padding: 10px;
    }
    nav {
      display: flex;
      flex-direction: row;
      justify-content: space-around;
    }
    li:nth-child(1) {
      border-top: grey solid 1px;
      padding-top: 10px;
      margin: 0px;
    }
    .container {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-around;
      flex-wrap: wrap;
    }
    .hero {
      margin-bottom: 3%;
      width: 100%;
    }
    .main-content {
      border-left: lightgrey 1px solid;
      border-right: lightgrey 1px solid;
      width: 33.3%;
    }
    .side1 {
      width: 30%;
    }
    .side2 {
      width: 30%;
    }
  }
}

.text {
  width: 100%;
  overflow: hidden;
  text-align: center;
  align-self: center;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title></title>
  <link rel="stylesheet" href="styles.css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:300i" rel="stylesheet">


</head>

<body>
  <header>
    <nav>
      <li><a href="#"> Home</a></li>
      <li><a href="#"> Heading1</a></li>
      <li><a href="#"> Heading2</a></li>
      <li><a href="#"> Heading3</a></li>
    </nav>
  </header>

  <div class="hero">
    <div class="text">
      <h1>Anna Gibson</h1>
      <h2>Web Dev. Writer. Thinker</h2>
    </div>
  </div>


  <div class="container">
    <div class="side1">
      <h2>Column 1</h2>
      <p>
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
        in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </div>

    <div class="main-content">
      <h2>Main-content</h2>
      <p>
        "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human
        happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves
        or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical
        exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
      </p>
    </div>

    <div class="side2">
      <h2>Column 2</h2>
      <p>
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
        in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </div>
  </div>
</body>

</html>
...