html - 在右侧创建响应元素

标签 html css

我无法在与左侧图像相同的高度上创建响应式 div。在此 div 中,我想添加文本,但是当我这样做时,当我尝试更改窗口的分辨率时,段落的高度和 div 元素也会拉伸(stretch)。 Check codepen

HTML:

#left-side {
  width: 50%;
  height: 60em;
  background-color: black;
  float: left;
  text-align: center;
  display: inline-block;
}

#left-side>div>img {
  margin-top: 15%;
  border: solid #A98646 2px;
  border-bottom: none;
  width: 50%;
  height: 25%;
}

#right-side {
  width: 50%;
  height: 60em;
  background-color: red;
  float: left;
  text-align: center;
  display: inline-block;
}

.description {
  margin-top: 15%;
  width: 50%;
  height: 72%;
  margin-left: 25%;
  background: green;
}
<section>
  <article id="left-side">
    <div class="image">
      <img src="img1.jpg">
    </div>
  </article>
  <article id="right-side">
    <div class="description">2</div>
  </article>
</section>

最佳答案

如果你在 #right-side 元素上用 position:absolute; 做这样的事情会怎么样?

CodePen

header{
    background-color: #282828;
    width: 100%;
    height: 35em;
}

header > h1{
    color: #A98646;
    font-family: 'Righteous';
    font-size: 4rem;
    text-align: center;
    padding-top: 6.75rem;
    
}

header .logo{
    width: 40px;
    margin-left: 2rem;
    margin-top: 2rem;
    opacity: 0.3;
}

header .logo:hover{
    opacity: 1;
    transition: 0.2s;
}

nav{
    float: right;
    margin-right: 2rem;
    margin-top: 0rem;
    text-align: center;
    cursor: pointer;
}

nav li{
    display: none;
    background-color: black;
}

nav>ul>img{
    width: 100px;
}

header > p{
    text-align: center;
    margin-top: 30px;
    color: white;
    font-family: 'Old Standard TT', serif;
}



#left-side{
    width: 50%;
    height: 60em;
    background-color: black;
    float: left;
    text-align: center;
    display: inline-block;
}
.image {
  height: 100%;
  position: relative;
}

#left-side>div>img{
    margin-top: 15%;
    border: solid #A98646 2px;
    border-bottom: none;
    width: 50%;
    height: 75%;
}


#right-side{
    width: 50%;
    height: 100%;
    background-color: red;
    text-align: center;
    display: inline-block;
    position: absolute;
}

.description{
    width: 50%;
    height: 75%;
    margin: 15% auto;
    background: green;

}


section { 
    height: 100%;
    display: inline-block;
    position: relative;
    width: 100%;
}
<section>
  <article id="left-side">
    <div class="image">
      <img src="img1.jpg">
    </div>
  </article>
  <article id="right-side">
    <div class="description">2</div>
  </article>
</section>

关于html - 在右侧创建响应元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50605180/

相关文章:

javascript - Typo3 中的响应式拆分菜单

html - CSS3 : border on a border-radius div

javascript - 如何通过 jquery 在任意位置单击隐藏弹出窗口?

javascript - 如何拉伸(stretch)图像以适合网页中的正方形?

javascript - jQuery - 查找其中包含多个 HTML 标记属性的元素

html - 如何将两个全屏大小的html元素放在彼此之上

javascript - 如何将这个动态创建的 3D 对象置于其父对象的中心?

javascript - 观察div中的属性变化

javascript - 更改 DIV 背景图像不起作用

html - 如何对齐有些有文本而有些没有文本的 div 元素?