For the past two days, I have been struggling to responsively position some HTML elements. The effect I am aiming for is similar to what can be seen on this site before the stacking occurs in the Field Service Management and Intelligent Route Planning & Fleet Management sections:
Both of these sections consist of two parts - an image with a fixed pixel length that shrinks at different breakpoints, and on the other side, an h1, p, and button element that should stay in the same position as the image shrinks. I attempted to achieve this by using absolute positioning for the elements together, but encountered issues with margins pushing the elements down too far.
How can I ensure that the HTML elements (h1, p, and button) remain unaffected when the image size decreases based on media queries? Any help would be greatly appreciated.
The current code I am working with is:
.btn-primary {
background-color: #de6426 !important;
border-color: #de6426 !important;
color: #fff;
}
.btn-primary:hover {
background-color: hsla(20, 74%, 41%, 1) !important;
border-color: hsla(20, 74%, 41%, 1) !important;
color: #fff;
}
.btn-primary.focus, .btn-primary:focus {
background-color: hsla(20, 74%, 41%, 1) !important;
border-color: hsla(20, 74%, 41%, 1) !important;
color: #fff;
}
body {
margin: 0;
}
.container {
display: flex;
flex-direction: row;
}
@media screen and (max-width: 792px) {
.container {
display: flex;
flex-direction: column;
}
}
.fleet {
width: 400px;
}
.items-wrapper {
display: flex;
background-color: #0f2c4d;
}
.items {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
margin-left: 50px;
min-width: 390px;
max-width: 500px;
}
h1 {
margin: 0;
color: #008ad1;
}
p {
color: white;
margin-left: 6rem;
margin-right: 6rem;
}
.btn {
height: 30px;
width: 80px;
}
h1 {
font-family: Carnas-Light;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="./css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./css/style.css">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="items-wrapper">
<div class="items">
<h1>Intelligent Route Planning & Fleet Management</h1>
<p>Improve efficiency and scalability of fleet operations through dynamic planning, intelligent route optimization and more.</p>
<button type="button" class="btn btn-primary">Button</button>
</div>
</div>
<img class="fleet" src="https://i.imgur.com/UakU07V.png" alt="Mountain View">
</div>
</body>
</html>