首页 > 编程问答 >如何使该页面对移动设备友好?

如何使该页面对移动设备友好?

时间:2024-06-06 12:21:12浏览次数:7  
标签:css mobile grid

这是背景徽标。 GTA 的 3 张标题图片在 768px 宽度下无法排成一列,媒体查询将它们设置为只有一列的网格。我以前这样做成功过,但在这里却行不通。

.body {
  margin-top:0pt;
  margin-left:0pt;
  margin-right:0pt;
  margin-bottom:0pt;
}

.gta {
   background-image: url('logos/GTA3_Artwork.jpg');
   background-position:center;
                                               
}

.item {
  font-family: "Freeman", sans-serif;
  font-weight: 800;
  font-size: 2rem;
  color: rgb(2, 1, 0);
  margin-top: 30px;
}

.gta3 {
  position: relative;
  left: 600px;
  top:200px;
  color:rgb(0, 0, 0);
  font-family: 'Pricedown Bl', sans-serif;
  font-size:60px;
  text-shadow: 20px;
  宽度:200px;
  display:block;
}

.gtavicecity {
  position: relative;
  left: 110px;
  top:-70px;
  color: rgb(221, 71, 221);
  font-family: 'Rage Italic', sans-serif;
  font-size: 90px;
  宽度:200px;
  display: block;
}

.gtasanandreas {
  position:relative;
  left: 1000px;
  bottom:300px;
  font-family: 'Beckett', sans-serif;
  font-size: 80px;
  颜色:黑色
  宽度:200px;
  display:block;

}

.alsoflexbox {
  display: flex;
  justify-content:space-evenly;
  font-family: "Freeman", sans-serif;
  font-weight: 800;
  font-size: 32px;
  margin-bottom:100px;
  背景颜色:灰色;
  border-radius:30px;
  flex-wrap:wrap;
}

.kezdo {
  font-family: "Freeman", sans-serif;
  font-weight: 800;
  font-size: 2rem;
  display: block;
  text-decoration: none;
  color: black;
  text-align: center;
  margin-bottom:50px;

}

@media (max-width: 768px)
{
  .container{
    display:grid;
    grid-template-columns:100%;
    grid-template-rows: auto;}
    
    .item {
      font-family: "Freeman", sans-serif;
      font-weight: 800;
      font-size: 2rem;
      color: rgb(2, 1, 0);
      margin-top: 30px;
    }

}
.gta3 {
  color:rgb(0, 0, 0);
  font-family: 'Pricedown Bl', sans-serif;
  font-size:60px;
  text-shadow: 20px;
  width: 200px;

}

.gtavicecity {
  color: rgb(221, 71, 221);
  font-family: 'Rage Italic', sans-serif;
  font-size: 90px;
  width: 200px;
}

.gtasanandreas {
  font-family: 'Beckett', sans-serif;
  font-size: 80px;
  color:black;
  width: 200px;

}
.gta {
  background-image: url('logos/GTA3_Artwork.jpg');
  background-position:center;
}
<body class="gta" >;
    <div class="container">;
        <div class="item"><a class=" gta3" href="https://www.gta.fandom.com" style="text-decoration:none;">Grand Theft Auto III</a></div>;
        <div class="item"><a class="gtavicecity" href="https://www.gta.fandom.com" style="text-decoration:none;">Vice City</a></div>;
        <div class="item"><a class="gtasanandreas" href="https://www.gta.fandom.com" style="text-decoration:none;">San Andreas</a></div>;
    </div>;

    <div class="alsoflexbox">;
        <a style="text-decoration: none;color:black" href="zene.html"><div>Zene</div></a>;
        <a style="text-decoration: none;color:black" href="gta.html"><div>GTA</div></a>;
        <a style="text-decoration: none;color:black"href="gitár.html"><div>Gitár</div></a>;
        <a style="text-decoration: none;color:black"href="számítógép.html"><div>Számítógép</div></a>;
        <a style="text-decoration: none;color:black"href="fotózás.html"<div>Fotózás</div></a>;
        <a style="text-decoration: none;color:black"href="utazas.html"><div>Utazásaim</div></a>;
        <a style="text-decoration: none;color:black"href="sport.html"><div>Sport</div></a>;
        <a style="text-decoration: none;color:black"href="kepesiteseim.html"><div>Képesítéseim</div></a>;
        <a style="text-decoration: none;color:black"href="valami.html"><div>Valami</div></a>;
        </div>;
        <div class="kezdo"> <a style="text-decoration: none;color:black" href="index.html">Kezdőoldal</a>;
        </div>;
</body>;
</html>;

我使用了媒体查询,可能还有许多无用的代码行。我不知道为什么当我缩小屏幕尺寸时,我的 3 个徽标会变成一列。我可以使用网格成功地使我的其他页面移动到一列,但不知道为什么在这里不起作用。


问题在于你的媒体查询只对 .container 元素应用了网格布局,而没有对其中的子元素( .item )进行任何布局调整。

为了解决这个问题,你需要在媒体查询中也对 .item 元素应用样式,将它们排列成一列。你可以通过将 .item 的宽度设置为 100% 来实现。

以下是如何修改你的代码:

@media (max-width: 768px) {
  .container {
    display: grid;
    grid-template-columns: 100%;
    grid-template-rows: auto;
  }

  .item {
    font-family: "Freeman", sans-serif;
    font-weight: 800;
    font-size: 2rem;
    color: rgb(2, 1, 0);
    margin-top: 30px;
    /* 将 .item 的宽度设置为 100% */
    width: 100%;
  }
}

此外,你的 CSS 代码中还有一些其他问题:

  • 重复的样式 : 你在媒体查询内外都定义了 .gta3 .gtavicecity .gtasanandreas 的样式。最好将这些样式合并到一个地方,以避免重复和混乱。
  • 不必要的定位 : 你使用了大量的 position: relative left top 属性来定位元素。这可能会导致布局问题,并且难以维护。建议使用更灵活的布局方法,例如 Flexbox 或 Grid。
  • 内联样式 : 尽量避免在 HTML 中使用内联样式,而是将所有样式都放在 CSS 文件中。

建议你重新组织你的 CSS 代码,并使用更现代的布局方法来简化你的代码并提高可维护性。

标签:css,mobile,grid
From: 78584449

相关文章

  • CSS
    css介绍用来对HTM进行装饰的注释语法:/**/语法结构:选择符书写位置直接写在style标签中<style>h1{color:red}</style>直接在标签中定义一个style属性<h1style='color:read'>***</h1>通过外部文件引入<linkrel='',href=''>......
  • web 关于CSS
    我主要将两个好理解的:1这个代码是直接写在html里的,这个是不安全的。还有这个是在<head>标签下的。<styletype="text/css">body{background-image:url('images/background2.jpeg');background-size:cover;line-height:2;}.center-text{text-align:......
  • CSS 头部固定,中间滑动
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width......
  • 裁剪的3种方式,CSS 如何隐藏移动端的滚动条?
    在移动端开发中,经常会碰到需要横向滚动的场景,例如这样的但很多时候是不需要展示这个滚动条的,也就是这样的效果,如下你可能想到直接设置滚动条样式就可以了,就像这样::-webkit-scrollbar{display:none;}目前来看好像没什么问题,但在某些版本的iOS上却无效(具体待测试),滚......
  • Css var 的基础使用
    Cssvar语法var(custom-property-name,value)-custom-property-name必须变量必须以--开头后面可以是英文、数字连接符,区分大小写-value不必须默认值当custom-property-name不存在时使用优先级style>id>class>tag>*>:root伪类:root相当于文档根元......
  • DevExpress WPF中文教程:Grid - 如何向项目添加GridControl并绑定到数据
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。无论是Office办公软件的衍伸产品,还是以数据为中心......
  • WPF datagrid scrolldown and change the marked the location in canvas
    <Windowx:Class="WpfApp134.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • 大学生HTML期末大作业——HTML+CSS+JavaScript美食网站(甜品)
    HTML+CSS+JS【美食网站】网页设计期末课程大作业web前端开发技术web课程设计网页规划与设计......
  • 大学生HTML期末大作业——HTML+CSS+JavaScript个人网站(图书爱好)
    HTML+CSS+JS【个人网站】网页设计期末课程大作业web前端开发技术web课程设计网页规划与设计......
  • :empty 选择器在 css 中不起作用
    我在.error类中使用了:empty选择器。问题是,即使在带有error类的div中没有内容,error类也不会被完全删除。当我在firebug中进行测试时,我发现div中仍有一些空白,而当我删除这些额外的空格时,div就会消失。.error{border:solid1px#ff0000;color:#ff......