【问题标题】:image with bootstrap, breaking column/div带引导程序的图像,打破列/ div
【发布时间】:2018-09-13 19:46:35
【问题描述】:

我已经构建了一个 CMS,但在使用 TinyMCE 和 Bootstrap 时遇到了一些问题。

我有一个页面,其中概述了 div,如果用户单击 div,他们可以从模式中选择图像。图像被插入到 tinymce 实例中,当用户点击“保存”时,它会使用 html(来自 tinymce)保存到数据库中,但也会添加到 div 中以供预览。

我需要帮助找到一种方法来确保无论图像有多大,它都包含在引导列中。

空的div:

添加大图后

我可以在此处的 html 中使用一些东西来进行引导,即使在 tinyMce 中放入巨大的图像,它也不会破坏 div?

<html>

<head>
  <title>Template One</title>

  <style type="text/css">
    @import "style.css";
    html,
    body {
      height: 100%;
      overflow: hidden;
    }
    
    .modal-lg {
      max-width: 80% !important;
    }
    
    .my-container {
      display: flex;
      flex-direction: column;
      height: 100%;
    }
    
    .my-container>.top [class^="col-"],
    .my-container>.bottom [class^="col-"] {
      background-color: #929292;
      color: white;
      text-align: center;
    }
    
    .my-container>.middle {
      flex-grow: 1;
      padding: 30px;
      background-size: cover;
    }
    
    .my-container>.middle>* {}
    
    #clock {
      /*background-color:#333;*/
      font-family: sans-serif;
      font-size: 40px;
      text-shadow: 0px 0px 1px #fff;
      color: #fff;
    }
    
    #clock span {
      color: #fff;
      font-size: 40px;
      position: relative;
    }
    
    #date {
      margin-top: -10px;
      letter-spacing: 3px;
      font-size: 20px;
      font-family: arial, sans-serif;
      color: #fff;
    }
    
    .buttonContainer {
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
  </style>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css" crossorigin="anonymous">
  <link href="https://cdn.jsdelivr.net/npm/gijgo@1.9.6/css/gijgo.min.css" rel="stylesheet" type="text/css" />
  <link href="https://rawgit.com/tempusdominus/bootstrap-4/master/build/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link href="src/ytv.css" type="text/css" rel="stylesheet" />

  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.0/moment-with-locales.js"></script>
  <script src="https://rawgit.com/tempusdominus/bootstrap-4/master/build/js/tempusdominus-bootstrap-4.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/gijgo@1.9.6/js/gijgo.min.js" type="text/javascript"></script>
  <script type='text/javascript' src='//cdn.jsdelivr.net/jquery.marquee/1.4.0/jquery.marquee.min.js'></script>


</head>

<body>

  <div class="container-fluid my-container">
    <div class="row middle">
      <div class="col-lg-6 leftFifty" id="leftFifty">
        <div class="leftContent" style="background-color: white; height: 100%; border: dotted 1px black;">
          <!-- This is the div that is clicked in to select an image -->
        </div>
      </div>
      <div class="col-lg-6 rightFifty" id="rightFifty">
        <div class="rightContent" style="background-color: white; height: 100%; border: dotted 1px black; ">
          <!-- This is the div that is clicked in to select an image -->
        </div>
      </div>
    </div>
  </div>
</body>

</html>

【问题讨论】:

  • 图片是img标签还是背景图片?
  • 它们有一个图像标签,因为这是 TinyMCE 保存它们的方式。但有时这将是文本而不是图像,因此我无法明确创建图像标签,尽管我可以说“如果 img,那么...”

标签: html css bootstrap-4 tinymce


【解决方案1】:

其实你只需要设置width: 100%;高度可以是auto 或完全省略以保持纵横比。

img {
  width: 100%;
  height: auto;
}
<html>

<head>
  <title>Template One</title>

  <style type="text/css">
    @import "style.css";
    html,
    body {
      height: 100%;
      overflow: hidden;
    }
    
    .modal-lg {
      max-width: 80% !important;
    }
    
    .my-container {
      display: flex;
      flex-direction: column;
      height: 100%;
    }
    
    .my-container>.top [class^="col-"],
    .my-container>.bottom [class^="col-"] {
      background-color: #929292;
      color: white;
      text-align: center;
    }
    
    .my-container>.middle {
      flex-grow: 1;
      padding: 30px;
      background-size: cover;
    }
    
    .my-container>.middle>* {}
    
    #clock {
      /*background-color:#333;*/
      font-family: sans-serif;
      font-size: 40px;
      text-shadow: 0px 0px 1px #fff;
      color: #fff;
    }
    
    #clock span {
      color: #fff;
      font-size: 40px;
      position: relative;
    }
    
    #date {
      margin-top: -10px;
      letter-spacing: 3px;
      font-size: 20px;
      font-family: arial, sans-serif;
      color: #fff;
    }
    
    .buttonContainer {
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
  </style>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css" crossorigin="anonymous">
  <link href="https://cdn.jsdelivr.net/npm/gijgo@1.9.6/css/gijgo.min.css" rel="stylesheet" type="text/css" />
  <link href="https://rawgit.com/tempusdominus/bootstrap-4/master/build/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link href="src/ytv.css" type="text/css" rel="stylesheet" />

  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.0/moment-with-locales.js"></script>
  <script src="https://rawgit.com/tempusdominus/bootstrap-4/master/build/js/tempusdominus-bootstrap-4.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/gijgo@1.9.6/js/gijgo.min.js" type="text/javascript"></script>
  <script type='text/javascript' src='//cdn.jsdelivr.net/jquery.marquee/1.4.0/jquery.marquee.min.js'></script>


</head>

<body>

  <div class="container-fluid my-container">
    <div class="row middle">
      <div class="col-lg-6 leftFifty" id="leftFifty">
        <div class="leftContent" style="background-color: white; height: 100%; border: dotted 1px black;">
          <img src="https://via.placeholder.com/600x250" />
          <!-- This is the div that is clicked in to select an image -->
        </div>
      </div>
      <div class="col-lg-6 rightFifty" id="rightFifty">
        <div class="rightContent" style="background-color: white; height: 100%; border: dotted 1px black; ">
          <!-- This is the div that is clicked in to select an image -->
        </div>
      </div>
    </div>
  </div>
</body>

</html>

【讨论】:

  • 哇,这实际上解决了这个问题,但我在右侧 div 中放了另一张更高更宽的图片,但它仍然超出了高度
  • 所以左边的图像是 1800x824 并且很合适,我测试的右边的 div 图像是 1024 x 942 并且它的宽度被包含但底部超出了虚线
  • 可能是因为我在这个 .row-middle 的上方和下方都有行吗?
  • 在小提琴中,如果我做 1024x942 它似乎适合
  • 尝试给图片一个最大宽度:100%;最大高度:100%
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-08
  • 2021-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-30
  • 1970-01-01
相关资源
最近更新 更多