简体   繁体   English

CSS 在中间并排对齐两个 DIV

[英]CSS Aligning two DIVs side-by-side in the middle

在此处输入图像描述 Dears Greeting,,亲爱的问候,,

I want to Align two Divs side by side in the middle using HTML.我想使用 HTML 在中间并排对齐两个 Div。

I really hope I can find the solution.我真的希望我能找到解决方案。 I attached the code below the final result should look like the attached image我附上了最终结果下面的代码应该看起来像附加的图像

many thanks & best regards非常感谢和最好的问候

 .circle { width: 300px; height: 300px; line-height: 300px; border-radius: 50%; margin: 50px; outline: solid 1px black; display: flex; justify-content: center; align-items: center; font-size: 30px; color: #fff; text-align: center; vertical-align: middle; position: relative; box-shadow: inset -10px -10px 100px #000, 10px 10px 20px black, inset 0px 0px 10px black; display: inline-block; margin: 5%; background: white }
 <div class="circle"><a href="https://www.w.com/">1</a></div> <div class="circle"><a href="https://www.w.com/">2</a></div>

The code snippet which you have shared has two different <div> for each element and your CSS also does not have .margin or .width proportion to match the center of the page.您共享的代码片段每个元素都有两个不同的<div>并且您的CSS也没有.margin.width比例来匹配页面的中心。

You can add parent wrapper <div> around your both circle <div> elements.您可以在两个圆<div>元素周围添加父包装器<div>

See if this snippet works for you:查看此代码段是否适合您:

 .circle { width: 300px; height: 300px; line-height: 300px; border-radius: 50%; margin: 50px; outline: solid 1px black; display: flex; justify-content: center; align-items: center; font-size: 30px; color: #fff; text-align: center; vertical-align: middle; position: relative; box-shadow: inset -10px -10px 100px #000, 10px 10px 20px black, inset 0px 0px 10px black; display: inline-block; margin: 5%; background: white }
 <div style="text-align:center;"> <div class="circle"><a href="https://www.w.com/">1</a></div> <div class="circle"><a href="https://www.w.com/">2</a></div> </div>

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

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