简体   繁体   中英

CSS canvas and navigation bar positioning

I've a navigation bar which is fixed position on the top, and a canvas. The top of my canvas gets hidden behind the navigation bar. I don't want to make canvas position absolute. I've to get my canvas below the navigation bar and in the center horizontally. To center it I put it in tag center>, but I can't get it below navigation bar, How can I get it done? my style sheet:

 CSS
    #nav{
        position:fixed;
        margin:0px;
        display:block;
        }
    #canvas{
        text-align:center;
        background-color:transparent;
        border: 2px solid black;
        display:block;
        }
    HTML
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <link href="IV.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <nav>


    <div id = "toolbar_effects">

    <input type="image" src="Icons/imageviewer.svg" width="50" height="50" id="Imageviewer2"class = "s">
    <input type="image" src="Icons/effect-grayscale.svg" width="50" height="50" id="grayscale"class = "s">
    </div>
    </nav>
    <center><canvas id = "canvas" width="600" height="400"><center>
    </canvas>
    </body>
    </html>

Use z index in css on your navigation https://css-tricks.com/almanac/properties/z/z-index/

Without that by default elements that are later in code are higher in structure.

Set padding-top to the body. And don't use center tags it is deprecated. It works http://jsfiddle.net/soov7k2k/ . You probably forgot to position your navbar properly! position: fixed is half of the work. You need to add top:0 and left:0 to your navbar otherwhise it won't work. See the fiddle.

body {
padding-top: 100px;//Or whatever the height of your navbar is.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM