gpt4 book ai didi

html - 带有文本和按钮的响应式标题

转载 作者:行者123 更新时间:2023-12-04 15:24:46 24 4
gpt4 key购买 nike

我正在制作一个带有文本和按钮的简单标题,但是当我使用移动设备时,一切都没有响应。我尝试使用 %'s 但没有任何效果。当我在移动设备上滚动时,我的 CSS 会上下跳动。这是代码笔,https://codepen.io/Religion/pen/ZEQerQZ .下面是 CSS 。 HTML 你可以在 codepen 上查看,因为帖子说它主要是代码。CSS:

@media only screen and (max-width: 767px) {
.header1{
padding: 15%;
text-align: center;

background-image: url('https://manchesterdental.org/img/dentalimg/welcomenote.jpg');
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
color: white;
font-size: 30px;
position: relative;

}
.header-text1 h2{
margin-top:20%;
font-size:1.8rem;
width:45vh;
margin-left:-20%;
color:white;




}
.header-text1 p{

font-size:1.1rem;
width:44vh;
margin-left:-20%;
padding-top:40px;
color:white;
font-weight: 500;



}
.header-text{
position: absolute;
bottom:0;
left:0;



width:1px;



}
.button {
background-color: #00aeef; /* Green */

color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
margin-left: 2%;
width:95%;
margin-bottom: 20px;

}
}

@media (min-width:900px) {
.header1{
padding: 60px;
text-align: center;

background-image: url("{% static 'dentist/img/bg-img/header.jpg' %}");
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
color: white;
font-size: 30px;
height:80vh;

}
.header-text1 h2{
margin-top:10%;
color:white;
font-size: 3rem;



}
.header-text1 p{
padding-top:40px;
font-size:1.5rem;
max-width:80%;
margin-left:10%;


color:white;
font-weight: 500;



}
.button {
background-color: #00aeef; /* Green */

color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
margin-left: 2%;
width:45%;
font-family: "Comic Sans MS", cursive, sans-serif;
font-weight:800;


}
}

HTML:

<div class="header1">
<div class = "header-text1">
<h2>We Believe Everyone Should Have Easy Access To Great Dental Care</h2>
<p >As a leading industry innovater, * Dental Business* is opening up exciting new opportunities for dental professionals, investors, employees & suppliers. Contact us to find out what we have to offer you.</p>
<br>
<a href="{% url 'contact' %}"><button class="button button1">Contact Us!</button></a>

</div>
</div>

enter image description here

最佳答案

要使文本元素在 div 中居中,您可以使用 flexbox。只需将以下代码添加到媒体查询之前的 CSS 文件顶部:

.header-text1 {
display: flex;
flex-direction: column;
justify-content: center;

width: 100%;

此外,无需将此包含在您的媒体查询中,因为无论视口(viewport)大小如何,flexbox 都会处理所有内容。

Codepen更新了代码 - 还更改了第二个媒体查询,以便 CSS 不会像以前那样在 767px 和 900px 之间中断。

关于html - 带有文本和按钮的响应式标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62504170/

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