gpt4 book ai didi

html - flexbox 中文本对齐的媒体查询

转载 作者:太空宇宙 更新时间:2023-11-04 06:27:34 24 4
gpt4 key购买 nike

当屏幕尺寸减小时,我有两个并排的 flexbox,它们在媒体查询下一个堆叠在另一个之上。左边的框有左对齐的文本,右边的框有右对齐的文本。激活媒体查询时,是否可以将两个 flexbox 中的文本居中对齐?如果可能,请发布代码。谢谢。

/* Container for flexboxes */
header {
display: -webkit-flex;
display: flex;
}

/* Responsive layout - makes the menu and the content (inside the section) sit on top of each other instead of next to each other */
@media (max-width: 600px) {
header {
-webkit-flex-direction: column;
flex-direction: column;
}
}


/* Style the side */
logosmall {
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
background: #FA8072;
padding: 20px;
}

/* Style the content */
bannersmall {
-webkit-flex: 3;
-ms-flex: 3;
flex: 3;
background-color: #FFA07A;
padding: 10px;
}


/* Container for flexboxes */
section {
display: -webkit-flex;
display: flex;
}
<header>

<logosmall>
<h1 style="font-size:15px; font-style:italic; color:#555; text-align: left;">Text-align: left</h1>
</logosmall>

<bannersmall>
<h1 style="font-size:15px; font-style:italic; color:#555; text-align: right;">Text-align: right</h1>
</bannersmall>
</header>

最佳答案

删除 h1 上的内联样式这里是更新后的代码。希望对你有帮助

/* Container for flexboxes */
header {
display: -webkit-flex;
display: flex;
}

/* Responsive layout - makes the menu and the content (inside the section) sit on top of each other instead of next to each other */


/* Style the side */
logosmall {
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
background: #FA8072;
padding: 20px;
}
header h1{
font-size:15px; font-style:italic; color:#555; text-align: left;
}
header bannersmall h1{
text-align:right;
}
/* Style the content */
bannersmall {
-webkit-flex: 3;
-ms-flex: 3;
flex: 3;
background-color: #FFA07A;
padding: 10px;
}


/* Container for flexboxes */
section {
display: -webkit-flex;
display: flex;
}

@media (max-width: 600px) {
header {
-webkit-flex-direction: column;
flex-direction: column;
}
header h1, header bannersmall h1{
text-align:center;
}
}
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content ="ie=edge">




<title>Test</title>

<style>

</style>
</head>



<body>

<header>

<logosmall>
<h1>Text-align: left</h1>
</logosmall>

<bannersmall>
<h1>Text-align: right</h1>
</bannersmall>
</header>

</body>

关于html - flexbox 中文本对齐的媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54942043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com