Centered div and fluid left padding over the container

半世苍凉 提交于 2019-12-10 23:23:31

问题


I have a centered red div (blue) with a max width (1240px) in my layout and I search to make this in CSS. The logo area (purple) from the left of the centering area (blue) is 300px. At the left of this point, in red, it will be fluid (whatever the screen resolution you have).

(btw, that's the same thing for the lightgray div just below)

Do you have an idea to do that?

<header>
   <div id="logo">
      <div class="w">
         <a href="#">Website name</a>
      </div>
   </div>

   <div class="wrap">
      <div class="r">
         <nav id="menu">
            <ul>
               <li><a href="#">link</a></li>
               <li><a href="#">link</a></li>
               <li><a href="#">link</a></li>
            </ul>
         </nav>
         <nav id="social">
            <ul>
               <li><a href="#">link</a></li>
               <li><a href="#">link</a></li>
            </ul>
         </nav>
      </div>
   </div>
</header>

回答1:


Not exactly sure what you are after other than something that depends on the window size or resolution, so, does using percentages help here? You might know this allright but you can use percentages in css, in margins and paddings and widths and so on. This is directly dependent on the window size or resolution and scales?

http://mattsnider.com/css-using-percent-for-margin-and-padding/




回答2:


Solved with a :before pseudo-class on the #logo element.

#logo:before{content:""; position:absolute; top:0; right:100%; width:1000%; height:100%; background:red;}

http://jsfiddle.net/Flayks/fUf2z/



来源:https://stackoverflow.com/questions/17638475/centered-div-and-fluid-left-padding-over-the-container

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