我有HTML标记,我无法改变.
例
<p>
TEXT 1
<hr>some text
<hr>
<hr>TEXT 2
<hr>some text
</p>
Run Code Online (Sandbox Code Playgroud)
我想删除任何hr紧跟在另一个之后hr没有文本的东西.正如您从下面的代码片段中看到的那样,额外的hr是导致双线.
我认为这不可能用CSS.我尝试使用相邻(+)选择器,但意识到它显然不起作用.
我看着使用jQuery:empty,但由于hr自我关闭,我发现很难定位.
我很感激任何建议.
片段
body {
width: 500px;
margin: 0 auto;
}
hr {
border-top: 3px solid #CCC;
border-bottom: none;
color: #CCC
}
hr + hr {
/* display: none; // doesn't work */
}Run Code Online (Sandbox Code Playgroud)
<p>
TEXT 1
<hr>some text
<hr>some more text
<hr>even more text
<hr>
<hr>TEXT 2
<hr>some text
<hr>some more text
<hr>even …Run Code Online (Sandbox Code Playgroud)我正在尝试检测文本中的字符,如果发现在HTML元素中将其包装在前面,则删除该字符.
例:
Case:
Run Code Online (Sandbox Code Playgroud)
变
<span class="th">Case</span>
Run Code Online (Sandbox Code Playgroud)
方法
我可以检测到:使用的存在:
if (str.indexOf(':') > -1)
Run Code Online (Sandbox Code Playgroud)
在我使用之前得到这个词:
var th = str.split(':')[0];
Run Code Online (Sandbox Code Playgroud)
要将单词包装在我尝试过的元素中:
var th_wrap = "<span class='th'></span>";
$(th).wrap(th_wrap);
Run Code Online (Sandbox Code Playgroud)
哪个不起作用.要删除:我试过:
th.replace(':', '');
Run Code Online (Sandbox Code Playgroud)
哪个也行不通.
为了使它稍微复杂一点,我想抓住任何一个someword:,而不仅仅是第一个.
我很感激任何指示,欢呼.(javascript或jQuery)
SNIPPET
var str = $('.target').html();
if (str.indexOf(':') > -1) {
var th = str.split(':')[0];
th.replace(':', '');
var th_wrap = "<span class='th'></span>";
$(th).wrap(th_wrap);
}Run Code Online (Sandbox Code Playgroud)
th { font-weight: bold; }Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="target">
Case 1:
<br />some text
<br />some more text
<br />even more …Run Code Online (Sandbox Code Playgroud)我有一个带有图像的专栏。该列的高度有限,我希望所有图像都垂直适合该列。这可能吗?我正在尝试使用 Flexbox,但尚未成功。
.zoom__images {
overflow: hidden;
height: 300px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
img {
width: auto;
height: auto;
}Run Code Online (Sandbox Code Playgroud)
<div class="zoom__images">
<img src="https://s-media-cache-ak0.pinimg.com/736x/42/d4/66/42d466fd73a3b284f49d3020c27cf80e--aloes-martin-omalley.jpg" class="" alt="Simple Picture">
<img src="https://s-media-cache-ak0.pinimg.com/736x/42/d4/66/42d466fd73a3b284f49d3020c27cf80e--aloes-martin-omalley.jpg" class="" alt="Simple Picture">
<img src="https://s-media-cache-ak0.pinimg.com/736x/42/d4/66/42d466fd73a3b284f49d3020c27cf80e--aloes-martin-omalley.jpg" class="" alt="Simple Picture">
<img src="https://s-media-cache-ak0.pinimg.com/736x/42/d4/66/42d466fd73a3b284f49d3020c27cf80e--aloes-martin-omalley.jpg" class="" alt="Simple Picture">
</div>Run Code Online (Sandbox Code Playgroud)
最好的祝愿