Suggestions on designing a website's layout

Currently, I am in the process of designing a website that is tailored to perfectly fit within the browser window. Here's a brief overview of the layout:

At this point, the Red area is set as display:block, while the Green area has been configured with display:block and margin-right:200px. The Blue areas, nested within a div, are floated to the right.

The width has been successfully adjusted, but now I am seeking guidance regarding the height. Both the Red and Dark Blue areas have fixed heights, yet I need the Green and Light Blue areas to adapt their heights according to the browser window view.

I have attempted to utilize box-sizing, however, it seems to surpass the height of the window view by extending all the way to maximum height of the window. My explanation might be a bit confusing, so any advice or suggestions would be greatly appreciated. Thank you!

Answer №1

If you want a green box to have a height of calc(100%-{height of red box});, and for the light blue box to have a height of

calc(100%-{height of dark blue box}-{height of red box});

Answer №2

This is like the earlier version of C-Link's response.

Link to jsFiddle and View in fullscreen mode

One limitation is that any content extending beyond one full page will be outside its container (visible when scrolling down in the fiddle, not on fullscreen).

Ensure our page expands to its complete height.

body, html { height: 100%; width: 100%; margin: 0; padding: 0;}

Establish a fixed-height header.

header {
    height: 101px;
    background: red;
}

Create a box for everything below the header. Previously mentioned box-sizing technique was going in the right direction. We can also add padding equal to the header's height. Then percentages inside it will function well.

.content{
    position: absolute;
    box-sizing: border-box;
    padding-top: 111px;
    padding-bottom: 10px;
    top: 0; left: 0;
    height: 100%; width: 100%;
}

Float our aside element (could vary based on content) and apply some styles to it.

aside {
    float: right;
    width: 20%;
    height: 100%;
    padding-bottom: 111px;
    box-sizing: border-box;
}

.top {
    height: 100px;
    background: blue;
}

.bottom {
    margin-top: 10px;
    height: 100%;
    background: skyblue;
}

This area contains the main content, floated to the left. Width could be specifically defined if precise padding is desired with additional HTML markup.

[role="main"] {
    width: 78%;
    background: limegreen;
    height: 100%;
    float: left;
    box-sizing: border-box;
}

You may add overflow-y: auto to either the main or aside elements for them to scroll when content exceeds the space. Mobile styles should eliminate floating, absolute positioning, styling, and widths nearly 100% for this page.

Answer №3

One way to adjust the height of the green box is to set it equal to the window height minus the height of the red box.

Similarly, you can set the light box height to the window height minus the combined height of the red box and the dark blue box.

Edit 1: It's important to note that this adjustment needs to be made using JavaScript.

Edit 2: Don't forget to take into account any paddings and margins as well.

Answer №4

Is it possible to simply specify a maximum or minimum height for the divs based on their intended use?

Personally, I prefer to utilize a main container or wrapper div to encapsulate all other elements within, essentially defining my effective page or screen area.

<div id="wrapper">
    <div id="content">
        <div id="sidebar">
        </div>
    </div>
 </div>

#wrapper{
    min-height: Specify desired value here;
    max-height: Specify desired value here;
}

Consider structuring your page with primary container divs not only for content but also for header and footer sections.

For example, I typically have a main wrapper representing the entire page, within which are nested the header, content, nav, and footer divs as the key components. All additional elements can then be enclosed within these.

You can create a layout using percentages for fluid design that adapts to varying browser sizes. Remaining elements will fit neatly inside the main divs and remain bound by them. Additional consideration may be required for positioning, but this is generally the recommended approach.

<div id="wrapper">
<div id="header">Include header content and related divs here</div>
<div id="content">Enter all content here</div>
<div id="nav">This represents your sidebar</div>
<div id="footer">Footer, similar to header</div>
</div>

Then adjust the CSS to customize the aforementioned layout focusing on the main divs exclusively. Use percentages instead of pixels for fluidity maintenance.

#wrapper{
width: 100%;
height: 100%
}
#header{
width: 100%;
height: 20%
}
#content{
width: 70%;
height: 60%;
float:left;
}
#nav{
width: 30%;
height: 60%;
float:left;
}
#footer{
width: 100%;
height: 20%
}

Answer №5

One clever technique involves setting the green (and light blue) box with absolute positioning, a padding, and a negative margin. Since 100% width is relative to the containing box (whether it's a parent div or the window itself), this approach works well. If the header had a fixed height, like 10%, it would have been simpler. The padding ensures that content doesn't get hidden by the header, while the negative margin repositions the box. Remember to set the z-index too, to prevent the content (green part) from overlapping the header.

The CSS code would be:

.header { position: absolute; width: 100%; height: 100px; background: red; z-index: 1; }
.content { position: absolute; width: 100%; height: 100%; padding: 100px 0 0; margin-top: -100px; background: green; z-index: 0; }

You can see how it works in this fiddle: http://jsfiddle.net/2L7VU/

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

Alter the background color of a table cell in Angular HTML depending on a boolean value

Attempting to use Angular ng-class to set the background color of a table cell. I'm referencing code snippets from these resources: Angular: How to change the color of cell table if condition is true Change HTML table cell background color using ...

Tips for expanding the boundary of a Font Awesome icon

The image is in a h1 editing margin of h1 only edits margin-left increases the margin on the left of the image. trying to increase margin of i element does nothing either on i element does nothing either. <h1 class="display-4"><i class="fas fa- ...

"Creating a 2-column layout for an unordered list using CSS Flex

After spending far too much time at work today pondering this issue, I've decided to turn to the collective wisdom of the internet. My dilemma involves a standard <ul> containing multiple <li> elements (currently 12, but this number could ...

My goal is to generate four HTML buttons that trigger specific functions: addition, subtraction, multiplication, and division

I am currently learning JavaScript, and I am facing some challenges with my assignment. The task is to create four buttons in HTML that trigger different functions - addition, subtraction, multiplication, and division. The goal is for the user to input two ...

Presenting tailored information within a structured chart

Working on my angular project, I have a table filled with data retrieved from an API. The table includes a status column with three possible values: 1- Open, 2- Released, 3- Rejected. Current display implemented with the code snippet <td>{{working_pe ...

Creating code to ensure a div element is displayed only after a specific duration has elapsed

Can anyone help me with coding to make a div appear on a website after a specific amount of time? Here's an example of what I'm trying to achieve: <div class="container"> <div class="secretpopout"> This is the hidden div that should ...

What is the reason that `font-size` does not match the `height`? For example, if the `<span>` on the left is 2rem, on the right I could fit 2 smaller `<span>`s, each with a size of 1rem

How can I achieve a layout like this? https://i.sstatic.net/rrISu.png Essentially, I have 2 containers in flexbox: The first one with text "33" The second one is a grid container: The first element in the grid is "EUR" The second element in the grid i ...

Trick for adjusting padding on top and bottom for responsive blocks of varying widths

Hello there, I've been working on a project where I need to create a responsive grid of cards, like news articles, that maintain their proportions even when the browser's width changes. To achieve this, I decided to use an aspect-ratio hack by s ...

Storing a selected value in the database using Laravel Blade

Attempting to save information from a select field to the database. Tested this method: <div class="form-group"> <label>Type</label> <input style="width:10%" type="text" name="type" class="form-control" value="{{$findBook-& ...

Notify the user with a Jqgrid alert when they attempt to select multiple checkboxes

When editing rows, I wanted to avoid multiple selections. In order to achieve this, I need to check the condition if(count>1) and display an alert message. I am struggling to figure out how to retrieve the count of selected checkboxes in jqGrid. var m ...

Tips for saving data from dynamically created input and select boxes

I have developed a webpage where users can add or delete rows by clicking on the addrow and delrow buttons. Everything is working fine so far. The issue I am facing now is that I need to store the values of dynamically generated fields using the post metho ...

Horizontal image scrolling problem across different browsers

Check out my Fiddle. I'm having trouble with scrolling on different browsers. In Chrome, the scroll behaves as expected and stops when the content ends. However, in Firefox, it keeps scrolling even after reaching the end despite setting a fixed width ...

What is the process for building an interactive quiz using JavaScript?

In the process of creating a quiz, I envision a user interface that presents questions in a "card" format. These questions will include simple yes/no inquiries and some multiple-choice options. As the user progresses through the quiz, their answers will de ...

Fixed position scrollable tabs with Material UI

I recently implemented material-ui scrollable tabs in my project, referencing the documentation at https://mui.com/material-ui/react-tabs/#scrollable-tabs. Here is a snippet of the code I used: <Tabs value={value} onChange={handleChange ...

When hovering over the menu list, the background-color of the text area remains the same

I am facing an issue with my list menu. The hover effect changes the background color only in the box area, but not in the text area. I would like to figure out a way to make both areas change color on hover: Here is the code snippet: <div class="se ...

Display picture on webpage in 10 seconds

Hi, I'm working on a website project and I've run into an issue where I need to use JavaScript, but I haven't mastered it yet. I have a background image slideshow set up where a new image appears every 6 seconds. My idea is to have the sec ...

Verify whether the element within an iFrame contains any content

After conducting extensive research, I have been unable to find a satisfactory answer to my question. Therefore, I am reaching out to see if anyone has the knowledge I seek. The Goal: I aim to check the contents within an iFrame and determine whether it ...

Switch off any other currently open divs

I'm currently exploring a way to automatically close other div's when I expand one. Check out my code snippet below: $( document ).ready(function() { $( ".faq-question" ).click(function() { $(this).toggleClass('open'); $(this ...

Unable to open fancybox from a skel-layer menu

Seeking assistance with integrating a Fancybox inline content call from a Skel-layer menu (using the theme found at ) <nav id="nav"> <ul> <li><a href="#about1" class="fancybox fancybox.inline button small fit" >about< ...

The animation function in A-frame causes entities to vanish when used with D3.js

Working with the animation property in D3.js has been a bit of a challenge for me. When I include the a-animation directly in the HTML section, everything works as expected. <a-box id="box" position="0 1 0" rotation="0 0 0" scale="1 1 1" color="#4CC3D9 ...