我在左侧像图像的同一高度创建响应div有问题。在这个div中我想添加文本但是当我这样做时,当我尝试更改窗口的分辨率时,段落也会在高度和div元素中拉伸。 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>
&#13;
答案 0 :(得分:0)
如果您在position:absolute;
元素上使用#right-side
执行了类似的操作,该怎么办?
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>