Two child DIVs within a single parent DIV

I am struggling to keep two divs side-by-side within a parent div. Initially, I was able to position the image in the right div successfully, but when resizing the elements, everything became disorganized and I can't seem to fix it. As a beginner, I would appreciate if you could provide a simple solution.

div.surf2
{
position:absolute;
background: #41c3ac;
height: 600px;
}

div.surfleft
{
display: inline-block;
width: 45%;
padding-top: 80px;
padding-left: 20px;
height: 600px;
}

div.surf2right
{
display: inline-block;
height: 600px;
width: 55%;
}
<div class="surf2">
    <div class="surfleft">
    <p class="title1">Interactive games</p>
        <ul style="font-size: 1.5em">
        <li>We offer various games for you to enjoy, including object recognition exercises, multiple-choice quizzes, and error-spotting challenges.</li>
            <li>These games are designed to make learning English engaging and rewarding.</li>   
          </ul>
    </div>
    <div class="surf2right">
    <img src="console.png">
    </div>
</div>

Answer №1

The inline-block property always creates a space. You can either utilize float: left; or eliminate the space:

div.surf2 {
  position: absolute;
  background: #41c3ac;
  height: 600px;
}
div.surfleft {
  display: inline-block;
  width: 45%;
  padding-top: 80px;
  height: 600px;
}
div.surf2right {
  display: inline-block;
  height: 600px;
  width: 55%;
}
<div class="surf2">
  <div class="surfleft">
    <p class="title1">Interactive games</p>
    <ul style="font-size: 1.5em">
      <li>Explore various game types such as object recognition, multiple-choice exercises, and spot-the-mistake challenges.</li>
      <li>These games are designed to make learning and practicing English enjoyable yet challenging.</li>
    </ul>
  </div><<!--
  --><div class="surf2right">
    <img src="console.png">
  </div>
</div>

Also, consider eliminating the padding-left or using box-sizing: border-box.

div.surf2 {
  position: absolute;
  background: #41c3ac;
  height: 600px;
}
div.surfleft {
  display: inline-block;
  width: 45%;
  padding-top: 80px;
  height: 600px;
  padding-left: 20px;
  box-sizing: border-box;
}
div.surf2right {
  display: inline-block;
  height: 600px;
  width: 55%;
}
<div class="surf2">
  <div class="surfleft">
    <p class="title1">Interactive games</p>
    <ul style="font-size: 1.5em">
      <li>Explore various game types such as object recognition, multiple-choice exercises, and spot-the-mistake challenges.</li>
      <li>These games are designed to make learning and practicing English enjoyable yet challenging.</li>
    </ul>
  </div><<!--
  --><div class="surf2right">
    <img src="console.png">
  </div>
</div>

Answer №2

<html>
<head>
<style type="text/css">
#content {

width: 980px;
height: 500px;
padding: 20 20 20 20;
background-color: #00fcff }
#package_update {

width: 680;
height: 500;
float: left;
background-color: #aaaaaa }
#previous_update {

width: 280;
height: 500;
float: right;
background-color: #ffcc00 }
</style>
</head>
<body>
<div id="content">

<div id="package_update"></div>
<div id="previous_update"></div>

</div>
</body>
</html>

Answer №3

To fix the issue of the div going over 100%, remove the padding-left property and add float: left to both divs. You can also consider removing the display: inline-block property.

div.surf2
{
position:absolute;
background: #41c3ac;
height: 600px;
}

div.surfleft
{
width: 45%;
padding-top: 80px;
height: 600px;
}

div.surf2right
{
height: 600px;
width: 55%;
}

div.surf2right, div.surfleft {
    float: left;
}
<div class="surf2">
    <div class="surfleft">
    <p class="title1">Interractive games</p>
        <ul style="font-size: 1.5em">
        <li>We have different types of games you can play, testing your abilities to recognise objects, multiple choice exercises and also putting you to the test of spotting mistakes.</li>
            <li>Those games are designed to help you learn and practice English combining fun with hard work.</li>   
          </ul>
    </div>
    <div class="surf2right">
    <img src="console.png">
    </div>
</div>

Answer №4

Give this a shot:

.surf2 {
    width: fit-content;
    position:absolute;
    background: #41c3ac;
    height: 600px;
}


.surf2 div.surfleft {
    float:left;
    display: block;
    width: 45%;
    padding-top: 80px;
    height: 600px;
 }

.surf2 div.surfright {
    float:right;
 }

 <div class="surf2">
    <div class="surfleft">
        <p class="title1">Interactive games</p>
         <ul style="font-size: 1.5em">
            <li>Explore various types of games that challenge your object recognition, test your multiple-choice skills, and assess your ability to spot errors.</li>
            <li>These games are designed to help you enhance your English proficiency through an engaging learning experience.</li>   
          </ul>
    </div>
    <div class="surf2right">
    <img src="console.png">
    </div>
</div>

The use of width: fit-content will adjust the div's width based on the content inside it

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can we ensure that pointer events return the same coordinates as touch events when the viewport is zoomed in?

