A pair of large pillars perfectly aligned at the center in both horizontal and vertical position

Can anyone suggest an efficient way to design the following layout with responsiveness in mind?

I attempted to divide the elements into sections and applied the transform property, but I encountered difficulties when trying to style the boxes on either side. I am uncertain if this layout is optimal and compatible across various devices.

How would you approach solving this issue?

Computer Layout:

https://i.sstatic.net/LcwX0.png

Responsive Phone Layout:

https://i.sstatic.net/VjtyY.png

This is my current script that still needs improvement:

.page-4 {
width: 100vw;
background-color: #ffd9d2;
z-index:3;
min-height: 100vh;
}

.page-4 .box {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
}

.page-4 .box .group {
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.left {
    float: left;
    max-width: 50%;
}

.right {
    float: right;
    max-width: 50%;
}
    
.group:after {
    content:"";
    display: table;
    clear: both;
}
<div class="page-4">
<div class="box">
<div class="group">

<div class="left">
<div class="page-4-heading">TEXT1</div>
</div>

<div class="right">
<div class="page-4-text">TEXT2</div>
</div>

</div>
</div>
</div>

Answer №1

Have you considered utilizing the power of Flexbox

Check out this fiddle where you can interactively resize the visible area and see the layout change

* { box-sizing: border-box; }

.wrap {
  display: flex;
  flex-flow: row wrap;
}

.wrap > .item {
   border:solid 3px black;
   padding: 10px;
   width: 50%;
}

@media (max-width: 600px) {
    .wrap > .item {
      width: 100%;
    }
}
<div class="wrap">
    <section class="item">1 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</section>
    <section class="item">2 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</section>
</div>

Answer №2

.page-4{
  width: 100vw;
  min-height: 100vh;
}

.page-4 .box{
  width: 100%;
  height: 100%;
}
.page-4 .box .group{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 100%;
}
.left, .right{
  width: 720px;
  height: 300px;
  border: 2px solid black;
  padding: 20px;
}
<div class="page-4">
<div class="box">
<div class="group">

<div class="left">
<div class="page-4-heading"><div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempora hic voluptatum qui, consectetur harum exercitationem. Mollitia, at nesciunt cumque veritatis quia temporibus ex necessitatibus, voluptas suscipit explicabo ab, quos blanditiis.</div></div>
</div>

<div class="right">
<div class="page-4-text"><div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quasi quam, illum, dicta repudiandae ab quisquam dolore fuga nihil perferendis nesciunt vitae reprehenderit blanditiis porro esse? Vel rem eligendi numquam accusamus!</div></div>
</div>

</div>
</div>
</div>

Have you considered utilizing display: flex?

Furthermore, here is another suggestion:

@media screen and (max-width: 400px) {
  /* Apply styles for mobile devices */
}
@media screen and (min-width: 401px) {
 /* Implement styles for desktop screens */
}

Answer №3

.section1, .section2{
width:50%;
height:300px;
background:grey;
padding:10px;
border:3px solid black;
}
.box{
border:1px solid black;
background:grey;
}

@media (max-width:767px){
.section1, .section2{
width:100%;
}
}
<div class='section1'><div class="box"> some text</div> </div>
<div class='section2'><div class="box">another text </div></div>

Feel free to leave a comment if you have any questions

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

Tips for adjusting the maximum width and content-based width for columns within an HTML/CSS table

I'm working on a simple HTML/CSS code featuring a container with two adjustable slots, controlled by a handler in the middle to modify the space each slot occupies. The first slot contains a table with fixed columns, automatic columns, and limited col ...

What is the reason that adding bottom padding and margins is ineffective in creating vertical space between these links?

I am struggling with aligning links vertically in a div. Currently, I am using <br> tags to stack them on top of each other because I couldn't find a way to add vertical spacing with CSS. I attempted to add bottom margin and padding to the &apos ...

How can I center an image in HTML while maintaining a slight margin at the bottom

I am facing a minor issue with the bottom margin of an image. I can't figure out why there is a small gap between the image and the menu below. Can someone provide an explanation? My goal is to have the menu align perfectly with the image, but for so ...

Attempting to create a JavaScript class within an HTML document

Having an issue with instantiating a JavaScript class in a separate HTML file. The JavaScript class looks like this: class Puzzle { constructor(fenStart, pgnEnd) { this.fenStart = fenStart; this.pgnEnd = pgnEnd; } } module.exports = Puzzle; ...

Is there a way to incorporate a click function into this code if the id and xpath methods are ineffective?

Check out the code snippet below: <div class="btn-group" style="margin-top: -10px; box-shadow: none !important;"> <a class="btn btn-clear store-name headerActive" style="margin-left: 0px !important;" ng-click="account();" _href="#/app ...

How to disable a select list in HTML using vue.js when it is checked

I need assistance with a form that includes an "age" field. There are two possible scenarios: if the "unknown" box is checked, then the user should not be able to enter/select an age (the option should be disabled). If the box is unchecked, then the user s ...

Display only the content that is within the container and visible

Within this demonstration, there are 2 divs present - one containing the text t, and the other containing the text s. Both of these divs are enclosed within the .items container. As it stands currently, both divs are visible. However, my goal is to modify ...

Table designed using the Flexbox layout model

I am looking to create a table with multiple columns that can handle dynamic data. The challenge is that using the base <table> element would cause the column width to change when the content changes and I also need the ability to hide columns using ...

Ensure that outlines are visible only when navigating with the tab key using tabindex

Currently, I am working on enhancing the accessibility of my website by improving navigation using the tab button. I have implemented tabindex to manage this, but I have noticed that elements with tabindex display an outline both when clicked and when focu ...

Flexbox allows you to easily manage the layout of your website

I am currently working on a CSS project and have encountered an issue. Whenever I apply the "display: flex" property to the .student element, the border around it mysteriously doubles. The reason for wanting to use the flex property is to align the text ve ...

The HTML file seems to be having trouble connecting to the JavaScript file

I am currently working on a small, fun website project and have an HTML file along with a JavaScript file in the same directory. However, my HTML seems to be unaware of the existence of my JavaScript file. It fails to execute the function during the load e ...

What could be causing the Javascript Dynamic HTML5 Table to not display on the page?

I have a program that calculates the total price of products based on a specified quantity and updates an HTML table with these values. To demonstrate this, I am constantly taking input using an infinite loop. <!DOCTYPE html> <html> ...

Tips on customizing the appearance of the dropdown calendar for the ngx-daterangepicker-material package

Is there a way to customize the top, left, and width styling of the calendar? I'm struggling to find the right approach. I've been working with this date range picker. Despite trying to add classes and styles, I can't seem to update the app ...

Use jQuery to permit only numeric characters and the symbol "-" to be entered into a textbox

I have been working on a JQuery script that only allows users to input numbers in a text field. However, I am now trying to modify the code to also allow users to enter "-" (hyphen), but so far it's not working as expected. If anyone can provide assis ...

How can I dynamically swap one div with another within the same div using Javascript?

I have a piece of code that I am working with, and I need it to replace every div element whenever a specific div is clicked. function updateContent(target, replacementID) { document.getElementById(target).innerHTML = document.getElementById(replaceme ...

Guide on choosing a specific div element from a different page using AJAX

I have a Social Media platform with posts, and I am trying to display the newest ones using JavaScript (JS) and AJAX. I attempted to reload my page using AJAX and insert it into a div element, but now the entire website is loading within that div element, ...

Is it possible to incorporate multiple gradients into the border-image?

When it comes to the background-image, you have the freedom to include as many radial-gradient and/or linear-gradient as you want. However, for the border-image, it appears that only one gradient can be added. This seems peculiar since the display principl ...

What causes the ul element to display upon clicking the input field?

Why is the ul disappearing with display: none when the input element is clicked? Here is the HTML code snippet: When this input is clicked: <input class="input country" type="text"/> This unordered list should be displayed (but ...

Placing Bootstrap nav-items outside of the justify-content-center alignment

Having trouble positioning a button in the nav container to the right side of the screen while keeping all other nav items centered using justify content center. I've tried the following solutions: Using margin-left:auto on the button, but it shifts ...

Disable the click functionality while preserving the hover feature

Due to my previous question being incorrectly marked as a duplicate, even though it wasn't, and no one is rectifying the mistake, I am re-posting my inquiry. I am dealing with an <a> element that has a default onClick function. This <a> a ...