Three horizontal stripes in CSS

主宰稳场 提交于 2019-12-08 10:32:45

问题


I've created three horizontal stripes to create an extended flag that will run at the top of my page:

CSS

#main1 div{
width: auto;
height: 20px;
margin: 0px

HTML

<div id="main1">
<div style="background-color:red;"></div>
<div style="background-color:blue;"></div>
<div style="background-color:orange;"></div>

How to get it to stick right up to the edge of the browser? (as in no gaps on the left right or top)

And also is there any easier / better way I could have done this Keep in mind I'm very much a novice

Your help is much appreciated! Thanks


回答1:


Remove any margin and padding from html and body elements, then use a single div with a linear-gradient as a background

Example: http://codepen.io/anon/pen/rOxEgJ

html, body { margin: 0; padding: 0 }


#flag {
   height : 100px;
   width  : 100%;
   background: linear-gradient(to bottom, 
       red    0%, red  33.33%, 
       blue   0%, blue 66.66%,        
       orange 0%);
}


来源:https://stackoverflow.com/questions/32607835/three-horizontal-stripes-in-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!