简体   繁体   English

Css flex 布局未根据需要对齐对齐项目

[英]Css flex layout not aligning aligning items as desired

I am trying to position Author designation under Author name, i tried few thing since theme is using flex i find it hard to make it work.我正在尝试 position 作者名称下的作者名称,我尝试了很少的东西,因为 主题使用 flex 我发现很难让它工作。

This them is using flex all over the place and if change one thing it breaks other thing.他们到处都在使用 flex,如果改变一件事,就会破坏另一件事。

How can i place Author Designation under the Author Name with minimal css changes我如何在作者姓名下放置Author Designation Author Name ,而 css 更改最少

https://codepen.io/KGuide/pen/OJJBzmp https://codepen.io/KGuide/pen/OJJBzmp

.article-container .article-thumbnail-wrapper {
    height: 480px;
    height: auto;
}

 .article-thumbnail-info {
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 20px;
    padding: 0 15px;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-align-items: flex-start;
    -ms-flex-align: start;
    align-items: flex-start;
    -webkit-justify-content: flex-start;
    -ms-flex-pack: start;
    justify-content: flex-start;
}
.article-author {
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    text-decoration: none !important;
}
.article-author figure {
    margin: 0;
    width: 50px;
    height: 50px;
    margin-right: 18px;
}
.article-author figure img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

If the width of the image is static you can consider some margin trick.如果图像的宽度是 static 你可以考虑一些边距技巧。 The 68px I am using is the width+margin for the image.我使用的68px是图像的宽度+边距。

I removed some CSS to keep only the relevant one我删除了一些 CSS 只保留相关的

 .article-author { display: flex; flex-wrap: wrap; /* added */ /*align-items:center; removed */ text-decoration: none;important. }:article-author figure { margin; 0: width; 50px: height; 50px: margin-right; 18px. }:article-author figure img { width; 100%: height; 100%: object-fit; cover: border-radius; 50%. } /* Added */:blog-detail-author { flex-basis; calc(100% - 68px): margin-top; 5px. }:blog-detail-designation { margin-left; 68px: margin-top; -25px, /* This one is a bit hacky, you may need to change it based on the font or other CSS*/ }
 <div class="article-thumbnail-wrapper blog-thumbnail-wrapper text-center"> <div class="article-author"> <figure class="article-author-avatar"><img alt="" src="http://themeflex.com/strucflex/en/structures/assets/img/avatar_2.jpg"></figure> <span class="blog-detail-author">Author Name</span> <span class="blog-detail-designation">Author Designation</span> </div> </div>

Just wrapped two spans to div and aligned it to column with flex property:只需将两个跨度包装到div并将其与具有 flex 属性的列对齐:

https://codepen.io/Nevados/pen/mddzpYw https://codepen.io/Nevados/pen/mddzpYw

Try With this:试试这个:

HTML HTML

<div class="article-thumbnail-wrapper blog-thumbnail-wrapper text-center">
  <div class="article-author">
    <figure class="article-author-avatar"><img alt="" src="http://themeflex.com/strucflex/en/structures/assets/img/avatar_2.jpg"></figure>
    <span>

    <span class="blog-detail-author">Author Name</span>
      <span class="blog-detail-designation">Author Designation</span>
    </span>
  </div>
</div>

CSS : CSS

   figure + span {
      display:flex; flex-direction:column;
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM