首页 > 解决方案 > 我网站的标志比正文宽

问题描述

我网站的顶部(带有徽标和导航栏)比主体(由 2 个 css 列组成)略宽。如何使顶部和主体尺寸相同?另外,我最近遇到了相反的问题,身体变宽了,但是通过使身体规则,它使顶部太宽了。

这就是问题

我的基础html:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-175481126-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-175481126-1');
</script>

<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
font-family: Tahoma, Geneva, sans-serif;
background-color: #333;
}
li {
float: left;
border-right: 1px solid #bbb;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
 li a:hover {
   background-color: #111;
   color: white;
   text-decoration:none;
 }

/* for buttons*/
.paging {
background-color: #333;
border: none;
color: white;
padding: 8px 14px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
}
button:hover {
background-color: #111;
}

.register {
  float: right;
}

.paging {
  background-color: #333;
  border: none;
  color: white;
  padding: 8px 14px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  font-family: Tahoma, Geneva, sans-serif;
}
button:hover {
  background-color: #111;
}

/* title */

.title {
  color: black;
  padding: 10px;
  text-align: center;
  font-size: 40px;
  font-family: Tahoma, Geneva, sans-serif;
  Color: black;
  text-decoration: none;
}

/* descriptions */

.description {
  color: black;
  padding: 15px;
  font-family: Tahoma, Geneva, sans-serif;
  text-align: left;
  font-size: 13px;
}

/* embedd url */
.iframe-container{
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; 
  height: 0;
    margin-left: auto;   /* Automatic margin from left */ 
    margin-right: auto; /* Automatic margin from right */
}
.iframe-container iframe{
  position: absolute;
  top:0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* make columns */

* {
    box-sizing: border-box;
}

.row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    flex: 0 0 100%;
    max-width: 100%;
    /* you can just remove these margins all together. Just wanted to emphasize that there should be no margin left or right, to avoid overflow */
    margin-left: 0px;
    margin-right: 0px;
}

.videos, .ads {
    flex-grow: 0; flex-shrink: 0;
}

.ads {
    display: block;
    float: right;
    background-color: #c1c4c9;
    width: 25%;
}

.videos {
    display: block;
    float: left;
    width: 75%;
    padding-right: 10%;
    padding-left: 10%;
}

.image {
  padding-right: 5%;
  padding-left: 5%;
  padding-top: 5%;
  padding-bottom: 5%;
}

.logo {
    flex-direction:; row;
    flex:; 0 0 100%;
    max-width 100%;
    justify-content:; center;
}

.banner {
/*  float: left;*/
  width: 100%;
  height: 5%;
  background-color: red;
  color: white;
  text-align: center;
}

img {
    max-width: 100%;
    max-height: 100%;
}

/* header */
.header {
  background-color: #F1F1F1;
  text-align: center;
  padding: 20px;
  font-family: Tahoma, Geneva, sans-serif;
}
</style>

<html>

{% load static %}

<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico' %}"/>

<div class="logo">
<div class="header">
  <a href="/">
  <img src="https://i.ibb.co/5Rqps7F/logo-black.png" alt="Computer Man">
</a>
</div>

<ul>
  <li class="all"><a href="/">All videos</a></li>
  <li class="stam"><a href="/stam">Stam videos</a></li>
  <li class="music"><a href="/music">Music videos</a></li>
  <li class="news"><a href="/news">News videos</a></li>
  <li class="contact"><a href="/contact">Contact</a></li>
  <li class="register"><a href="/register">Login/Register</a></li>
</ul>

<div class="banner">
    <text align="center">We are still developing our site, so we may not be able to update videos as often as we want</text>
</div>
</div>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

页面html:

{% include 'base.html' %}
<style>
    .{{ category }} {
        background-color: grey;
    }
</style>

<div class="row">
    <div class="videos">
    {% autoescape off %}
            <h1 class="title"> {{ video_.title }} </h1>
            {% ifnotequal video_.tag 'none' %}
                <small align = left> {{ video_.tag }} </small>
            {% endifnotequal %}
            <div class="iframe-container"><p align="center"> {{ video_.url }}</p></div>
            <div class="description"> {{ video_.description }} </div>
            <hr/>

{% endautoescape %}
    </div>

    <div class="ads">
        {% for ad in ad_item %}
            {% ifequal ad.redirect 'False' %}
                <img class="image" src="{{ ad.pic }}"></img>
            {% endifequal %}
            {% ifnotequal ad.redirect 'False' %}
                <a href="{{ ad.redirect }}"><img class="image" src="{{ ad.pic }}"></img></a>
            {% endifnotequal %}
        {% endfor %}
    </div>
</div>

标签: htmlcss

解决方案


尝试添加margin: 0px. 由于您使用的是 Bootstrap,因此您可以m-0在需要的地方添加类。

<div class="row m-0">
    <div class="videos m-0">
    {% autoescape off %}
            <h1 class="title"> {{ video_.title }} </h1>
            {% ifnotequal video_.tag 'none' %}
                <small align = left> {{ video_.tag }} </small>
            {% endifnotequal %}
            <div class="iframe-container"><p align="center"> {{ video_.url }}</p></div>
            <div class="description"> {{ video_.description }} </div>
            <hr/>

{% endautoescape %}
    </div>

    <div class="ads m-0">
        {% for ad in ad_item %}
            {% ifequal ad.redirect 'False' %}
                <img class="image" src="{{ ad.pic }}"></img>
            {% endifequal %}
            {% ifnotequal ad.redirect 'False' %}
                <a href="{{ ad.redirect }}"><img class="image" src="{{ ad.pic }}"></img></a>
            {% endifnotequal %}
        {% endfor %}
    </div>
</div>

推荐阅读