Перемещение изображений с относительным расположением - PullRequest
0 голосов
/ 15 ноября 2018

У меня есть веб-страница, где у меня есть родительский div с относительным позиционированием и весь текст с абсолютным позиционированием.Теперь я заметил, что вообще не могу передвигаться по изображению.Что я должен делать?http://jsfiddle.net/uchn0m5k/1/ Редактировать: я хочу, чтобы изображение было позади (с точки зрения пространства Z) текста, но, поскольку я хочу добавить больше изображений, я не хочу устанавливать его в качестве фонового изображения:)

html:

<div class="container">
  <img id="squiggle" src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"  style=" height:30%;">

  <div class="top-left">
    <h1>Lorem Ipsum.</h1>
    <a class="button"href="#">Button to clcik</a>
  </div>
</div>

css:

.button {
    background-color: #08aabe;
    border: none;
    color: #faead3;
    padding: 0.2em 0.65em;
    text-decoration: none;
    font-size: 2.3vw;
    margin-left: 5em;
    letter-spacing: 0.02em;
    -webkit-transition: 0.3s;
    -moz-transition: 0.3s;
    -o-transition: 0.3s;
    transition: 0.3s;
  }

img{
  max-width: 100%;
  user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-drag: none;
-webkit-user-select: none;
-ms-user-select: none;
}

.container {
    position: relative;
    height:100vh;
}



/* Top left text */
.top-left {
    position: absolute;
    top: 8px;
    left: 16px;
}

.top-left h1{
  margin:0px;
  font-size: 4.5vw;
  color: #08aabe;
  margin-left: 2.5em;
  padding-top: 3em;
  padding-bottom: 0.2em;

}

body{
  margin: 0px;
  font-family: sans-serif;
  background-color:black;

}

#squiggle{
  right: 30vw;
}

Любая помощь будет оценена.Спасибо

Ответы [ 3 ]

0 голосов
/ 15 ноября 2018

Вы пытались сделать так?

.button {
    background-color: #08aabe;
    border: none;
    color: #faead3;
    padding: 0.2em 0.65em;
    text-decoration: none;
    font-size: 2.3vw;
    margin-left: 2em;
    letter-spacing: 0.02em;
    -webkit-transition: 0.3s;
    -moz-transition: 0.3s;
    -o-transition: 0.3s;
    transition: 0.3s;
  }

img{
  max-width: 100%;
  user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-drag: none;
-webkit-user-select: none;
-ms-user-select: none;
}

.container {
    position: relative;
    height:100vh;
}



/* Top left text */
.top-left {
    position: absolute;
    top: 8px;
    left: 16px;
}

.top-left h1{
  margin:0px;
  font-size: 4.5vw;
  color: #08aabe;
  margin-left: 1em;
  padding-top: 1em;
  padding-bottom: 0.2em;

}

body{
  margin: 0px;
  font-family: sans-serif;
  background-color:black;

}

#squiggle{
  position:absolute;
  left: 22vw;
  top: 29px;
}

.container{
  position:relative;
}
<div class="container">
  <img id="squiggle" src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"  style=" height:30%;">

  <div class="top-left">
    <h1>Lorem Ipsum.</h1>
    <a class="button"href="#">Button to clcik</a>
  </div>
</div>
0 голосов
/ 15 ноября 2018

Итак, я думаю это то, что вы просите?Я переключил CSS и в основном добавил z-index для элементов «container», «img» и «top-left», которые переместили изображение кубика за контейнером «top-left».

img{
    max-width: 100%;
    position: absolute;
    z-index: -2;
    top: 120px;
    left: 40px;
    user-drag: none;
    user-select: none;
    -moz-user-select: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

.container {
    position: relative;
    height:100vh;
    z-index: -3;
}



/* Top left text */
.top-left {
    position: absolute;
    top: 8px;
    left: 16px;
    z-index: -1;
}

Надеюсь, это ответит на ваш вопрос.Если нет, пожалуйста, дайте мне знать, и я буду рад попытаться найти лучшее решение!

0 голосов
/ 15 ноября 2018

Обновленный ответ:

Вы можете просмотреть это codepen .

body {
  background: black;
  font-family: sans-serif;
}

.logo {
  position: absolute;
  top: 5em;
  left: 5em;
  z-index: -1;
}

.logo-text {
  position: absolute;
  top: 4em;
  left: 4em;
  z-index: 1;
}

h1.logo-text {
  color: #fff;
}
<div class="container">
  <div class="logo">
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png">
  </div>
  <h1 class="logo-text">Lorem Ipsum</h1>  
</div>
...