开发者

CSS Frames, my content does not obey the frame limitations

开发者 https://www.devze.com 2023-01-30 08:08 出处:网络
I am trying to create a CSS Frame where I have a small left frame and a large right frame. I want to put a logo and some misc links on the left.

I am trying to create a CSS Frame where I have a small left frame and a large right frame.

I want to put a logo and some misc links on the left.

I want to put navigation and content on the right.

When I add content to the left side it pushes the content on the right down to the lowest point. I used an example CSS frame page to start.

Here is an example link: http://6colors.co/test/

I want the Media Room and About links to be at the top of the right frame and I just don't see it.

An HTML snippet:

<!-- Left Frame -->
<div id="framecontentLeft">
    <div class="innertube">
        <header>  
        <hgroup>
        <div class="FloatingBox">
                    <h1>6&nbsp;&nbsp;
            <span class="AppleGreen">C</span>&nbsp;&nbsp;
            <span class="AppleYellow">o</span>&nbsp;&nbsp;
            <span class="AppleOrange">l</span>&nbsp;&nbsp;
            <span class="AppleRed">o</span>&nbsp;&nbsp;
            <span class="ApplePurple">r</span>&nbsp;&nbsp;
            <span class="AppleBlue">s</span>&nbsp;&nbsp;
        </h1>  

        <h2>
            A&nbsp;
            <span class="AppleBlue">Nostalgic</span>
            <span class="ApplePurple">Trip</span>
            <span class="AppleRed">Down</span>
            <span class="AppleOrange">Memory</span> 
            <span class="AppleYellow">Lane</span>.
        </h2>
        </div>

                <br /><br /><br /><br /><br /><br />
                <a class="AppleRed" href="#">Have Footage To Submit?</a>

        <br /><br /><br /><br />
            <a class="AppleRed" href="#">Need To Contact Us?</a>
    </hgroup>  
     </header>
 </div>
</div>

<!-- Right Frame -->
<div id="maincontent">
    <div class="innertube">

    <?php include('includes/menu.inc'); ?>

    </div>
</div>

Here is the CSS:

/* v1.0 | 20080212 */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    /* vertical-align: baseline; */
    background: transparent;
}

body {
    margin: 0;
    padding: 0;
    border: 0;
    line-height: 2;
    background-image: url('images/background.png');
    /*width: 90%; */
    over开发者_StackOverflowflow: hidden;
    height: 100%; 
    max-height: 100%; 
}

.framecontentLeft, .framecontentRight{
   position: absolute; 
    top: 0; 
left: 0; 
width: 200px; /*Width of left frame div*/
height: 100%;
overflow: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
background-color: navy;
color: white;
}

.framecontentRight{
left: auto;
right: 0; 
width: 150px; /*Width of right frame div*/
overflow: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
background-color: #fff;
color: #fff;
}

.maincontent{
position: absolute; 
top: 0;
left: 200px; /*Set left value to WidthOfLeftFrameDiv*/
/*right: 150px; */ /*Set right value to WidthOfRightFrameDiv*/
bottom: 0;
overflow: auto; 
background: #fff;
}

.innertube{
   margin: 15px; /*Margins for inner DIV inside each DIV (to provide padding)*/
}

* html body{ /*IE6 hack*/
    padding: 0 0 0 200px; /*Set value to (0 WidthOfRightFrameDiv 0 WidthOfLeftFrameDiv)*/
}

* html #maincontent{ /*IE6 hack*/
height: 100%; 
width: 100%; 
}

Can anyone help me understand how to fix this and achieve what I want?


The first thing that I noticed was that you have <div id="maincontent"> in the markup but .maincontent in the styling which would target <div class="maincontent">

I wouldn't use position absolute for this.


Please, do yourself a favour, and get rid of absolute positioning..
What you could do in this particular case, is to float left the side menu and keep the main content layer as a normal static positioned div, just adding an appropriate left margin.
See the example code below:

Markup:

<body>
<div id="container">
    <div id="sidemenu">some content</div>
    <div id="maincontent">blah blah blah</div>
</div>
</body>

Style:

* { /* jolly selector '*' applies the following rules to all elements */
    margin: 0;
    padding: 0;
}
body {
    background: #CCC; /* whatever background you see fit */
}
#container {
    width: 100%;
    float: left;
    display: inline; /* IE fix */
}
#sidemenu { /* this layer is floated LEFT */
    float: left;
    display: inline; /* IE fix */
    width: 200px;
    background: #DDD;
}
#maincontent { /* this layer is a plain fixed-position div */
    margin-left: 220px; /* the margin makes it align correctly with the left 'frame' */
}
0

精彩评论

暂无评论...
验证码 换一张
取 消