"Tall artificial columns that add a touch of grandeur

It has been a while since I last coded a website, so my skills are a bit rusty. My goal is to create a fixed-width sidebar with full height and a fluid content area. (Check out the visual mockup here: )

I came across faux columns, which seem to be working well for most of the layout. However, I'm struggling to make the sidebar full height using this technique.

Below is the CSS and HTML code I'm currently using:

html,body {
    height: 100%;
}
#page-container {
    min-height: 100%;
    margin: 0;
    position: relative;
}
* html #page-container {
    height: 100%;
}
#inner-container:after {
    content: " ";
    display: block;
    clear: both;
}
#left-col {
    float: left;
    width: 250px;
    background-color: #F3F3F3;
}
#right-col {
    position: relative;
    margin-left: 250px;
}

HTML:

<div id="page-container">
    <div id="inner-container">
        <div id="left-col">
            <ul>
                <li>Lorem Ipsum</li>
                <li>Dolar Sit Amet</li>
                <li>Consectetur</li>
                <li>Adipiscing</li>
                <li>Elit Integer</li>
            </ul>
        </div>
        <div id="right-col">
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
        </div>
    </div>
</div>

Any suggestions on how I can achieve a full-height sidebar? Perhaps there's a better column technique to use?

Answer №1

If you want to position the sidebar absolutely, you can do so by giving the content area an equivalent margin-left:

<style>
*, html {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
position: relative;
}

/* Consider using conditional stylesheets for IE fixes */
* html div.column {
height: 100%;
}

div.column {
min-height: 100%;
}
div#content {
margin-left: 250px;
background-color: #FFFF99;
}
div#sidebar {
position: absolute;
top: 0;
left: 0;
width: 250px;
background-color: #99FFFF;
}
</style>

HTML:

<div id="content" class="column">
content
</div>
<div id="sidebar" class="column">
sidebar
</div>

Note: A key advantage of this method is that it allows you to place the content markup above the navigation in the page source, which can be beneficial for SEO purposes.

Answer №2

A simple solution is to convert your floated left column into an absolutely positioned element and set its height to 100%:

#left-col {
    position: absolute;
    top: 0;
    left: 0;
    width: 250px;
    height: 100%;
    background-color: #F3F3F3;
}

See it in action here: http://jsfiddle.net/ambiguous/XyBzC/

If you follow this approach, you can eliminate the need for #inner-container:after, which was previously used to clear the float from the left column (which is no longer floating).

Check out a version without the :after pseudo-element here: http://jsfiddle.net/ambiguous/XyBzC/1/

In addition, as mentioned by Joseph in the comments, adding padding: 0 to the html,body can help remove unnecessary scrollbars in the fiddle:

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

For instance: http://jsfiddle.net/ambiguous/XyBzC/2/

Answer №3

The concept you have there is not exactly what is typically referred to as faux columns. If you're interested in learning more about faux columns, I would highly recommend checking out this informative article from A List Apart.

I personally tend to avoid using absolutely positioned elements unless it's absolutely necessary (and in this particular case, it isn't).

Unfortunately, jsfiddle doesn't permit the use of external assets like images, so for a straightforward example of faux columns, feel free to check out this demonstration here.

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

Is it possible to replace multiple li elements with multiple ul elements within a single ul for better organization?

In the world of HTML and CSS, there are endless possibilities for creating unique designs. Recently, I stumbled upon an interesting question that has been lingering in my mind without a clear answer. Typically, people use a single "ul" element to create a ...

What is the best way to prevent a draggable div from moving past the edge of the viewport?

My situation involves a draggable div that functions as a popup window when a specific button is clicked. However, I noticed that dragging the div to the end of the viewport allows me to drag it out of the visible area, causing the body of the page to expa ...

Creating XPaths for HTML using Selenium: A step-by-step guide

What is the proper way to create an xpath expression for the following block of html? <li> <a href="/parade/storeus/browse/Home-Accents-Radios/_/N-1c7kmv"> Radios </a> </li> ...

When hovering over the menu, the page's opacity decreases to 0.5

Feeling lost on how to create a navigation menu that reduces the transparency of the entire page to 50% when hovered over. Any advice on the CSS code needed for this scenario? Check out jsfiddle.net/websensation/uMMPa for more insights. ...

