gpt4 book ai didi

css - 创建 Bootstrap 响应式布局时如何设置容器 div 的宽度?

转载 作者:技术小花猫 更新时间:2023-10-29 11:08:15 26 4
gpt4 key购买 nike

我正在尝试制作 Bootstrap 响应式布局。这里我正在尝试的是缩短主容器 div 的宽度。我尝试设置内联宽度,但布局失去了响应性。当我检查 bootstrap.css 时,容器 div 的宽度是自动的。如果有人能揭示这背后的逻辑,我将不胜感激。以下是 bootstrap 的演示代码。

PS - 我不想缩短 navbar-fixed 类的宽度,我只是想缩短容器的宽度而不失去响应能力。

HTML

<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Project name</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>

<div class="container" >

<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
<h1>Hello, world!</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
</div>

<!-- Example row of columns -->
<div class="row">
<div class="span4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
</div>

<hr>

<footer>
<p>&copy; Company 2012</p>
</footer>

</div>

CSS

  .container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
width: 1170px;
}
.container {
width: auto;
}

截图

Screenshot http://img442.imageshack.us/img442/7074/testjxk.jpg

最佳答案

在 bootstrap-responsive.css 文件中,您会找到代码块,称为媒体查询,例如

@media (max-width: 480px) {
/* Your CSS here */
}

@media (min-width: 768px) and (max-width: 980px) {
/* Your CSS here */
}

您可以将内容区域的宽度设置为这些 block 内每个屏幕宽度的适当宽度,而不会影响其他 block 。

关于css - 创建 Bootstrap 响应式布局时如何设置容器 div 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11609231/

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