css - 将文本左对齐(相对于)div
问题描述
我有一些h2
文本当前在移动视图中与左侧对齐,位于居中的 div 上方。我如何才能将其相对于移动视图中的 div 向左对齐(应用下面的 CSS 中提供的媒体查询)?
相关HTML:
<section class="container-projects">
<h2 class="portfolio-header">Featured Work</h2>
<div class="project">
相关CSS:
.portfolio-header {
/* Puts header in its own row without removing from container with row flex direction (setting parent container to wrap also required) */
width: 100%;
text-align: left;
color: #7d97ad;
}
.container-projects {
display: flex;
/* Parent container needs this for flex-item to take full width in row */
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
margin: 2em 0;
}
/* Special styling for screens up to 767px wide, inclusive (applies to landscape phones) */
@media screen and (max-width: 767px) {
header, .container, footer {
max-width: 100%;
}
/* Must specify max-width for img even though parent .container has the same declaration because max-width isn't inherited */
.container img {
max-width: 100%;
}
.project {
/* Centers projects (aligned left otherwise) */
margin: 0 auto;
}
}
解决方案
您可以为移动设备添加媒体查询
@media screen and (max-width: 600px) {
.portfolio-header {
width: 300px;
margin: 10px auto;
}
}
推荐阅读
- c# - 处理电脑显示器[扩展]
- html - 是否有替代已弃用的 HTML 标记来获得相同的输出,以便将页面划分为所需的列数?
- c# - IOException on Directory.Move 使用该目录的进程后
- forms - 表单验证如何排除输入字段?
- javascript - 类型错误:无效的 URL
- server - 服务器无法处理请求。---> 客户端发现响应内容类型为“text/html”,但预期为“text/xml”
- spring-boot - 找不到类型的字段所需的 bean。错误 springboot API 部署到 ubuntu
- ios - 无法在我的 iOS 应用程序中访问我的可可框架的 .json 文件
- c# - 如何在插入数据库时将类属性的值设置为另一个类的生成 id 值?
- asp.net-mvc - 将 Google Drive API 托管到 IIS 后上传失败。将错误显示为无法启动浏览器