first comes the content in the two column layout

HTML:

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

CSS:

#content {
    background: blue;
    height: 900px;
    width: calc(100% - 200px);
}

#sidebar {
    float: right;
    width: 200px;
    height: 900px;
    background: red;
}

JSFIDDLE: http://jsfiddle.net/aFrPc/

To achieve the desired layout, I have rearranged the order of the div elements in the HTML code. The #content now comes before #sidebar and has been set to fill all remaining space using the CSS property 'width: calc(100% - 200px);'.

Image of final wanted result:

Answer №1

UPDATED In order to display the content text before the sidenav text, follow this structure: Fiddle


    <div id="main">
        <div id="content">
            <div style="padding-left:200px">
                Context
            </div>
        </div>        
        <div id="sidebar">sidebar</div>    
    </div><!--#main-->

    #content {
        background: blue;
        height: 900px;
        width:100%;
        margin-left:-200px;
        float:right;
        color:#fff;
    }

    #sidebar {
        float: left;
        width: 200px;
        height: 900px;
        background: red;
    }

Answer №2

If you want the content to be displayed first and take up all available space after a 200px sidebar, try this method:

body{
  overflow-x:hidden;
}
#content {
  background: blue;
  height: 900px;
  position:absolute;
  width:100%;
  left:200px;
}

#sidebar {
  float: left;
  width: 200px;
  height: 900px;
  background: red
}

You can check out the code in action on Jsfiddle: http://jsfiddle.net/VkQ6U/

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

Protect the digital art piece on Canvas by utilizing Codeigniter framework

I followed a video tutorial series to create an HTML5 Canvas Drawing App and now I am looking to save the drawings as images in a database using codeigniter. Additionally, I want to allow users to input a name for the image before saving it. Since I am new ...

What is the secret behind the functionality of this Jquery dark mode code?

I was experimenting with creating a dark/light mode toggle using jQuery and I came up with this solution One thing that puzzles me is when I remove the 'darkmode' class, instead of adding the 'whitemode' class, it simply adds the attri ...

Where to position a button in the middle of a div that varies in size

I'm currently working with this code snippet: <div class="outer"> <ul class="list"> <li class="inner"> <div class="line">information1</div> <div class="line">hyperlink1</div&g ...

Tips on adjusting video to the screen size

I am looking to create a fullscreen video for my webpage. I originally used an image as a cover, but now I want to switch to using a video. You can check out my old code on this link. Below is my new video code: <div class="embed-responsive embed-resp ...

Scroll elements to the left and display the element on the far right

I need help with setting the CSS for an unordered list inside a container. I want the last list item to show and the leftmost item to be hidden when there is not enough space in the container. Order: li1 > li2 After adding li4, the order should be: ...

Creating alternate blocks of even and odd numbers using a while loop with an odd number as the starting point. Man

My title may be a bit confusing, so if you can make it clearer for everyone, please edit my post. Thank you. I have created a while loop and I want the blocks to form an X pattern. I have two blocks next to each other every time. But I want them to alter ...

How to use a jQuery each loop to retrieve the margin of an element

I currently have 7 different elements, each with unique margin-left and margin-top properties set in the CSS file. I am looking to loop through these elements and gather information about their margins. This is what my jQuery code looks like so far: var ...

What is the best way to modify this CSS code for use in a React Native

Encountering an issue while trying to apply this CSS property in a React Native project. border-radius: 50% / 100%; Attempting the following: borderRadius: '50% / 100%' An error message is displayed stating "Java.lang.string cannot be cast to ...

How can one properly utilize material-ui CSS?

Just starting out with material-ui and react, I'm currently following this palette customization guide from Material-UI. However, when attempting to replicate the example shown, I encountered the error: Cannot read property 'prepareStyles' ...

What could be causing my image to fail to load on Firefox while successfully loading on Safari and Chrome?

Can anyone explain why my image fails to load on Firefox but works fine on Safari and Chrome? .shape { border-radius: 25px; background: #4D5061; content: url(http://i1126.photobucket.com/albums/l611 ...

Troubleshooting Problem with Button Image Display in CSS

I have created a custom CSS for a PayPal sprite that I made. Below is an image comparison showing how it appears in Internet Explorer and Firefox. Here is the code to display the sprite: .ppsprite { background: url('/images/paypal_sprite.png') ...

Executing a PHP function through an HTML button click while maintaining the current page state without

I have a php script: <?php $species = $_GET['species'] ...//do things to prepare the query $result = //result of the query. if (isset($_GET['download'])){ getCSV(); } function getCSV(){ if ($result->num_rows > 0){ ...

Enabling and disabling multiple input fields based on the status of a checkbox in order to manage dynamic inputs

I need help with a situation involving dynamic input fields and checkboxes. My goal is to disable the input field if the checkbox with the corresponding ID is checked. Here is the PHP code snippet: <table class="table table-striped"> <thead& ...

Issue with Line 126: Syntax Error Unexpected End - Troubleshooting Required

Encountering an issue in my JS/HTML5 pong game project at line 126: tennisJS_game.html:126 Uncaught SyntaxError: Unexpected end of input I can't seem to pinpoint the error. I have closed the function and everything else appears correct. Below is th ...

Spacing is missing between Months and Years in the Bootstrap Datepicker

Currently, I am utilizing the Bootstrap Date picker plugin from . In their example, they showcase a grid-style format with spacing between the months and years that appears quite visually appealing. However, when implementing their JavaScript and CSS file ...

Highlight particular words within a string by assigning them specific colors

WordPress is my platform of choice. Initially, I crafted an HTML template and established a class for specific words within strings, which has proven to be successful. However, I am now contemplating whether it's feasible to apply this technique afte ...

Exploring Anchor Tags in Next.js

I'm having trouble using an anchor tag in Next.js Despite not receiving any console errors when setting it up and clicking the link, the page doesn't scroll to the specified id tag. A recent GitHub issue implies that a significant amount of cus ...

How can I place two divs side by side with borders in Bootstrap 3?

I am facing a challenge with aligning some text next to a Twitter button while ensuring that they are all lined up neatly within borders. The issue I encountered is that the text div shrinks and floats to the upper left corner along with its borders, unlik ...

Responsive design challenge

I'm currently working on a WordPress theme with a fixed header and footer on the homepage, and a vertical slider in between that includes content and images. I've made the website responsive, but I'm facing an issue where the content in the ...

How to Generate HTML Reports Using JBoss?

Is there a convenient and efficient way to generate .html reports for JBoss applications that is not time-consuming? I have a database containing entities that I need to display in multiple tables. The report should include links to navigate between secti ...