html - 对齐某些东西但保持响应的最佳方法是什么
问题描述
链接到我的代码以查看问题:https ://jsfiddle.net/0sbcdfLk/2/
我正在使用引导响应式登录表单模板,我也将其用于登录屏幕的设计。我已经复制了代码的 formContent 部分两次,所以我现在有 2 个容器,但我希望第二个容器通常与左侧对齐,并在移动设备上直接位于下方。
我可以将其与边距对齐到左侧,但这会使移动设备上的设计混乱。响应式设计的最佳实践是什么?这是我正在使用的确切引导模板https://bootsnipp.com/snippets/X2bG0
我已经复制了这部分代码
<div id="formContent">
<!-- Tabs Titles -->
<!-- Icon -->
<div class="fadeIn first">
<img src="https://www.b-cube.in/wp-content/uploads/2014/05/aditya-300x177.jpg" id="icon" alt="User Icon" />
<h1>Aditya News</h1>
</div>
<!-- Login Form -->
<form>
<input type="text" id="login" class="fadeIn second" name="login" placeholder="username">
<input type="text" id="password" class="fadeIn third" name="login" placeholder="password">
<input type="submit" class="fadeIn fourth" value="Log In">
</form>
<!-- Remind Passowrd -->
<div id="formFooter">
<a class="underlineHover" href="#">Go to the Site</a>
</div>
我可以在底部添加一种样式,该样式margin: -50% 0px -6px -95%
适用于 PC,但在移动设备上它基本上是屏幕的一半并且溢出了第一个表单。
解决方案
使用“CSS @media”规则。按窗口宽度拆分 CSS。您可以为不同的设备屏幕尺寸定义@media 规则,以适应移动设备、平板电脑、PC、宽屏。使用它们,您可以像往常一样操纵一切。在 HTML 中为表单内容 div 设置类(有多个 ID,即使使用一次,类也更适合样式化):
<div id="formContent" class="account-details">
添加媒体规则以在足够宽的屏幕上显示左侧的表单:
@media only screen and (min-width: 1400px) {
.account-details{
position: absolute !important;
left: 0;
margin-left: -150px;
}
}
推荐阅读
- c# - 每次使用代码在数据网格中插入数据时如何添加新行?
- python - 将元组列表转换为该列表中使用的所有整数的列表
- spring-boot - 将 MVC webapp 部署到 tomcat 问题 URI
- asp.net - 基于下拉 (asp.net) 生成动态 Gridview
- cucumber - Cucumber Serenity NoSuchMethodException cucumber.runtime.SerenityBackend(ResourceLoader, TypeRegistry)
- azure - 唯一非聚集索引 - 插入重复值
- android - 使用 Tab Activity 搜索视图并查看寻呼机和片段
- python - 构建“pycocotools._mask”扩展错误:未知文件类型“.pyx”(来自“pycocotools/_mask.pyx”)
- python - 将函数应用于一系列特定行
- python - 询问输入时代码中断的原因是什么?