在我的面板中,我希望在页面大小为<时将所有文本设置为居中对齐。 768,但我的媒体查询无法使文本居中。这是我的Fiddle
@@media all and (min-width : 768px) {
.text-left {
text-align: center;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Messages</a></li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group input-group">
<input type="text" class="form-control" placeholder="Search..">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> My Account</a></li>
</ul>
</div>
</div>
</nav>
<div class="container text-center">
<div class="row">
<div class="col-sm-3 well">
<div class="well">
<p><a href="#">My Profile</a></p>
<img src="bird.jpg" class="img-circle" height="65" width="65" alt="Avatar">
</div>
<div class="well">
<p><a href="#">Interests</a></p>
<p>
<span class="label label-default">News</span>
<span class="label label-primary">W3Schools</span>
<span class="label label-success">Labels</span>
<span class="label label-info">Football</span>
<span class="label label-warning">Gaming</span>
<span class="label label-danger">Friends</span>
</p>
</div>
<div class="alert alert-success fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<p><strong>Ey!</strong></p>
People are looking at your profile. Find out who.
</div>
<p><a href="#">Link</a></p>
<p><a href="#">Link</a></p>
<p><a href="#">Link</a></p>
</div>
<div class="col-sm-7">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default text-left">
<div class="panel-body">
<p contenteditable="true">Status: Feeling Blue</p>
<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-thumbs-up"></span> Like
</button>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="well">
<p>John</p>
<img src="bird.jpg" class="img-circle" height="55" width="55" alt="Avatar">
</div>
</div>
<div class="col-sm-9">
<div class="well">
<p>Just Forgot that I had to mention something about someone to someone about how I forgot something, but now I forgot it. Ahh, forget it! Or wait. I remember.... no I don't.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="well">
<p>Bo</p>
<img src="bandmember.jpg" class="img-circle" height="55" width="55" alt="Avatar">
</div>
</div>
<div class="col-sm-9">
<div class="well">
<p>Just Forgot that I had to mention something about someone to someone about how I forgot something, but now I forgot it. Ahh, forget it! Or wait. I remember.... no I don't.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="well">
<p>Jane</p>
<img src="bandmember.jpg" class="img-circle" height="55" width="55" alt="Avatar">
</div>
</div>
<div class="col-sm-9">
<div class="well">
<p>Just Forgot that I had to mention something about someone to someone about how I forgot something, but now I forgot it. Ahh, forget it! Or wait. I remember.... no I don't.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="well">
<p>Anja</p>
<img src="bird.jpg" class="img-circle" height="55" width="55" alt="Avatar">
</div>
</div>
<div class="col-sm-9">
<div class="well">
<p>Just Forgot that I had to mention something about someone to someone about how I forgot something, but now I forgot it. Ahh, forget it! Or wait. I remember.... no I don't.</p>
</div>
</div>
</div>
</div>
<div class="col-sm-2 well">
<div class="thumbnail">
<p>Upcoming Events:</p>
<img src="paris.jpg" alt="Paris" width="400" height="300">
<p><strong>Paris</strong></p>
<p>Fri. 27 November 2015</p>
<button class="btn btn-primary">Info</button>
</div>
<div class="well">
<p>ADS</p>
</div>
<div class="well">
<p>ADS</p>
</div>
</div>
</div>
</div>
UPDATE! - 我将媒体查询设置为
@@media only screen and (max-width : 767px) {
.text-left {
text-align: center;
}
}
当我打开Chrome时,它运行正常。但是如果我打开IE 11时,默认窗口大小约为900px,文本居中(不好)。仅供参考 - 如果我做一个小窗口调整文本重新调整到左边!这是一个奇怪的IE漏洞吗?
答案 0 :(得分:2)
对于小型设备您无法使用min-width
。
您可以指定所有最低和最高的最佳方式。
@media all and (max-width: ***px) and (min-width: ***px){ }
更多示例:
@media only screen and (min-width: 768px) {
/* Tablets and Desktop */
}
@media only screen and (max-width: 767px) {
/* Phones */
}
@media only screen and (max-width: 767px) and (orientation: portrait) {
/* Portrait Phones */
}
您是否担心所有和仅屏幕?
此外,您可以阅读一些关于此的Stackoverflow Q:
更新IE -11问题的答案
Stackoverflow上的相同问题 Link_1 Link_2
<强>解决方案:强>
@media all and (max-width: ***px) {
//Media Query CSS
}
答案 1 :(得分:1)
@media all and (max-width : 768px) {
.text-left {
text-align: center;
}
}
答案 2 :(得分:1)
不是@@media
,而是@media
。
@media all and (min-width: 768px) {
.text-left {
text-align: center;
}
}
答案 3 :(得分:1)
您是否设置了视口元标记?
<meta name="viewport" content="width=device-width, initial-scale=1">
此标记未设置,媒体查询无法预测。