gpt4 book ai didi

html - CSS:内容居中,左对齐背景图片

转载 作者:行者123 更新时间:2023-11-28 17:38:01 24 4
gpt4 key购买 nike

我需要实现以下布局:

enter image description here

content wrapper 有一个固定的大小并且居中:

.content
{
width:960px;
margin:0px auto;
}

问题是,如何实现子导航中的左对齐背景栏(见箭头)?

我不想使用 javascript + onresize 之类的。有什么想法吗?

谢谢

我的标记看起来像

标准页面布局

<div class="wrapper">
<header class="header">
<strong>Header:</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tortor. Praesent dictum, libero ut tempus dictum, neque eros elementum mauris, quis mollis arcu velit ac diam. Etiam neque. Quisque nec turpis. Aliquam arcu nulla, dictum et, lacinia a, mollis in, ante. Sed eu felis in elit tempor venenatis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut ultricies porttitor purus. Proin non tellus at ligula fringilla tristique. Fusce vehicula quam. Curabitur vel tortor vitae pede imperdiet ultrices. Sed tortor.
</header><!-- .header-->
<main class="content">
<strong>Content:</strong> Sed placerat accumsan ligula. Aliquam felis magna, congue quis, tempus eu, aliquam vitae, ante. Cras neque justo, ultrices at, rhoncus a, facilisis eget, nisl. Quisque vitae pede. Nam et augue. Sed a elit. Ut vel massa. Suspendisse nibh pede, ultrices vitae, ultrices nec, mollis non, nibh. In sit amet pede quis leo vulputate hendrerit. Cras laoreet leo et justo auctor condimentum. Integer id enim. Suspendisse egestas, dui ac egestas mollis, libero orci hendrerit lacus, et malesuada lorem neque ac libero. Morbi tempor pulvinar pede. Donec vel elit.
</main><!-- .content -->
<footer class="footer">
<strong>Footer:</strong> Mus elit Morbi mus enim lacus at quis Nam eget morbi. Et semper urna urna non at cursus dolor vestibulum neque enim. Tellus interdum at laoreet laoreet lacinia lacinia sed Quisque justo quis. Hendrerit scelerisque lorem elit orci tempor tincidunt enim Phasellus dignissim tincidunt. Nunc vel et Sed nisl Vestibulum odio montes Aliquam volutpat pellentesque. Ut pede sagittis et quis nunc gravida porttitor ligula.
</footer><!-- .footer -->

.wrapper {
width: 960px;
margin: 0 auto;
min-height: 100%;
height: auto !important;
height: 100%;
}


/* Header
-----------------------------------------------------------------------------*/
.header {
height: 47px;
background: #FFE680;
}


/* Middle
-----------------------------------------------------------------------------*/
.content {
padding: 0 0 100px;
}




/* Footer
-----------------------------------------------------------------------------*/
.footer {
width: 960px;
margin: -100px auto 0;
height: 100px;
background: #BFF08E;
position: relative;
}

最佳答案

你可以试试this

HTML

<div class="outer">
<div class="bar">test</div>
<div class="cnt">Test</div>
</div>

CSS

* {margin: 0}
.bar {
background: #ccc;
margin-right: calc((100% - 960px)/2)
}
.cnt {
background: yellow;
min-height: 600px;
width: 960px;
margin: 0 auto
}

关于html - CSS:内容居中,左对齐背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24734696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com