Responsinvess and positioning text inside div

Viewed 30

I'm trying to achieve something like this:

https://www.figma.com/file/lqy0NTOiakaxeG5HoJk50f/Untitled?node-id=0%3A1

body {
  margin: 0;
  background-color: #242038;
}

.header {
  color: white;
  position: center;
  text-align: center;
  font-size: 12px;
  margin: auto;
  width: 50%;
  padding: 10px;
  font-family: 'Inter', serif;
  font-weight: bold;
}

.description {
  position: absolute;
  left: 20%;
  top: 30%;
  height: 150px;
  transform: translate(-50%, -50%);
  border: 5px solid #FFFF00;
  padding: 10px;
}

.title button {}

img {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}
<tr th:each="randomSummerCamp:${randomSummerCamps}">
  <div class="header">
    <h1 th:text="${randomSummerCamp.title}"></h1>
    <h1 th:text="${randomSummerCamp.state}"></h1>
  </div>
  <div class="description">
    <p th:text="${randomSummerCamp.description}"></p>
  </div>
  <img alt="" th:src="*{'data:image/jpeg;base64,'+{randomSummerCamp.image}}" style="align-content: center" src="">
  <button type="button" onclick="document.location.href = '/adventureHolidays/getRandomSummerCamps'">Randomize
        again!
    </button>
</tr>

That is how I tried so far, but my text inside div is not responsive and its always over image or not positioined well

2 Answers

Maybe you can try viewport width measuring unit.

vw

.header {
    color: white;
    position: center;
    text-align: center;
    font-size: 12vw;
    margin: auto;
    width: 50%;
    padding: 10px;
    font-family: 'Inter', serif;
    font-weight: bold;
}

.description {
    font-size: 5vw
    position: absolute;
    left: 20%;
    top: 30%;
    height: 150px;
    transform: translate(-50%, -50%);
    border: 5px solid #FFFF00;
    padding: 10px;
}

This is a good start for you. Look at display:flex, because it aligns items horizontally, and it helps a lot. Also, i put width: 50% for items, but if you do it with Bootstrap framework for frontend, it has all that classes for responsive etc.

body{
  text-align: center;
}
.margin-top-none{
  margin-top: -1rem;
}
.row-flex{
  display: flex;
}
.left-side{
  width: 50%;
}
.right-side{
  width: 50%;
}
<h1>
Heading
<h4 class="margin-top-none">
Text under heading
</h4>
</h1>

<div class="row-flex">
  <div class="left-side">
    <p>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
  </div>
  <div class="right-side">
   <img src="https://source.unsplash.com/featured/300x201">
   <div class="row-flex">
     <button>
     Click
     </button>
     <button>
     Click
     </button>
   </div>
  </div>
</div>

Related