I attempted to utilize pointer events (such as pointerdown) instead of using a combination of touch events (e.g. touchstart) and mouse events (e.g. mousedown) to determine the input event coordinates. var bodyElement = document.body; bodyElement.addEvent ...

Abandoned <li> and </li> elements

I've come across some HTML code where orphaned <li> and </li> tags are surrounding certain paragraphs without any corresponding opening or closing <ul> or <ol> tags. Is there a way to efficiently parse or mass find/replace ove ...

Adding a combination of HTML and Javascript to an element can result in unexpected behavior

http://jsfiddle.net/PeKdr/ Encountering an issue when having a JavaScript variable that contains both HTML and JavaScript, resulting in unexpected behavior in the output window. Neither of the buttons - one triggering the function appendTheString() or the ...

Redirecting files from the file system to the emulator is not functioning properly

I am new to Phonegap and need help resolving this issue. In my application, I need to redirect to the List.html file when a button is clicked. Here is the code I have written: button1 function test() { window.location="/home/swift-03/phonegapexa ...

I am attempting to display the Δ symbol on my website, however, it is not appearing on the webpage

In my attempt to display my company logo on the website, I encountered an issue where the Δ symbol is not appearing correctly in the browser. strong class="footer-logo">KyΔnsys</strong To address this problem, I have implemented unicode charset=" ...

What is the best way to create a collage of images with a random and unique arrangement?

Recently, I stumbled upon a website and was intrigued by the unique effect of images randomly appearing on the screen. I'm curious about how this effect can be achieved. Is it possible to use CSS Grid to divide the screen and designate some grid ite ...

Learn how to showcase a text file uploaded to a webpage with NODE js and HTML

<!DOCTYPE html> <html> <body> <form action = "/submit" method = "post"> Select a file: <input type="file" name="file"> <input type="submit"> </form> </bod ...

How can I ensure that my jQuery code only executes after the mobile CSS has been loaded

When it comes to loading my mobile-only CSS, I typically use a media query similar to: <link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" href="/includes/css/mobile.css" /> However, in addition to these CSS mod ...

The header row in HTML tables sometimes vanishes unexpectedly after sorting the table

Upon filtering the table, I noticed that the header disappears sporadically. The issue is that the table header row should remain in place regardless of whether or not the characters used for filtering are present in the table rows. In Example 1: When fil ...

What are the steps to connecting incoming data to an Angular view utilizing a reactive form?

Hello, I am currently fetching data from an API and have successfully displayed the teacher values. However, I am unsure of how to utilize the incoming array values for "COURSES" in my Angular view. This is the response from the REST API: { "courses ...

Utilize the href attribute on an image, whether it be through a class

I work as a designer and I'm looking to extract the same href link from class="kt-testimonial-title", either in id="slick-slide10", or in class="kt-testimonial-item-wrap kt-testimonial-item-0", or in class="kt-testimonial-image". Can this be achieved ...

Positioning a centered div with absolute positioning may result in offset issues on Android devices when the content exceeds the viewport size

Encountering a peculiar issue on Android browsers, particularly when the following elements are present on a page: A div element larger than the device's viewport size. (In this case, set at 1200px.) One or more other div elements styled for centeri ...

Using AJAX to send data with a POST request in Django may not function properly

Let me preface by saying I have searched for solutions online, but none of them seem to address my specific issue (mainly because they use outdated methods like Jason). I am currently working on a Django project and trying to implement ajax for a particul ...

Exploring the possibilities of applying CSS to customize the color of various elements

Is there a way to set the color of elements in CSS so that it applies to everything such as fonts, borders, and horizontal rules when applied to the body? How can I accomplish this effectively? ...

What is the best way to store checkbox statuses in local storage and display them again in a JavaScript to-do list?

I'm currently working on a to-do list application using basic JavaScript. One issue I'm facing is saving the checked status of the checkbox input element and displaying it again after the page is refreshed. Since I'm still learning JavaScrip ...

Ensure that PHP form validations are checked when submitting the form using jQuery

I have created a form in HTML with basic verification. Here is the code: <form class="" action="submit/save" method="POST" enctype="multipart/form-data" id="submit_form"> <input class="form- ...

I'm having trouble with my code - I suspect the issue might be related to the header() function

When I execute the following code, it resets the form and keeps me on the same page. I am aiming for it to redirect to home.php after a successful login. I believe there is an issue with my header() I have experimented with different approaches and have ...

Try implementing a body template when using the mailto function

Is there a way to customize an HTML template for the mailto() function body? For example, suppose I have the following link: echo "<a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97f2faf6fefbd7f0faf6fefbb ...

Issue with Firefox browser: Arrow keys do not function properly for input tags in Twitter Bootstrap drop down menu

Requirement I need to include a login form inside the dropdown menu with username and password fields. Everything is working fine, except for one issue: Issue When typing, I am unable to use the arrow keys (up/down) in Firefox. This functionality works ...

In Safari, my layout is disrupted by the mere mention of the word 'City'

There's something strange happening in Safari that I can't quite figure out. Here's how my layout looks in Chrome: https://i.sstatic.net/lPhnP.png But when viewed in Safari, it looks like this: https://i.sstatic.net/IMnQb.png For some r ...