内容未按媒体查询的预期居中

时间:2018-06-27 01:36:13

标签: html css responsive

我已经学习HTML / CSS / Bootstrap大约一个星期了,我只是开始创建一个投资组合网站,作为对到​​目前为止我能做的事情的一种测试。目前,由于我在该页面上有图片,因此无法创建响应页面“关于我”。

网站链接位于http://moeminmamdouh.000webhostapp.com/aboutme.html

理想的结果是使所有内容基本上居中,但这就是https://ibb.co/idEPVT

此处是密码笔链接:https://codepen.io/muchkler/project/editor/AznjbN#

这是HTML代码:

<!DOCTYPE html>
<html>
<head> 
    <title> About Me </title>
    <link rel="stylesheet" type="text/css" href="aboutme.css">
    <link rel="stylesheet" type="text/css" href="bootstrap.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css?family=Raleway:300,400,500,600,700" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Noto+Sans:400,700" rel="stylesheet">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="icon" href="apple-icon.png">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet">
</head>
<body>
    <nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.html">Moemin Mamdouh</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a href="portfolio.html">Portfolio <span class="sr-only">(current)</span></a></li>
        <li class="active"><a href="#">About Me</a></li>
          <li><a href="#">Contact Me</a></li>
          </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

    <img src="images/rightprof.png" class="rightprof">

<div class="row">    
   <h1>HELLO.</h1>
    <h2>I'm Moemin Mamdouh</h2>
    <h3>graphic designer/ ui designer/ front-end developer</h3>
    <p>I provide entrepeneurs and startups with the kick they need to help start their business. A business is nothing without a brand, and a brand requires a stable and responsive website. I will be providing designs in both Adobe Photoshop and Adobe XD as the first step to any projects, afterwards, I move on to coding the actual website using HTML, CSS, and Bootstrap.  </p>
    <div class="imgbtns">
    <a href="https://www.facebook.com/moemin.mamdouh.3"><img src="images/facebook.png" height="30px" width="30px" class="facebook"></a>
    <a href="https://www.behance.net/Muchkler"><img src="images/behance.png" height="30px" width="30px" class="behance">  </a>  
</div>   
</div>   



</body>
</html>

这是CSS代码:

body{
    background: url(images/tom-sini-710353-unsplash.jpg);
    background-position: center;
    background-attachment: fixed;
    background-size: cover; 
    background-repeat: no-repeat; 
    height: 100%; 


}



.row{
    color: white; 
    padding-top: 350px;
    padding-left: 250px;
    width: 900px;

}

.rightprof{
    float: right; 
    padding-top: 250px;
    padding-right: 250px;
}

.navbar-default{
    background-color: #D91E18 !important;
    border-style: none !important; 
}

.navbar-brand{
    color: white !important; 
}

.navbar-default .navbar-nav > li > a {
  color: white !important; 
}

.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
  color: #555;
  background-color: #CF000F !important;
}

@media only screen and (max-width: 992px){
    .leftside{
        padding: 300px; 
    }


}



@media only screen and (max-width: 992px){
    .row{
        text-align: center; 
        padding-right: 110px;

    }

    .rightprof{

    }

}

@media only screen and (max-width: 1042px){

    .row{
        text-align: center; 


}

@media only screen and (max-width: 768px){

    .row{
    font-size: 10px;
    width: auto;
    margin-right: 200px; 
    }


    }

任何帮助将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:0)

我建议删除您的about.css文件。学习网格。您的代码在“ .row”周围缺少“ .container”,并且缺少列定义(.col-sm-8,.col-sm-4)。避免在图像和内容上添加CSS宽度和浮标,因为它会炸毁响应式网格。而是在图像中添加“ .img响应式”类。

<!doctype html>
<html>

<head>
    <title> About Me </title>

    <link rel="stylesheet" type="text/css" href="bootstrap.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css?family=Raleway:300,400,500,600,700" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Noto+Sans:400,700" rel="stylesheet">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
        crossorigin="anonymous">
    <link rel="icon" href="apple-icon.png">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet">
</head>

<body style="padding-top:70px;">
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
                    aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">Moemin Mamdouh</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="portfolio.html">Portfolio
                            <span class="sr-only">(current)</span>
                        </a>
                    </li>
                    <li class="active">
                        <a href="#">About Me</a>
                    </li>
                    <li>
                        <a href="#">Contact Me</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>



    <div class="container">
        <div class="row">
            <div class="col-sm-8">
                <h1>HELLO.</h1>
                <h2>I'm Moemin Mamdouh</h2>
                <h3>graphic designer/ ui designer/ front-end developer</h3>
                <p>I provide entrepeneurs and startups with the kick they need to help start their business. A business is nothing
                    without a brand, and a brand requires a stable and responsive website. I will be providing designs in
                    both Adobe Photoshop and Adobe XD as the first step to any projects, afterwards, I move on to coding
                    the actual website using HTML, CSS, and Bootstrap. </p>
                <div class="imgbtns">
                    <a href="https://www.facebook.com/moemin.mamdouh.3">
                        <img src="images/facebook.png" height="30px" width="30px" class="facebook">
                    </a>
                    <a href="https://www.behance.net/Muchkler">
                        <img src="images/behance.png" height="30px" width="30px" class="behance"> </a>
                </div>
            </div>
            <div class="col-sm-4">
                <img src="images/rightprof.png" class="img-responsive">
            </div>
        </div>
    </div>
</body>
</html>