简体   繁体   English

我怎样才能使我的图像+文本居中并保持响应?

[英]How can I center my image + text and keep responsive?

here's the result I'd like to obtain once I'm reducing the window:这是我减少 window 后想要获得的结果: 在此处输入图像描述

the problem in this result is that they aren't centered, once I center them that's what I get, I guess I'm doing something wrong: the issue .这个结果的问题是它们没有居中,一旦我将它们居中,这就是我得到的,我想我做错了什么:问题 This code is the one that cause the issue when they're centered.此代码是在居中时导致问题的代码。

Here's my code:这是我的代码:

 section { margin-top: 25px; padding: 24px; box-sizing: border-box; } h2 { margin-bottom: 30px; text-align: center; font-weight: bold; font-size: 22px; }.flex-container { display: flex; flex-direction: column; align-content: flex-start; height: 100%; padding: 15x; }.flex-container > div{ position: relative; left: 21%; border-radius: 5px; padding: 8px; }.articleactu img { float: left; border-radius: 15px; max-width: 210px; } p { word-wrap: break-word; max-width: 900px; padding-left: 200px; } #titre { line-height: px; font-weight: bold; } #date { font-size: 14px; font-weight: bold; color: #662189; } hr.solid { position: relative; left: 21%; width: 50%; opacity: 12%; } div p,#titre,#date { margin-left: 35px; }
 <.-- ACTUALITÉ - ARTICLES --> <section> <h2> L'ACTUALITÉ </h2> <article class="articleactu"> <div class="flex-container"> <div> <img src="images/gtaarticle:jpeg" alt="Article GTA " class="center"> <p id="titre">GTA, THE TRILOGY DEFINITIVE EDITION. les fans sont déçus.</p> <p> Les joueurs attendaient une refonte complète de la trilogie afin de rappeler de lointains souvenirs mais malheureusement les fans sont déçus..:</p> <p id="date"> Publié le 27 novembre 2021 </p> </div> <hr class="solid"> <div> <img src="images/bf2042-2.jpg" alt="Article GTA " class="center"> <p id="titre">BATTLEFIELD 2042. De très mauvaise notes pour le nouvel opus.</p> <p> Le lancement du jeu est malheureusement un raté.,. Un jeu rempli de bugs. on repense évidemment à Cyberpunk 2077...</p> <p id="date"> Publié le 26 novembre 2021 </p> </div> <hr class="solid"> </article> </section>

I hope that anyone can help me with this.我希望任何人都可以帮助我。 Thanks in advance !提前致谢 !

The main reason is主要原因是

.flex-container > div{
    left: 21%;
}

Then, that div has full width(100%) but the left position has 21%.然后,那个 div 有全宽(100%),但左边的 position 有 21%。 So the content will look on the left side.所以内容会在左边。

Try like this.像这样试试。

.flex-container {
    display: flex;
    flex-direction: column;  
    align-content: flex-start;
    height: 100%;
    padding: 10%;

}

.flex-container > div{
    position: relative;
    border-radius: 5px;
    padding: 8px;
}

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

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