What is the best way to utilize justify-content or align-self to perfectly center this?

Despite my efforts to center it, I'm struggling to do so. I've experimented with justify-content and align-items for each row and col class, but unfortunately, nothing seems to be effective. In the breakpoints (md, lg), I really need the 4 lorem ...

Should we avoid styling HTML tags?

Would it be considered poor practice, for instance, to apply the following CSS rules to all images on my webpage in order to make them responsive: img { display: inline-block; height: auto; max-width: 100%; } Instead of using img-responsive on each ...

Leveraging numerous Yii applications

In my directory structure, I have the following: root/ root/protected root/framework root/backend root/backend/protected The first Yii application is located directly inside the root folder at the same level as the framework folder. The second Yii applic ...

"Interactive feature allowing users to edit and view the most recently inserted HTML

My approach involves using a contenteditable div as an input field for entering text and inserting icons through a button that adds small HTML pictures within the text. Everything works fine when the text is narrower than the contenteditable field. Howev ...

jQuery SlideDown Navigation

Is there a way to implement jQuery code that will display dropdown menu options when the Trials link is clicked? Update: jQuery(document).ready(function () { $("a[href='http://sheep.local/cms/trials']").click(function(e){ e.prevent ...

Tips for decreasing Vuetify Grid column width on larger screens

I'm currently utilizing the vuetify grid system to construct a reply component. The column ratio is set at 1:11 for the icon and reply columns, respectively. Below you'll find the code snippet: <v-row justify="center" class="ma-0 pa-0"> ...

Unable to load HTML image from Google Cloud

Despite my limited coding knowledge, I have dedicated the last 6 hours to solving this issue. Follow this link to view the image I am trying to load. If I need to change the SRC lines, where and how should I do that? The HTML image loads correctly from ...

applying custom font to select boxes in bootstrap

Trying to style the select option text using a Poppins font with the following class: .poppinsregular14diese00000061 { font-family: Poppins; font-weight: 400; font-size: 14px; color: #00000061; } You can view the implementation in this fi ...

Issue with sticky navbar in parallax design

I have been working on a website where all pages feature a header and a navbar located just below it. As the user scrolls down the page, I want the navbar to stick to the top of the screen once it reaches that position. However, on one specific page, I am ...

Issue: The function view.hlp(...) is not recognized within jsrender

Currently, I am utilizing jsrender to map the templates within a grid. In this process, I have incorporated a method call inside jsrender based on a certain condition as shown below: @section scripts{ $.views.helpers({ isMobile: function () { ...

Error encountered with the item properties in vue-simple-calendar 'classes'

For my Vue.js project, I am utilizing the npm calendar package called `vue-simple-calendar` and aiming to implement dynamic classes for each event item like background-color, etc. However, the `classes` property doesn't seem to be functioning as expec ...

The Android WebView display is consistently showing a blank white screen, failing to reflect CSS or HTML modifications, and exhibiting choppy animations

There seems to be a strange inconsistency when I make changes to CSS classes. Sometimes, after adding a down class name to a button using a touch event, the changes do not appear on the button or anywhere else on the page. It's frustrating how unpredi ...

Tips for running a JavaScript statement multiple times in the browser console

When I enter the following JavaScript statement in the browser console: inbreedingInvite('74011','107433',''); and press enter, it sends an invitation to user number 107433 to join group id 74011. If I want to invite another ...

Understanding the concept of for loops in JavaScript and incorporating them in CSS styling

Hello there! I initially used this code to draw 12 lines, but now I am looking to incorporate a for loop and implement it in CSS. Can someone please guide me on how to proceed? <!DOCTYPE html> <html> <head> <style> #straigh ...

Create a web design where two HTML elements with full width are positioned to overlap each other,

I am facing a design challenge where I need sections to span the full width of the page, but the content is contained within an article. Additionally, there is an interactive aside that needs to float above the full-width sections. Both the article and as ...

By incorporating JavaScript, clicking on an image will trigger a shift in the position of a different element

Just starting out with JavaScript and experimenting with creating an event where clicking on an image triggers the movement of another hidden image. The hidden image is positioned off-screen to the left, while there is a table of images in the center of th ...