【问题标题】:Responsive Vertical Aligning Float Right Image and text响应式垂直对齐浮动右图和文本
【发布时间】:2019-06-12 03:14:22
【问题描述】:

我对此很陌生

我正在尝试在具有响应式背景颜色的浮动右图像旁边创建文本。 此部分将作为文章的一部分显示,但样式仅适用于此部分。

下面的代码似乎可以工作,但是我希望文本与图像垂直对齐。使文字显示在图像的中间。

我似乎无法做到这一点

我已经定义了 <img style="float: right; vertical-align: middle;">

Picture of code rendered

这是代码 (https://codepen.io/Masseve/pen/LMoMyW/)

<div id="blogcontent">   
<img style="float: right; vertical-align: middle;" src="https://image.shutterstock.com/z/stock-photo-city-interchange-closeup-at-night-beautiful-transport-infrastructure-background-267836915.jpg" width="700"/> 
<div id="textcontent">
<H1> A Title </h1>
<P>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. <br> <br>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</P>                                                                                                                              
</div>
</div>                                                                                                                               

#blogcontent {
border-radius: 4px;
background-color: #ebe9e5;
display: inline-table;
}

#textcontent {
Padding: 20px
}

【问题讨论】:

标签: css image text


【解决方案1】:

这是一个小例子:D

.wrapper {
  display: flex;  
  flex-flow: row wrap;
}

.main {
  text-align: left;
  background: deepskyblue;
  flex:1.5
}


.aside-1 {
  background: purple;
   flex:1
}
.image{
  width:100%;
  height:100%;
  background-image:url('https://image.shutterstock.com/z/stock-photo-city-interchange-closeup-at-night-beautiful-transport-infrastructure-background-267836915.jpg');
  background-size:cover;
}

@media all and (min-width: 600px) {
      .aside { flex: 1; }
    }

/*@media all and (min-width: 800px) {
  .main    { flex: 3 0px; }
  .main    { order: 1; }
  .aside-1 { order: 2; } 
 
}*/
<div class="wrapper">
  <article class="main">
   <h1> A Title </h1>
<P>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. <br> <br>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</P>                                                  
                    <br>
                                        <br>
  </article>
  <aside class="aside aside-1">
  <div class="image"></div>
  </aside>
</div>

【讨论】:

  • 您好,感谢您的宝贵时间,但我尝试了 display: flex 但我发现它没有响应,因为它并排显示文本和图像,而不是在到达断点时显示在文本上方
  • 你没有说你有/想要一个断点。如果此处建议的代码适用于大屏幕,那么您必须编写一个媒体查询,然后在视口达到一定宽度时将文本移动到图像下方。
  • 你只玩 float 和 @mediaquery 就完成了。
猜你喜欢
  • 1970-01-01
  • 2014-10-29
  • 2016-12-24
  • 2012-02-11
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
  • 2015-08-03
  • 1970-01-01
相关资源
最近更新 更多