Home > OS >  Responsinvess and positioning text inside div
Responsinvess and positioning text inside div

Time:09-19

I'm trying to achieve something like this:

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

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 >
    <h1 th:text="${randomSummerCamp.title}"></h1>
    <h1 th:text="${randomSummerCamp.state}"></h1>
  </div>
  <div >
    <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

CodePudding user response:

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;
}

CodePudding user response:

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 >
Text under heading
</h4>
</h1>

<div >
  <div >
    <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 >
   <img src="https://source.unsplash.com/featured/300x201">
   <div >
     <button>
     Click
     </button>
     <button>
     Click
     </button>
   </div>
  </div>
</div>

  • Related