已解决-如何消除图像两边的空白?

时间:2019-07-13 09:05:49

标签: html css reactjs mobile bootstrap-4

我正在尝试消除图像周围的空白,该空间位于引导程序列之内。

我设法使用-1rem左右边缘修复了台式机上的问题。我尝试将主体边距和填充设置为0,并弄乱了容器,行和图像的流体引导程序设置。

JSX / HTML。

import requests
import json

callback = 'angular.callbacks._0'

headers = {
    'Referer': 'https://learn.dict.naver.com/conversation',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/75.0.3770.100 Safari/537.36',
    'DNT': '1',
}
params = (
    ('callback', callback),
)

with requests.Session() as session:
    response = session.get('https://gateway.dict.naver.com/krdict/kr/koen/today/20190713/conversation.dict',
                           headers=headers, params=params)

    data = json.loads(response.text.lstrip(f"{callback}(").rstrip(")"))["data"]
    sentences = data["sentences"]

    for sentence in sentences:
        audio_id = sentence["id"]
        sentence_pron_file = sentence["sentence_pron_file"]

        response = requests.post(f'https://learn.dict.naver.com/dictPronunciation.dict?filePaths={sentence_pron_file}')
        audio_url = response.json()["url"][0]
        audio_file = session.get(audio_url)

        with open(f'./{audio_id}.mp3', 'wb') as f:
            f.write(audio_file.content)

CSS。

<React.Fragment>
    <div className="conatiner-fluid bg">
        <div className="row"
            <div className="col-lg-6 col-md-6 col-sm-12">
                <img classname="img-fluid" src={...}></img>
            </div>
            <div className="rightSide col-lg-6 col-md-6 col-sm-12 mt-5 text- 
             centered">
                <h1 className="display-4 text-center">Hello, world!</h1>
                <p className="lead">More text</p>
                <p>even more text</p>
            </div>
        </div>
    </div>
</React.Fragment>

我现在遇到的问题是修复移动设备上的外观。现在,它紧靠页面的左侧,右侧有很大的空白空间。图片为960x1080。任何帮助甚至建议都将不胜感激。谢谢!

编辑:将p-0添加到图像的div容器中,然后除去左右边缘的-1rem即可解决此问题。另一个问题是,使用img-fluid作为目标CSS标签存在一些全局命名问题。

旧:

.rightSide {
    background: black;
    color:white;
.bg {
    background: black;

.img-fluid {
    margin-right: -1rem;
    margin-left: -1rem;
}
<div className="col-lg-6 col-md-6 col-sm-12">
    <img classname="img-fluid" src={...}></img>
</div>

新功能:

.img-fluid {
    margin-right: -1rem;
    margin-left: -1rem;
}

<div className="col-lg-6 col-md-6 col-sm-12 p-0">
    <img classname="img-fluid" src={...}></img>
</div>

2 个答案:

答案 0 :(得分:1)

G-Cyr是正确的。容器div上的p-0以及在左右边距处消除-1rem的问题解决了图像上的填充问题。其他样式问题是由CSS样式的命名引起的。 img-fluid也正在另一个文件上被操纵。要学习更好的命名习惯,哈哈。谢谢G-Cyr!

答案 1 :(得分:0)

* {
  margin: 0;
  padding: 0;
}

img {
  width: 100%;
}

.rightSide {
    color:white;
}

.bg {
    background: black;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
  <section class="bg">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12">
          <img class="img-fluid" src=https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png>
      </div>
      <div class="rightSide col-lg-6 col-md-6 col-sm-12 pt-5 text- 
                  centered">
        <h1 class="display-4 text-center">Hello, world!</h1>
        <p class="lead">More text</p>
        <p>even more text</p>
      </div>
    </div>
    </div>
  </section>
  
  <script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  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>
</body>
</html>

试试看!希望对您有帮助