如何仅使用CSS调整帖子内第一张图片的大小,而不影响帖子中的任何其他图片。如果我使用以下代码:
#content div.single:nth-of-type(n) img {
width: 448px !important;
height: 252px !important;
padding: 0 !important;
margin-top: 0;
调整帖子内的所有图片大小。
我也试过nth-child但没有成功:
#content div.single img:nth-child(1){
width: 448px !important;
height: 252px !important;
padding: 0 !important;
margin-top: 0;}
这是the Demo
答案 0 :(得分:1)
为什么不像这样定位你想要的图像:
.alignnone.size-full.wp-image-35095 {
width: 448px !important;
height: 252px !important;
padding: 0 !important;
margin-top: 0;
}
当你有一个带空格的类时,你会在css中定位该类,但是你用一个点来改变每个空格。
如果您希望始终定位帖子中的第一个图像,那么您可以运行Jquery:
$( "#content img" ).first().attr('width', '150');
顺便说一下,你的第一张照片中有一个重要的部分,我为什么不能正常工作而感到困难:P
答案 1 :(得分:1)
你可以试试这个:
#content div.single img:first-child {
width: 448px !important;
height: 252px !important;
padding: 0 !important;
margin-top: 0;
}
答案 2 :(得分:1)
使用CSS轻松解决它:
.single p:nth-child(2) > img {
width: 448px !important;
height: 252px !important;
padding: 0 !important;
margin-top: 0;
}