这是我的代码:
.solid_color{
background-color: gray;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<div class="solid_color col-xs-3"></div>
<div class="col-xs-9">
" <span>A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone</span> "
<i>(Quote from someone)</i>
</div>
</div>
目前div.solid_color
是一条线。它的高度应与邻居元素的高度相同。我怎么能这样做?
答案 0 :(得分:4)
您可以使用 Flexbox 执行此操作:
.parent {
display: flex;
/* reason: "align-items: stretch" which makes flex-items of equal height by default, obviously they all take the height of the "tallest" one */
}
.solid_color {
background-color: gray;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="parent">
<div class="solid_color col-xs-3"></div>
<div class="col-xs-9">
" <span>A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone</span> "
<i>(Quote from someone)</i>
</div>
</div>
&#13;
答案 1 :(得分:1)
您只需使用选择器通过JS执行此操作,并使用var height = document.querySelector('.col-xs-9').getBoundingClientRect().height;
document.querySelector('.solid_color').style.height = height + 'px';
找到所需的高度。
.solid_color{
background-color: gray;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<div class="solid_color col-xs-3"></div>
<div class="col-xs-9">
" <span>A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone</span> "
<i>(Quote from someone)</i>
</div>
</div>
#include <iostream>
#include <string>
#include <algorithm>
int main() {
std::cout << "Enter string: ";
std::string s;
std::getline(std::cin, s);
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
std::cout << s;
}
答案 2 :(得分:0)
在父容器中添加display: flex;
,然后从子div中删除height: 100%;
。
.solid_color{
background-color: gray;
}
.myparent{
display: flex;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="myparent">
<div class="solid_color col-xs-3"></div>
<div class="col-xs-9">
" <span>A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone</span> "
<i>(Quote from someone)</i>
</div>
</div>
希望这个帮助
答案 3 :(得分:0)
我会给背景颜色的div一个绝对的位置,并用带有一些边距的文本推过div。请参阅以下代码:
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<style>
.solid_color {
position: absolute;
left: 0;
top: 0;
width: 25%;
height: 100%;
background-color: gray;
}
.outer {
position: relative;
float: left;
display: block;
width: 100%;
}
.right-text {
margin-left: 25%;
}
</style>
</head>
<body>
<div class="outer">
<div class="solid_color col-xs-3"></div>
<div class="right-text col-xs-9">
" <span>A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone A sentence from someone</span> "
<i>(Quote from someone)</i>
</div>
</div>
</body>
</html>