bootstrap 4使警告出现在行顶部

时间:2018-02-12 18:51:31

标签: html css twitter-bootstrap bootstrap-4 twitter-bootstrap-4

我有一个警告div和一个容器内的一行,当我关闭警报行内容向上移动时。我想让警报显示在行内容上,这样当我关闭时就不会发生任何事情。

QProcess file_search_process;
QString exec = "/usr/bin/find";
QString command = exec+" /"+" -name"+QString(" *")+needle+QString("*");
qDebug() << command;
file_search_process.start(command);
file_search_process.waitForFinished(-1);
QByteArray newData=file_search_process.readAll();
QString result = QString::fromLocal8Bit(newData);

提前致谢

3 个答案:

答案 0 :(得分:1)

如果将容器设置为position:relative;

,可以使Muhammad的建议起作用

.container {position: relative;}

.alert {position: absolute; top: 0;}
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<nav class="navbar">
  <div class="navbar-brand">Brand</div>
</nav>

<div class="container">
  <h2>Alerts</h2>
  <div class="alert alert-success alert-dismissable">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
    <strong>Success!</strong> This alert box could indicate a successful or positive action.
  </div>
</div>

</body>
</html>

答案 1 :(得分:0)

您可以尝试使用jQuery来更改警报的可见性,而不是显示:

$('.alert').on('close.bs.alert', function (e) {
  e.preventDefault()
  $(this).css('visibility', 'hidden')
})

这是一个演示:
https://www.bootply.com/TazOvYZQyC

答案 2 :(得分:-1)

这样做的一种方法是添加以下CSS:

position:absolute !important;
top:0px;

到警报div。 以下是示例代码:

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Alerts</h2>
  <div class="alert alert-success alert-dismissable" style="position: absolute; top:0px;">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
    <strong>Success!</strong> This alert box could indicate a successful or positive action.
  </div>
</div>

</body>
</html>
&#13;
&#13;
&#13;