如何在 iPhone 上正确调整 <div> 宽度?

我正在显示这些默认宽度的 div

https://img1.sycdn.imooc.com/65950204000102ed04420469.jpg

每次我尝试通过以下方式使这些 div 变大:


<center><h4>CONTACTO</h4></center>

<div style="width:600px; height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">

    <div></div>

</div>

<br>

<div style="height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">

    <div></div>

</div>

<br>

<div style="height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">

    <div></div>

</div>

<br>

<div style="height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">

    <div></div>

</div>

</section></center>

其中之一变宽,但它没有居中,即使我使用“center”标签也是如此。


我得到:

https://img1.sycdn.imooc.com/6595020f0001cf1506350406.jpg

我想让这些 div 的大小与第一个 div 的大小相同,但居中。我尝试使用align=“center”,但它不起作用。提前致谢。



慕工程0101907
浏览 41回答 2
2回答

青春有我

如果您正在寻找移动设备和桌面设备上的完全响应式屏幕,我会使用 CSS Flex 框和/或 Bootstrap 之类的东西。它们可以帮助确保容器对任何屏幕宽度的响应能力。.wrapper {&nbsp; &nbsp; margin: 10px;&nbsp; &nbsp; padding: 10px;&nbsp; &nbsp; min-height: 100%;}h4 {&nbsp; &nbsp; text-align: center;}.shell-container {&nbsp; &nbsp; width: 600px;&nbsp; &nbsp; height: 70px;&nbsp; &nbsp; opacity: 0.3;&nbsp; &nbsp; background: lightGrey;&nbsp; &nbsp; border-radius: 6px;&nbsp; &nbsp; display: flex;&nbsp; &nbsp; flex-direction: column;&nbsp; &nbsp; margin-left: auto;&nbsp; &nbsp; margin-right: auto;&nbsp; &nbsp; width: 80%;}<!DOCTYPE html><html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; &nbsp; &nbsp; <meta http-equiv="X-UA-Compatible" content="IE=edge">&nbsp; &nbsp; &nbsp; &nbsp; <meta name="viewport" content="width=device-width, initial-scale=1">&nbsp; &nbsp; &nbsp; &nbsp; <title>El</title>&nbsp; &nbsp; &nbsp; &nbsp; <!-- CSS -->&nbsp; &nbsp; &nbsp; &nbsp; <link rel="stylesheet" href="style.css">&nbsp; &nbsp; &nbsp; &nbsp; <!-- Bootstrap -->&nbsp; &nbsp; &nbsp; &nbsp; <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"/>&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <div class="wrapper fluid-container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h4>CONTACTO</h4>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="shell-container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="shell-container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="shell-container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="shell-container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; </body></html>

BIG阳

您的标签放错了位置。就是这个:<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <meta name="viewport" content="width=device-width, initial-scale=1.0">&nbsp; &nbsp; <meta http-equiv="X-UA-Compatible" content="ie=edge">&nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css">&nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css">&nbsp; &nbsp; <link rel="stylesheet" href="style.css">&nbsp; &nbsp; <title>Title</title></head><body>&nbsp; &nbsp; <center>&nbsp; &nbsp; &nbsp; &nbsp; <h4>CONTACTO</h4>&nbsp; &nbsp; &nbsp; &nbsp; <div style="width:600px; height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; <div style="width:600px; height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; <div style="width:600px; height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; <div style="width:600px; height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; <div style="width:600px; height: 70px; opacity: 0.3; background: lightGrey; border-radius: 6px;" class="shell container">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div></div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <br> </section>&nbsp; &nbsp; </center>&nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>&nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>&nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js"></script></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5