Trouble with HTML and CSS design layout

I'm struggling to create a responsive design for my webpage. The layout should consist of black blocks that display images.

Ensuring the layout adapts to different screen sizes is proving challenging. It needs to maintain its shape on smaller screens while fitting any size screen. On wider screens, the layout should expand accordingly.

I've attempted various solutions but can't seem to pinpoint the core issue causing the problem. It's not just one line of CSS that's off - it's something fundamental that I can't grasp.

Could someone create a Fiddle with just black boxes to troubleshoot this?


Here's my progress so far. The current issue lies in the margins between the blocks - they need to be 5px apart. When I adjust them as such, things start going awry. The block sizes are correct now, but I need to figure out how to space them properly.

HTML:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8>
<link href="style.css" rel="stylesheet" type="text/css" />
<title></title>
</head>
<body>
<div id="wrapper">
    <a href="#" class="link">
        <img class="mainImg" src="http://www.calvijn.nl/media/3529/IMG-20130925-WA0001_500x500.jpg" alt="test" />
    </a>
    <a href="#" class="link">
        <img class="subImg" src="http://stage.elephantcs.nl/wp-content/uploads/2011/11/img-impression-5.jpg" alt="test" />
    </a>
    <a href="#" class="link">
            <img class="subImg" src="http://stage.elephantcs.nl/wp-content/uploads/2011/11/img-impression-5.jpg" alt="test" />
        </a>
    <a href="#" class="link">
        <img class="subImg" src="http://stage.elephantcs.nl/wp-content/uploads/2011/11/img-impression-5.jpg" alt="test" />
    </a>
    <a href="#" class="link">
        <img class="subImg" src="http://stage.elephantcs.nl/wp-content/uploads/2011/11/img-impression-5.jpg" alt="test" />
    </a>
</div>
</bod>
</uhmtl>

CSS:

#wrapper {
position: absolute;
left: 5%;
right: 5%;
top: 100px;
width: 90%;
height: auto;
background: red;
}

.mainImg {
display: inline-block;
float: left;
width: 33%;
}

.subImg {
display: inline-block;
float: left;
width: 33%;
}

Check out the fiddle here: Fiddle

Any tips on how to space the blocks correctly would be greatly appreciated!

Thank you in advance!

Answer №1

Check out this fiddle / View Expanded Mode

HTML

<div id="wrapper">
    <div class="box">
        <div></div>
    </div>
    <div class="box">
        <div></div>
        <div></div><br/>
        <div></div>
        <div></div>
    </div>
</div>

CSS

html,body,#wrapper{
    width:100%;
    height:100%;
    margin:0 auto;
    padding:0 auto;
    white-space:nowrap;
    font-size:0px;
}
.box{
    display:inline-block;
    height:100%;
    white-space:nowrap;
}
.box:nth-child(1){
    width:30%;
    vertical-align:top;
    margin-right:5px;
}
.box:nth-child(2){
    width:70%;
}
.box div{
    display:inline-block;
    border-left:3px solid white;
    border-top:3px solid white;
    background-color:black;
}
.box:nth-child(1) div{
    width:100%;
    height:100%;
    padding-top:3px;
}
.box:nth-child(2) div{
    width:50%;
    height:50%;
}

Fresh Fiddle

Answer №2

To resolve this problem, it is recommended to utilize the min-height property.

For instance, you can refer to this example: http://jsfiddle.net/vRPfq/1/

However, keep in mind that this may affect the display of your images.

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

The offcanvas menu in the NextJS Tailwind website does not handle hover or tap events properly when outside of the parent dimensions

My header includes an off-canvas menu that slides in from the right side. Everything seems to be working fine, except for one issue: when the menu is open and visible, the mouse and touch events pass through it to the content underneath. Check out the cod ...

Having trouble locating the source of the issue causing the product page to appear too wide on Shopify

Can someone assist me in identifying the issue that is causing the product page on this website () to be too wide? Here is an image highlighting the issue. I made some CSS customizations to make the product gallery full width and added padding to the pro ...

What is the best way to incorporate visual indicators into specific columns containing certain keywords?

Is there a way to customize the script code responsible for displaying table data so that icons automatically appear next to specific keywords in the Gender column? For instance, can we have an icon like glyphicon glyphicon-heart-empty for Male and glyphic ...

Issue with VueJS components not functioning as expected with routes

