基本上,我有一個串列
來自 WYSIWYG 編輯器的標簽,底部邊距為 20 像素。但是,如果兄弟姐妹
標簽有一個標簽,我想洗掉該邊距,以便標簽可以設定邊距。我該怎么做?
這是我的造型
.wysiwyg {
p {
margin-bottom: 20px;
}
}
基本標記
<div class="wysiwyg">
<p></p>
<p></p>
<p></p>
// Styling must stop here so that there is no bottom margin from the first above <p> tag
<img />
<p></p>
<p></p>
<p></p>
</div>
uj5u.com熱心網友回復:
您可以使用tilde ~,它會選擇當前選擇器之后的所有元素,然后重置所有p之后的規則img:
.wysiwyg {
p {
margin-bottom: 20px;
}
img ~ p {
margin-bottom: 0;
}
}
這里有一個演示
.wysiwyg p {
margin-bottom: 20px;
background-color: red;
}
.wysiwyg img ~ p {
margin-bottom: 0;
background-color: transparent;
}
<div class="wysiwyg">
<p>1</p>
<p>2</p>
<p>3</p>
<img />
<p>4</p>
<p>5</p>
<p>6</p>
</div>
更多資訊可以在這里找到
uj5u.com熱心網友回復:
只需margin-top為img前面有p標簽的標簽設定一個否定:
.wysiwyg {
p {
margin-bottom: 20px;
}
p img {
margin-top: -20px;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/359713.html
標籤:javascript css 蠢货
