英文:
Align two HTML elements in the center and display side-by-side in markdown
问题
你可以尝试使用以下Markdown代码,将两个元素垂直居中并显示在页面的中间:
<details>
<summary>Hello, friend</summary>
<p align="center">
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c" alt="lol-haha" style="height:3.8cm; vertical-align: middle;">
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat" alt="aleixmt" style="display:inline-block; vertical-align: middle;">
</p>
</details>
这将使两个元素垂直居中,并且不会创建下拉菜单。请尝试并查看效果。
英文:
I am using github flavored markdown to format my github profile and I wanted to show an image alongside the profile views.
This is what I achieved so far:
With this markdown code:
<details>
<summary>Hello, friend</summary>
<p>
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c" alt="lol-haha" style="height:3.8cm;">
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat" alt="aleixmt" style="display:inline-block;vertical-align: middle;">
</p>
</details>
This code also adds a dropdown menu to see the images, I actually do not need that.
What I want is the profile view counter to be in the middle of the height of the image, still on its right side, so it is positioned with more height.
I should see it like this:
Can someone please help me? I am completely new with HTML and markdown and I did not know that aligning two elements was going to be so difficult. Bless front-end programmers.
Also note that the two elements must be displayed in the center of the page.
Do not use CSS to format the elements, add the styles in line since in markdown there is no support for explicit CSS. Also please test your solution since I have been using other solutions but they do not work with github flavored markdown:
- https://stackoverflow.com/questions/11819417/css-center-two-images-in-css-side-by-side
- https://stackoverflow.com/questions/255170/markdown-and-image-alignment
- https://stackoverflow.com/questions/7915791/divs-side-by-side-and-centered
- https://stackoverflow.com/questions/65554639/is-there-a-way-to-align-two-html-elements-side-by-side-without-css-how (my code is similar to this)
- https://stackoverflow.com/questions/35101813/vertical-middle-aligned-image-and-text-side-by-side-in-css (this looks good but does not work..)
Thank you very much.
EDIT: I finally was able to use a table with inline CSS styles as asked for solving my question.
Take a look here to see the final result.
答案1
得分: 1
你可以将这两个组件放到一个表格中:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
td {
vertical-align:center
}
<!-- language: lang-html -->
<table>
<tr>
<td>
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c" alt="lol-haha" style="height:3.8cm;">
</td>
<td>
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat" alt="aleixmt" style="display:inline-block;vertical-align: middle;">
</td>
</tr>
</table>
<!-- end snippet -->
Edit 1: 我之前使用了表格,但根据 @Sdili_81 的建议,这不是推荐的做法。
Edit 2: 鉴于在这个特定用例中这个解决方案不起作用,我已恢复到原始答案。
英文:
You can put both components into a table:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
td {
vertical-align:center
}
<!-- language: lang-html -->
<table>
<tr>
<td>
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c" alt="lol-haha" style="height:3.8cm;">
</td>
<td>
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat" alt="aleixmt" style="display:inline-block;vertical-align: middle;">
</td>
</tr>
</table>
<!-- end snippet -->
Edit 1: I previously used a table but that's not recommended according to @Sdili_81
Edit 2: Reverted back to the original answer as this solution did not work in this particular use case.
答案2
得分: 1
<!-- 开始代码片段: js 隐藏: false 控制台: true Babel: false -->
<!-- 语言: lang-css -->
.bro-code{
display:flex;
align-items:center;
}
<!-- 语言: lang-html -->
<p class="bro-code">
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c" alt="lol-haha" style="height:3.8cm;">
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat" alt="aleixmt" style="display:inline-block;vertical-align: middle;">
</p>
<!-- 结束代码片段 -->
英文:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.bro-code{
display:flex;
align-items:center;
}
<!-- language: lang-html -->
<p class="bro-code">
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c" alt="lol-haha" style="height:3.8cm;">
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat" alt="aleixmt" style="display:inline-block;vertical-align: middle;">
</p>
<!-- end snippet -->
答案3
得分: 0
没有提供解决我的问题的答案。幸运的是,我在这里找到了一个解决方案。我认为我已经使用了表格布局。我的解决方案代码仅使用内联CSS样式:
<!-- Eliot Alderson + profile visits counter -->
<div id="image-table" align="center">
<table>
<tr>
<td style="padding:10px">
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c"/>
</td>
<td style="padding:10px">
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat"/>
</td>
</tr>
</table>
</div>
我希望这对某人有帮助。我将标记此问题为已解决。
英文:
No answers are provided for this question that solve my problem. Luckily, I have found a solution in here. I think I have used the table layout. My solution code using only inline CSS styles is:
<!-- Eliot Alderson + profile visits counter -->
<div id="image-table" align="center">
<table>
<tr>
<td style="padding:10px">
<img src="https://github.com/AleixMT/AleixMT/assets/23342150/a802e799-cfcf-4add-ae22-0aa96bbecb6c"/>
</td>
<td style="padding:10px">
<img src="https://komarev.com/ghpvc/?username=aleixmt&label=Profile%20views&color=0e75b6&style=flat"/>
</td>
</tr>
</table>
</div>
I hope this helps someone. I will mark this question as solved.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论