Place two divs side by side and align them in the center of the page

I am facing a challenge with aligning two divs on the same line, but they are not centered on the page. I have tried to adjust the code but without success. Here is my current code:

.table-1 {
  overflow: hidden;
  margin: 0 auto;
}
.box-1 {
  background: url(../images/_C008.jpg) no-repeat center center /cover;
  width: 32%;
  height: 300px;
  float: left;
}
.box-2 {
  background: #374140;
  width: 32%;
  height: 300px;
  overflow: hidden;
}
<div class="table-1">
  <div class="box-1">
  </div>
  <div class="box-2">
    <p>Au quotidien, la vie de l’atelier est organisée autour des tâches minutieuses de chacun et tous sont conscients que l’excellence est le résultat d’un travail d’équipe.</p>
  </div>
</div>

Answer №1

Utilize the flexible box method by adding display: flex to the parent container of the two boxes, then use justify-content: center to align them in the middle.

Refer to the current browser compatibility chart for flexbox

.table-1 {
  display: flex;
  justify-content: center;
}
.box-1 {
  background: url(../images/_C008.jpg) no-repeat center center /cover;
  width: 32%;
  height: 300px;
  float: left;
}
.box-2 {
  background: #374140;
  width: 32%;
  height: 300px;
  overflow: hidden;
}
<div class="table-1">
  <div class="box-1">
    <p>Every day, the workshop life revolves around the meticulous tasks of each individual, with everyone aware that excellence is the result of teamwork.</p>
  </div>
  <div class="box-2">
    <p>Every day, the workshop life revolves around the meticulous tasks of each individual, with everyone aware that excellence is the result of teamwork.</p>
  </div>
</div>

Answer №2

.table-1 {
  overflow: hidden;
  margin: 0 auto;
  text-align: center;
}
.table-1 > div{
box-sizing: border-box;
display: inline-block;
vertical-align: top;
}
.box-1 {
  background: url(../images/_C008.jpg) no-repeat center center /cover;
  width: 32%;
  height: 300px;
border: 1px solid #ccc;
}
.box-2 {
  background: #374140;
  width: 32%;
  height: 300px;
  overflow: hidden;
}
<div class="table-1">
  <div class="box-1">
  </div>
  <div class="box-2">
<p>Everyday, the workshop life revolves around each person's meticulous tasks, and everyone is aware that excellence is the result of teamwork.</p>
  </div>
</div>

Answer №3

Check out my solution on jsfiddle:

display: inline-block;
text-align: center;

View Solution

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

Having issues with AngularJS ng-if when implemented within a Form

Is there a way to hide my form after it has been submitted using ng-if? I am facing an issue where clicking the 'See' button toggles the form on and off, but the same functionality does not work with the 'Add' button. Any insights on wh ...

Hover effect not activating on image within modal

only img:hover is working, but after adding this to the CSS: #user-profile #user-myModal .modal-body img:hover #user-profile #user-myModal .modal-body .change-pic i{ display: block; } it's not working. I changed the class and id names, tried eve ...

Tips for quickly navigating to filter results on a page using jquery

In order to display addresses of laboratories based on parameters such as regions and profile, I have utilized a clickable map and menu. (Visit the site for reference: ) The issue I am facing is how to ensure that when clicking on a region, it smoothly ju ...

The submission of the Jquery form is not successful

I am struggling with a form on my page. I want to disable the submit button and display a custom message when submitted, then use jQuery to actually submit the form. <form> <input type="text" name="run"/> <input type=&quo ...

Deck.gl's StaticMap component from Mapbox fails to resize properly, causing it to overwrite other elements on the screen

I am encountering an issue while trying to integrate a basic deck.gl (mapbox static map) into a react project. Although I can successfully add the map, it ends up taking over the entire page and hides any other content that should be visible above it. Spec ...

Adjusting the target of the anchor dynamically

I have a WordPress theme with a built-in widget that allows you to insert social media links into sidebars or headers. All the social media links are contained within a div with a unique class called social-links. I want to add target="_blank" to all anc ...

Retrieving Data from Created Table

I am working with a table generated using data from JSON. I want to create a behavior where clicking on any cell, specifically the row, will display the values as text at the bottom of the screen. Although my code works, the issue is that it combines the v ...

The changes to the position are being reflected in the debug console, yet my DOM remains stagnant

I'm currently working on developing a JavaScript clicker game, but I've encountered an issue with the gem animations. Despite debugging and confirming that the position is updating, the gems do not visually fall down after being clicked. Below is ...

Parent menu fails to trigger the opening of child menu upon clicking

I'm struggling to modify a Wordpress theme to enable the child menus to expand when clicking on the parent menus. Is there a way to edit this code to make that functionality work? // Implement expandable menus var expand_link = $('<a class="m ...

Tips for arranging divs in Bootstrap 5 to position one above the other

I have chosen to utilize Bootstrap 5 for my website project with the aim of enhancing its responsiveness on all devices. Specifically, I am seeking a way to ensure that when visitors access the site from a mobile device, the image-containing div appears a ...

Error in AngularJs addition calculation

Within a table, I have three columns titled deduction, advance, and total. The values for the first two columns are retrieved from the database, while the third column should display the sum of the first two columns but instead shows a concatenated resul ...

Tips for arranging five images side-by-side in a row

I have a collection of 5 images: Image 1: Image 2: Image 3: Image 4: Image 5: The dimensions of each image are as follows: Image 1: 70x40 Image 2: 80x42 Image 3: 90x44 Image 4: 100x46 Image 5: 120x48 I would like to arrange these images ...

Looking to dictate which image is displayed when sharing a webpage on social media or mobile devices?

I am managing an e-commerce website and I'm looking for a way to choose which image appears when users share my product description. The product description page includes a gallery of product images and an aside section with related products. The iss ...

Center the table cell element horizontally

Struggling to align a table cell element both horizontally and vertically? Currently, only managing the vertical alignment. The images vary in size, calling for fluidity and compatibility with max-height and width... Custom Style Sheet (CSS) .prod-img { ...

Exploring methods to extract content from an HTML tag in Bash with the help of XMLStarlet

Seeking assistance in accessing HTML tag content using XMLStarlet in a Bash script. Using www.wisdomofchopra.com/iframe.php as an example but facing challenges with specifying the correct addresses in the HTML for XMLStarlet. Below is my code attempt: URL ...

Hidden background image not shown

While working on a component in vue.js, I encountered an issue where the image is not being displayed within the specified tag: <b-icon v-if="displayShowHistory && checkRole('showHistory')" class="backlight show-modal-ic ...

Using JQuery to access options dynamically generated within Select elements

I am currently working on Select elements that are dynamically updated with new options at set intervals. My goal is to programmatically access these new options in order to check if a certain value exists within the select element. I attempted to use the ...

Is there a problem with css3 opacity transition in Webkit browsers?

While exploring alternative ways to modify the Bootstrap 3 carousel, I stumbled upon a technique that achieves a 'fade' effect instead of the usual 'slide'. However, in webkit browsers, the transition may appear choppy or flicker betwee ...

What is the best way to locate a div element with a specific style?

What is the method to locate a div element by its style? Upon inspecting the source code in IE6, here is what I find: ...an><div id="lga" style="height:231px;margin-top:-22px"><img alt="Google"... How can this be achieved using JavaScript? ...

What methods can be used to conceal and protect the source code of CSS and JavaScript files from being downloaded

Is there a way to keep the source code for my website's CSS, JS, and image files hidden and prevent them from being downloaded? I noticed a website that seems to have achieved this successfully: www[dot]sales.4080.ir/themes/corporate3/index.html I w ...