I've encountered an issue when using the component tag with an id of #app within the template of my components/App.vue file. Whenever I include this setup, I receive the following errors: // components/App.vue <template> <div id="app"> ...

The GridCalendar view of FullCalendar v6.1 is generating 50 `ARIA attribute unsupported or prohibited` errors when analyzed with the SiteImprove browser extension

The Challenges Creating a website that adheres to accessibility laws can be quite daunting. I am currently using SiteImprove, a free browser extension, to check for any issues on my site. Unfortunately, the GridCalendar view is showing 50 errors. ARIA a ...

Exploring the Link Between jQuery and HTML

Is it possible to connect between an HTML file and a jQuery file? Here is an example scenario: jquery-test.js: $(document).ready(function(){ $('#inputForm').submit(function(){ $('#inputForm :text:not("#submit")').each(func ...

Is it possible to change the inner html to null during an active ajax request?

My goal is to have two separate data.html files inserted into two different HTML files without needing a click event. I want the structure of my data.html files to remain consistent, while allowing the template of my website to change dynamically by callin ...

Is it possible to obtain the index of a table row using querySelector?

Is it possible to find the rowIndex of the first occurrence of a table row within the #myTable using JavaScript? http://jsfiddle.net/bobbyrne01/fmj6np6m/1/ html .. <table id="otherTable"></table> <table id="myTable"></table> js ...

Is there any method to ensure that IE8 properly displays opacity for a `:before` pseudo element?

Here is a simple CSS snippet that I am working with... div:before { content: "Hello there"; filter: alpha(opacity=40); -moz-opacity: .4; opacity: .4; } Check it out on jsFiddle. In Firefox 6, the :before pseudo element displays with t ...

Modifying button text with jQuery is not feasible

I'm facing a challenge with jQuery and I need the help of experienced wizards. I have a Squarespace page here: . However, changing the innerHTML of a button using jQuery seems to be escaping my grasp. My goal is to change the text in the "Add to car ...

"CSS: Mastering the Art of Color Curves

Is there a way to achieve this with just HTML and CSS? ...

Incorporation of a dynamic jQuery animation

I'm a beginner in jquery and I'm attempting to achieve the following: I want each menu to collapse separately when the mouse hovers over it. The issue is that both menus collapse simultaneously! I know it's probably something simple, but I ...

Instead of utilizing just one <select> element, Django mistakenly generates two while attempting to implement Bootstrap for form uploads

Struggling to develop a website using django and facing an issue where two select lists are appearing instead of one. Here is the HTML code: <form action="/upload/" method="post" enctype="multipart/form-data"> {% csrf_token %} <div class="form-g ...

Having trouble with the auto width CSS for the center section of my webpage

I am facing an issue with assigning widths to my divisions using the CSS calc property. Despite setting the width for the first and last divisions, I am unable to allocate any width to the middle division. HTML: <div style="width:400px;"> <div ...

The button similar to Facebook does not function properly when using fancybox

My photo gallery uses fancybox, and when fancybox is open a like button appears outside the title. However, the Facebook like button doesn't seem to work. Here is my JavaScript code: $(".fancyboxi").fancybox({ padding: 0, openE ...

How to Align Title in the Center of a Section Containing Multiple Images?

I have a situation where I am using a StyledHead section to display 10 images from an API. The images are wrapped in another section called StyledHeader, which also contains an h1 element. How can I center the h1 element both vertically and horizontally so ...

The button's size shrinks significantly when there is no content inside

When text is absent, the button shrinks in size. I am utilizing an angular model to bind the button text: <button type="button" class="btn btn-primary" ng-bind="vm.buttonText" tooltip="{{vm.tooltipText}}" ></button> I prefer not to apply any ...

What is the best way to place two span elements beside each other?

Is there a way to align the name and address on the same line, with the address positioned on the right and the name on the left? Currently, the address is appearing on a separate line from the name. How can I resolve this issue? Here is the provided cod ...

Can you guide me on how to duplicate a file when a button is clicked?

I am working on creating a one-page utility/prototype that has an admin user interface. The goal is to have a drop-down box for the admin user to select an option and then copy a file from one directory to another upon clicking a submit button. Although I ...

Can you tell me which BBC channel is airing this animation?

Is anyone familiar with the animation on the login screen of BBC when entering the day, month, and year? Check it out here: ...