I’m new to front end development, so please don’t insult me if it’s a very stupid question.
I have a set a 2 color background with the color red taking 2/3 of the screen, and the yellow taking the remaining 1/3.
Now i need to place an image, that is inside a div, beetween the two colors of the background, half image in red and half image in yellow, how do i do it?Like this
HTML:
<body>
<header>
<div class="logo-name">
<img class="logo" src="img/burger.svg">
<h1 class="name">Burger</h1>
</div>
<nav class="navbar">
<ul class="nav-links">
<li><a href="#">Home</a></li>
<li><a href="#">Menu</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contacts</a></li>
</ul>
</nav>
<button class="btn"><a href="#">Book A Table</a></button>
</header>
<main>
<div class="left">
<h1 class="left-title">Savor <span style="color: #ffac0c;">Every</span> Bite</h1>
<p class="left-description">Welcome to our burger haven, where every burger is more than a meal, they're a culinary adventure waiting to be savored.</p>
</div>
<div class="right">
<img class="burgerimg" src="img/burgerimg.webp">
</div>
</main>
</body>
CSS :
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Montserrat;
text-decoration: none;
color: inherit;
}
body {
background: linear-gradient(
to right,
#801404 0%,
#801404 70%,
#ffac0c 30%,
#ffac0c 100%
);
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 50px 10%;
height: 80px;
}
.nav-links li {
color: white;
text-transform: uppercase;
font-weight:700;
display: inline-block;
list-style: none;
padding: 0 20px;
font-size: 2rem;
}
.logo-name {
display: inline-flex;
}
.logo {
width: 40px;
height: auto;
margin: 0 20px;
filter: invert(99%) sepia(8%) saturate(808%) hue-rotate(172deg) brightness(122%) contrast(100%);
}
.name {
font-size: 3rem;
font-weight: 700;
color: white;
line-height: 80px;
}
.btn {
padding: 15px 20px;
background-color: #801404;
color: white;
text-transform: uppercase;
border: none;
border-radius: 50px;
font-weight: 700;
}
main {
display: flex;
justify-content: space-between;
align-items: center;
}
.left {
position: relative;
left: 10%;
margin: 12.5% 0;
}
.right {
margin: 0 18%;
}
.left-title {
font-size: 8rem;
color: white;
}
.left-description{
font-size: 3rem;
color: white;
}
.burgerimg {
width: 400px;
}
I tried using margin and padding with %, but the image (burger) changes position when resizing the window.
2
Answers
hello im also a new developer so please don’t insult me if it’s a very stupid answer but did you try:
I would recommend, that you use absolute positioning for you image. Get rid of the two column approach and just keep a wrapper around your text to set a width so it does not run into the yellow color. For the image itself, use:
I have simplified your example and removed the header, so the actual solutions becomes clearer.