Flexbox <p>元素与页面上的图像重叠大小

时间:2019-01-23 15:27:21

标签: html css flexbox

调整页面大小时,右栏中的文本与左栏中的图像重叠,如下所示:

problem

如何停止此操作并使右列停留在原位置,或者在调整页面大小时移至图像下方?全屏显示时,我不想更改页面的布局,但我希望它能够响应。

@import url(https://fonts.googleapis.com/css?family=Raleway);
body {
  margin: 0;
  font-family: 'Raleway', georgia, arial;
  background-color: #e0e0e0;
  text-align: center;
}

h1 {
  color: #aaaaaa;
  text-align: left;
}

.sortFilms {
  text-align: left;
  display: inline-block;
  background-color: #ff6699;
  width: 80%;
  padding: 20px;
}

header {
  text-align: center;
  display: inline-block;
  border-bottom: 5px;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  border-style: solid;
  border-color: #aaaaaa;
  width: 80%;
  padding: 20px;
  background-color: #e0e0e0;
}

.newFilm {
  text-align: left;
  display: inline-block;
  background-color: #ff6699;
  width: 80%;
  padding: 20px;
}

label {
  font-size: 1em;
  padding: 6px;
  color: #fff;
  font-weight: 700;
  display: block;
  text-align: left;
}

.form {
  margin: auto;
  display: flex;
  text-align: center;
  flex-direction: column;
}

h2 {
  font-weight: 700;
  font-size: 2em;
  width: 50%;
  color: #B2365F;
}

#formTitle {
  margin-top: 0;
  margin-bottom: 0;
}

.row {
  margin-left: -20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.col {
  padding: 20px;
}

input,
textarea,
select {
  width: 100%;
  display: block;
  border-radius: 25px;
  background-color: #e0e0e0;
  padding: 10px;
  border: none;
  box-sizing: border-box;
}


}
.tagline {
  margin: 0;
  color: #333333;
  font-size: 1em;
  font-weight: 700;
}
input::placeholder {
  color: #000;
}
textarea::placeholder {
  color: #000;
}
#modifyFilmButton {
  float: right;
}
@media only screen and (max-width: 700px) {
  .row {
    grid-template-columns: 1fr;
  }
}
@media screen and (max-width:800px) {
  table {
    border: 0;
  }
  
  table caption {
    font-size: 1.3em;
  }
  
  table thead {
    border: none;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
  }
  
  table tr {
    border: 2px solid #e0e0e0;
    background-color: #e0e0e0;
    display: block;
    margin-bottom: .625em;
    border-radius: 20px;
  }
  
  table td {
    display: block;
    font-weight: bold;
    font-size: 1.2em;
    text-align: left;
    padding: 15px;
  }
  
  table td::before {
    /*
    * aria-label has no advantage, it won't be read inside a table
    content: attr(aria-label);
    */
    content: attr(data-label);
    float: left;
    font-weight: bold;
    text-transform: uppercase;
  }
  
  table td:last-child {
    border-bottom: 0;
  }
}
.oldFilm {
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  text-align: left;
  display: inline-block;
  background-color: #AAAAAA;
  width: 80%;
  padding: 20px;
}
#oldTitle {
  margin-top: 0;
  margin-bottom: 0;
  color: #ff6699;
  padding-bottom: 20px;
}
td {
  padding: 5px;
  font-weight: bold;
}
table {
  border-collapse: collapse;
  text-align: center;
  width: 100%;
}
thead {
  background: #ff6699;
}
.reviewImage {
  width: 200px;
  border-radius: 20px;
}
.filmRow img {
  width: 300px;
  height: 420px;
  margin: 10px;
  border-radius: 20px;
}
.filmRow {
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
}
#filmContainer {
  width: 100%;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-around;
}
#date {
  padding: 5px;
  text-align: left;
  width: 30%;
}
#date input {
  width: auto;
}
#date label {
  display: -webkit-inline-box;
}
#oldTitle2 {
  margin-top: 0;
  margin-bottom: 0;
  color: #ff6699;
}
.genre {
  padding: 5px;
  text-align: left;
  width: 60%;
}
.genre input {
  width: auto;
}
.genre label {
  display: -webkit-inline-box;
}

/* third page */
#filmImage {
  width: 300px;
  height: 420px;
  margin: 10px;
  border-radius: 20px;
}
#filmTitle {
  font-weight: 700;
  margin-bottom: 20px;
  font-size: 3em;
  width: 100%;
  color: #B2365F;
}
#leftcol {
  width: 25%;
  display: flex;
  flex-direction: column;
}
#rightcol {
  display: flex;
  flex-direction: column;
  width: 50%;
  margin: 5px;
}
#rightcol label {
  padding: 0;
}
#rightcol p {
  margin-bottom: 10px;
  margin-top: 2px;
}
#filmContainer2 {
  width: 100%;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
}
#indent {
  margin: 5px;
}
<header>
  <img src="img/rv-logo.png">
  <p class="tagline">Want to know whether or not it's worth paying to watch a certain film or not? See what we think first!</p>
</header>


<div class="sortFilms">
  <div id="filmContainer2">
    <div id="leftcol">
      <img id='filmImage' src="https://images-na.ssl-images-amazon.com/images/I/51Gh9OaWVcL.jpg">
    </div>
    <div id="rightcol">
      <p id='filmTitle'>Deadpool</p>
      <div id="indent">
        <label>Year:</label>
        <p id='filmYear'>2016</p>
        <label>Genre:</label>
        <p id='filmGenre'>Action/Comedy</p>
        <label>Rating:</label>
        <p id='filmRating'>9/10</p>
        <label>Synopsis:</label>
        <p id='filmSynopsis'>blah blah blah blah</p>
      </div>
      <a href='viewFilms.html'>Back to list</a>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:3)

问题在于图像的div包含图像的宽度为25%,但是图像的宽度大于其父级的25%,因此图像溢出了其父级。您不应该尝试将图像宽度设置为100%。

要解决您的问题,请将图像的宽度设置为100%,并调整其父对象的宽度以调整图像大小

还有一个提示,如果您使用的是flexbox,请使用属性flex-wrap:wrap ...,以便flex内的div会根据屏幕尺寸自动下移

要了解有关flex的更多信息,请查看此链接 https://css-tricks.com/snippets/css/a-guide-to-flexbox/