How to seperate sidebar and content?












2















I'm trying to make a side bar and a content div but I don't know how to keep them separated and the content goes under the sidebar and obviously I don't want that. I'm pretty new to coding so I don't know what to do or if there's a better way to do this.



picture
Here's the code:



<div id="content" style="margin:50px; background-color:blue; padding:10px;">
<div id="sidebar" style="margin:25px; background-color:red; width:200px; border: 2px solid lime; position:fixed;">
<p>h</p>
</div>
<div id="stuff" style="background-color:orange; margin:20px;">
<p>Lorem ipsum blah blah</p>
</div>
</div>









share|improve this question

























  • Welcome to stackoverflow. Please post code as text. This makes it easier for other users so you are more likely to get helpful answers.

    – Simon.S.A.
    Nov 25 '18 at 4:34






  • 1





    my bad. i'll update it!

    – cayden
    Nov 25 '18 at 4:35
















2















I'm trying to make a side bar and a content div but I don't know how to keep them separated and the content goes under the sidebar and obviously I don't want that. I'm pretty new to coding so I don't know what to do or if there's a better way to do this.



picture
Here's the code:



<div id="content" style="margin:50px; background-color:blue; padding:10px;">
<div id="sidebar" style="margin:25px; background-color:red; width:200px; border: 2px solid lime; position:fixed;">
<p>h</p>
</div>
<div id="stuff" style="background-color:orange; margin:20px;">
<p>Lorem ipsum blah blah</p>
</div>
</div>









share|improve this question

























  • Welcome to stackoverflow. Please post code as text. This makes it easier for other users so you are more likely to get helpful answers.

    – Simon.S.A.
    Nov 25 '18 at 4:34






  • 1





    my bad. i'll update it!

    – cayden
    Nov 25 '18 at 4:35














2












2








2








I'm trying to make a side bar and a content div but I don't know how to keep them separated and the content goes under the sidebar and obviously I don't want that. I'm pretty new to coding so I don't know what to do or if there's a better way to do this.



picture
Here's the code:



<div id="content" style="margin:50px; background-color:blue; padding:10px;">
<div id="sidebar" style="margin:25px; background-color:red; width:200px; border: 2px solid lime; position:fixed;">
<p>h</p>
</div>
<div id="stuff" style="background-color:orange; margin:20px;">
<p>Lorem ipsum blah blah</p>
</div>
</div>









share|improve this question
















I'm trying to make a side bar and a content div but I don't know how to keep them separated and the content goes under the sidebar and obviously I don't want that. I'm pretty new to coding so I don't know what to do or if there's a better way to do this.



picture
Here's the code:



<div id="content" style="margin:50px; background-color:blue; padding:10px;">
<div id="sidebar" style="margin:25px; background-color:red; width:200px; border: 2px solid lime; position:fixed;">
<p>h</p>
</div>
<div id="stuff" style="background-color:orange; margin:20px;">
<p>Lorem ipsum blah blah</p>
</div>
</div>






html css web






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 13:16









kit

1,1063816




1,1063816










asked Nov 25 '18 at 4:26









caydencayden

135




135













  • Welcome to stackoverflow. Please post code as text. This makes it easier for other users so you are more likely to get helpful answers.

    – Simon.S.A.
    Nov 25 '18 at 4:34






  • 1





    my bad. i'll update it!

    – cayden
    Nov 25 '18 at 4:35



















  • Welcome to stackoverflow. Please post code as text. This makes it easier for other users so you are more likely to get helpful answers.

    – Simon.S.A.
    Nov 25 '18 at 4:34






  • 1





    my bad. i'll update it!

    – cayden
    Nov 25 '18 at 4:35

















Welcome to stackoverflow. Please post code as text. This makes it easier for other users so you are more likely to get helpful answers.

– Simon.S.A.
Nov 25 '18 at 4:34





Welcome to stackoverflow. Please post code as text. This makes it easier for other users so you are more likely to get helpful answers.

– Simon.S.A.
Nov 25 '18 at 4:34




