无论屏幕大小如何,都要在屏幕内部调整内容 - Bootstrap

时间:2018-04-11 18:58:06

标签: javascript html css twitter-bootstrap

在我的页面中,我有一个页眉,一个页脚和一个容器id="item",其中包含四个项目及其徽标的列表。我正在尝试根据屏幕大小调整item容器响应,以便整个页面始终适合屏幕,我不必滚动任何屏幕大小。

但我不确定如何使item容器响应,包括基于屏幕大小的徽标。我已经尝试了几种选择,但它们似乎都没有完美运作。

这是我到目前为止所做的。提前感谢您的建议:

这是fiddle

html,
body {
	width: 100%;
	height: 100%;
	min-height: 100%;
	background: #66B34E;
	color: #efefef;
}

.container {
	max-width: unset;
}

.title {
	background: #187be1;
	padding: 20px;
	width: 100%;
	font-size: 11px;
	color: aliceblue;
	bottom: 0px;
	right: 0px;
	left: 0px;
	text-align: center;
	text-decoration: none;
	margin-top: 7px;
	margin-bottom: 50px;
}

.list {
	max-height: 60%;
	max-width: 100%;
}

.menu {
	background: #f8f8f8;
	border-radius: 0;
	box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
	padding: 20px;
	width: 100%;
	font-size: 11px;
	color: black;
	bottom: 0px;
	right: 0px;
	left: 0px;
	text-align: center;
	text-decoration: none;
}

.footer {
	position: fixed;
	box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
	left: 0;
	bottom: 0;
	right: 0;
	width: 100%;
	background-color: #434A54;
	text-align: center;
	font-size: 12px;
	padding-top: 7px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container title"><br>This is the header<br><br></div>
<div class="container list" id="item">
   <div class="container">
      <div class="row">
         <div class="col-6 menu"> <img src="https://www.google.co.uk/images/srpr/logo11w.png"/> <br>
            Item 1
         </div>
         <div class="col-6 menu"><img src="https://www.google.co.uk/images/srpr/logo11w.png"/><br>
            Item 2
         </div>
      </div>
      <div class="row">
         <div class="col-6 menu"><img src="https://www.google.co.uk/images/srpr/logo11w.png"/><br>
            Item 3
         </div>
         <div class="col-6 menu"><img src="https://www.google.co.uk/images/srpr/logo11w.png"/><br>
            Item 4
         </div>
      </div>
   </div>
</div>
<div class="container footer"><br>
   This is the footer<br>
</div>

3 个答案:

答案 0 :(得分:2)

#item应该已经响应窗口了。尝试添加

#item img {
    max-width: 100%;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #66B34E;
  color: #efefef;
}

.container {
  max-width: unset;
}

.title {
  background: #187be1;
  padding: 20px;
  width: 100%;
  font-size: 11px;
  color: aliceblue;
  bottom: 0px;
  right: 0px;
  left: 0px;
  text-align: center;
  text-decoration: none;
  margin-top: 7px;
  margin-bottom: 50px;
}

.list {
  max-height: 60%;
  max-width: 100%;
}

.menu {
  background: #f8f8f8;
  border-radius: 0;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  padding: 20px;
  width: 100%;
  font-size: 11px;
  color: black;
  bottom: 0px;
  right: 0px;
  left: 0px;
  text-align: center;
  text-decoration: none;
}

#item img {
  max-width: 100%;
}

.footer {
  position: fixed;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  left: 0;
  bottom: 0;
  right: 0;
  width: 100%;
  background-color: #434A54;
  text-align: center;
  font-size: 12px;
  padding-top: 7px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container title"><br>This is the header<br><br></div>
<div class="container list" id="item">
  <div class="container">
    <div class="row">
      <div class="col-6 menu"> <img src="https://www.google.co.uk/images/srpr/logo11w.png" /> <br> Item 1
      </div>
      <div class="col-6 menu"><img src="https://www.google.co.uk/images/srpr/logo11w.png" /><br> Item 2
      </div>
    </div>
    <div class="row">
      <div class="col-6 menu"><img src="https://www.google.co.uk/images/srpr/logo11w.png" /><br> Item 3
      </div>
      <div class="col-6 menu"><img src="https://www.google.co.uk/images/srpr/logo11w.png" /><br> Item 4
      </div>
    </div>
  </div>
</div>
<div class="container footer"><br> This is the footer<br>
</div>

答案 1 :(得分:0)

要获得完整尺寸的#item容器,您应该为.container切换.d-flex.container默认设置padding max-width .d-flex,而img-fluid没有{。}}。

您还可以将类 html, body { width: 100%; height: 100%; min-height: 100%; background: #66B34E; color: #efefef; } .title { align-items: center; background: #187be1; height: 80px; width: 100%; font-size: 11px; color: aliceblue; justify-content: center; text-decoration: none; margin-top: 7px; margin-bottom: 50px; } .list { height: calc(100vh - 187px); background: red; } .menu { background: #f8f8f8; border-radius: 0; box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); padding: 20px; font-size: 11px; color: black; text-align: center; text-decoration: none; } .footer { color: white; align-items: center; position: fixed; height: 50px; box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); left: 0; bottom: 0; right: 0; width: 100%; background-color: #434A54; justify-content: center; font-size: 12px; }添加到您的所有徽标中,并使其适合其容器。

我将这些更正添加到小提琴中。

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex title"><br>This is the header<br><br></div>
<div class="list d-flex align-items-stretch row" id="item">
         <div class="col-6 align-items-center d-flex menu">
         <figure>
         <img src="https://www.google.co.uk/images/srpr/logo11w.png" class="img-fluid"/> <br>
            Item 1</figure>
         </div>
         
         <div class="col-6 align-items-center d-flex menu">
         <figure>
         <img src="https://www.google.co.uk/images/srpr/logo11w.png" class="img-fluid"/><br>
            Item 2</figure>
         </div>
         
         <div class="col-6 align-items-center d-flex menu">
         <figure>
         <img src="https://www.google.co.uk/images/srpr/logo11w.png" class="img-fluid"/><br>
            Item 3</figure>
         </div>
         
         <div class="col-6 align-items-center d-flex menu">
         <figure>
         <img src="https://www.google.co.uk/images/srpr/logo11w.png" class="img-fluid"/><br>
            Item 4</figure>
         </div>
         
      </div>
<div class="d-flex footer">
   This is the footer
</div>
matches

答案 2 :(得分:0)

您可以使用display:table和display:table-cell属性获得所需的结果。试试这段代码。

<li class='navUsernameLi'>
<div class="inner">
  <img class='navProfilePicture' src='http://via.placeholder.com/350x150'>
  <p class='navUsernameP'>Username</p>
  </div>
</li>

.navUsernameLi {
  float: right;
  margin-top: 10px;
}
.inner {
  display: table;
}

.navProfilePicture {
  display: table-cell;
  border-radius: 50px;
  vertical-align: inherit;
  height: 24px;
  width: 24px;
  vertical-align: middle;
}
.navUsernameP {
  display: table-cell;
  vertical-align: middle;
}