确保响应图像和类的大小相同

时间:2019-04-29 14:58:33

标签: css bootstrap-4 responsive-images

我正在尝试利用空白空间进行设计。

我在白色背景上有一张想要的图像。我有一个具有白色背景和图像本身的类(图像也具有白色背景)。我遇到一个问题,如果我两个人都响应的话,我不能确保div类与图像本身的高度相同。

我尝试添加第二个图像,该图像的高度与初始图像的高度相同,只是空白,将div设置为可响应的,以及其他很多操作,但是我不确定最好的方法是做到这一点。该页面本身位于http://jamieaurora.com/devinTribute.html处,以使我了解要执行的操作(尽管代码比我在此处发布的内容有些过时)。如果有人能指出我正确的方向,将不胜感激。我删去了我认为不相关的代码部分,但是如果您想看完整的HTML文件,它位于此hastebin中。非常感谢!

https://hastebin.com/tifiqaciri.xml

 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<style>
.responsive
{
  width: 100%;
  height: auto;
}
.hero-section
{
  background-color: white;
  font-family: Oswald;
  letter-spacing: 4px;
  top: 0;
  height: 64%;
  width: auto;
  padding-top: 5%;
  padding-bottom: 1%;
}
</style>
<body>
<nav>
<ul id='navbar' style="z-index:0;">
<li><a class = "active" href="index.html">Home</a></li>
</ul>
</nav>
<section class="hero-section" id="hero-section">
  <div class = "container-fluid">
    <div class = "row">
      <div class="col-xs-6">
        <img src = "images/devin-townsend-evermore.jpg" class="responsive" ></img>
      </div>
      <div class="col-xs-6">
        <h1 style="padding-left: 62%" class="responsive">Title Text</h1>
        <h2 style = "padding-left: 60%; font-size: 140%; align: left;" class="responsive">Paragraph Text</h2>
      </div>

      </div>

    </div>


  </section>

1 个答案:

答案 0 :(得分:0)

我有一个父div容器,其中并排有两个主要组件。我在右边有一个响应的图像。我希望左侧的文本保留在图片的中心和左侧,因为它根据浏览器的屏幕大小更改了大小。

我将父母的容器高度设置为与原始形式的图像相同的大小,但以em表示。

使用height: automax-height: 100%的组合为我工作。

我的React组件的返回是:

  <div className="videoAndDescription">
  <div className="left33">
    <div className="textToSquare">
      <h1>Firewood, delivered...</h1>
      </div>
  </div>

  <div className="right66">
    <img src={stoveburning} />
  </div>
</div>

我的CSS:

.videoAndDescription{
    display: flex;
    flex-direction: row;
    background-color: red;
    height: 40em;
}

.left33{
    color: orange;
    display: flex;
    justify-content: center;
    align-content: center;
    width: 60%;
}

.left33 .textToSquare{
    height: auto;
    background-color: black;
}

.right66{
    width: 40%;
}

.right66 img{
    max-height: 100%;

}