1




1





my bad. i'll update it!

– cayden
Nov 25 '18 at 4:35





my bad. i'll update it!

– cayden
Nov 25 '18 at 4:35












3 Answers
3






active

oldest

votes


















0














You can use display: flex at top level. It's easier to use than position: fixed or any other positioning strategies.






#content {
margin: 20px 0;
padding: 10px;
background: blue;
display: flex;
}

#content #sidebar {
background: red;
width: 150px;
border: 2px solid lime;
padding: 10px;
}

#content #stuff {
background-color: orange;
flex: 1;
margin-left: 10px;
padding: 10px;
}

<div id="content">
<div id="sidebar" style="">
<p>h</p>
</div>
<div id="stuff" style="">
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
<p>Lorem ipsum blah blah</p>
</div>
</div>








share|improve this answer































    0














    Instead of position:fixed do position:relative for the sidebar. This will prevent the text from going under the sidebar.
    If you want the sidebar to occupy the full width of the parent container you could do height: 100%.



    I would also suggest that you keep the style and html separated. Either inside a <script></script> tag or in another file.






    share|improve this answer































      0














      remove position: fixed. This property is used to position an element at a particular location on the browser window, yet you are not providing any position properties to support it.



      Add display: inline-block css properties to the sidebar and stuff divs if you want to allow the content of the other div to wrap around the sidebar.






      share|improve this answer

























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464648%2fhow-to-seperate-sidebar-and-content%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        You can use display: flex at top level. It's easier to use than position: fixed or any other positioning strategies.






        #content {
        margin: 20px 0;
        padding: 10px;
        background: blue;
        display: flex;
        }

        #content #sidebar {
        background: red;
        width: 150px;
        border: 2px solid lime;
        padding: 10px;
        }

        #content #stuff {
        background-color: orange;
        flex: 1;
        margin-left: 10px;
        padding: 10px;
        }

        <div id="content">
        <div id="sidebar" style="">
        <p>h</p>
        </div>
        <div id="stuff" style="">
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        <p>Lorem ipsum blah blah</p>
        </div>
        </div>








        share|improve this answer




























          0














          You can use display: flex at top level. It's easier to use than position: fixed or any other positioning strategies.






          #content {
          margin: 20px 0;
          padding: 10px;
          background: blue;
          display: flex;
          }

          #content #sidebar {
          background: red;
          width: 150px;
          border: 2px solid lime;
          padding: 10px;
          }

          #content #stuff {
          background-color: orange;
          flex: 1;
          margin-left: 10px;
          padding: 10px;
          }

          <div id="content">
          <div id="sidebar" style="">
          <p>h</p>
          </div>
          <div id="stuff" style="">
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          <p>Lorem ipsum blah blah</p>
          </div>
          </div>








          share|improve this answer


























            0












            0








            0







            You can use display: flex at top level. It's easier to use than position: fixed or any other positioning strategies.






            #content {
            margin: 20px 0;
            padding: 10px;
            background: blue;
            display: flex;
            }

            #content #sidebar {
            background: red;
            width: 150px;
            border: 2px solid lime;
            padding: 10px;
            }

            #content #stuff {
            background-color: orange;
            flex: 1;
            margin-left: 10px;
            padding: 10px;
            }

            <div id="content">
            <div id="sidebar" style="">
            <p>h</p>
            </div>
            <div id="stuff" style="">
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            </div>
            </div>








            share|improve this answer













            You can use display: flex at top level. It's easier to use than position: fixed or any other positioning strategies.






            #content {
            margin: 20px 0;
            padding: 10px;
            background: blue;
            display: flex;
            }

            #content #sidebar {
            background: red;
            width: 150px;
            border: 2px solid lime;
            padding: 10px;
            }

            #content #stuff {
            background-color: orange;
            flex: 1;
            margin-left: 10px;
            padding: 10px;
            }

            <div id="content">
            <div id="sidebar" style="">
            <p>h</p>
            </div>
            <div id="stuff" style="">
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            </div>
            </div>








            #content {
            margin: 20px 0;
            padding: 10px;
            background: blue;
            display: flex;
            }

            #content #sidebar {
            background: red;
            width: 150px;
            border: 2px solid lime;
            padding: 10px;
            }

            #content #stuff {
            background-color: orange;
            flex: 1;
            margin-left: 10px;
            padding: 10px;
            }

            <div id="content">
            <div id="sidebar" style="">
            <p>h</p>
            </div>
            <div id="stuff" style="">
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            </div>
            </div>





            #content {
            margin: 20px 0;
            padding: 10px;
            background: blue;
            display: flex;
            }

            #content #sidebar {
            background: red;
            width: 150px;
            border: 2px solid lime;
            padding: 10px;
            }

            #content #stuff {
            background-color: orange;
            flex: 1;
            margin-left: 10px;
            padding: 10px;
            }

            <div id="content">
            <div id="sidebar" style="">
            <p>h</p>
            </div>
            <div id="stuff" style="">
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            <p>Lorem ipsum blah blah</p>
            </div>
            </div>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 25 '18 at 4:54









            Dinesh PandiyanDinesh Pandiyan

            2,6161926




            2,6161926

























                0














                Instead of position:fixed do position:relative for the sidebar. This will prevent the text from going under the sidebar.
                If you want the sidebar to occupy the full width of the parent container you could do height: 100%.



                I would also suggest that you keep the style and html separated. Either inside a <script></script> tag or in another file.






                share|improve this answer




























                  0














                  Instead of position:fixed do position:relative for the sidebar. This will prevent the text from going under the sidebar.
                  If you want the sidebar to occupy the full width of the parent container you could do height: 100%.



                  I would also suggest that you keep the style and html separated. Either inside a <script></script> tag or in another file.






                  share|improve this answer


























                    0












                    0








                    0







                    Instead of position:fixed do position:relative for the sidebar. This will prevent the text from going under the sidebar.
                    If you want the sidebar to occupy the full width of the parent container you could do height: 100%.



                    I would also suggest that you keep the style and html separated. Either inside a <script></script> tag or in another file.






                    share|improve this answer













                    Instead of position:fixed do position:relative for the sidebar. This will prevent the text from going under the sidebar.
                    If you want the sidebar to occupy the full width of the parent container you could do height: 100%.



                    I would also suggest that you keep the style and html separated. Either inside a <script></script> tag or in another file.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 25 '18 at 4:37









                    Enes T.Enes T.

                    506




                    506























                        0














                        remove position: fixed. This property is used to position an element at a particular location on the browser window, yet you are not providing any position properties to support it.



                        Add display: inline-block css properties to the sidebar and stuff divs if you want to allow the content of the other div to wrap around the sidebar.






                        share|improve this answer






























                          0














                          remove position: fixed. This property is used to position an element at a particular location on the browser window, yet you are not providing any position properties to support it.



                          Add display: inline-block css properties to the sidebar and stuff divs if you want to allow the content of the other div to wrap around the sidebar.






                          share|improve this answer




























                            0












                            0








                            0







                            remove position: fixed. This property is used to position an element at a particular location on the browser window, yet you are not providing any position properties to support it.



                            Add display: inline-block css properties to the sidebar and stuff divs if you want to allow the content of the other div to wrap around the sidebar.






                            share|improve this answer















                            remove position: fixed. This property is used to position an element at a particular location on the browser window, yet you are not providing any position properties to support it.



                            Add display: inline-block css properties to the sidebar and stuff divs if you want to allow the content of the other div to wrap around the sidebar.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 25 '18 at 5:12

























                            answered Nov 25 '18 at 4:41









                            tshimkustshimkus

                            807919




                            807919






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464648%2fhow-to-seperate-sidebar-and-content%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                404 Error Contact Form 7 ajax form submitting

                                How to know if a Active Directory user can login interactively

                                TypeError: fit_transform() missing 1 required positional argument: 'X'