Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果有多个图像,请添加样式_Javascript_Html_Css - Fatal编程技术网

Javascript 如果有多个图像,请添加样式

Javascript 如果有多个图像,请添加样式,javascript,html,css,Javascript,Html,Css,我正在使用一个文本编辑器来编辑文章,为内容的每个部分创建 有时内容包含一个或多个图像,有时没有图像 .邮政{ 背景色:000; 边缘底部:20px; 颜色:fff } .后img+img{ 宽度:50% } 第一个职位 第二职位 试试这个: 选择一个子帖子 .post p img:first-child:nth-last-child(1) { width: 100%; } 选择包含更多子项的帖子 /* Select the first of more */ .post p i

我正在使用一个文本编辑器来编辑文章,为内容的每个部分创建

有时内容包含一个或多个图像,有时没有图像

.邮政{ 背景色:000; 边缘底部:20px; 颜色:fff } .后img+img{ 宽度:50% } 第一个职位

第二职位

试试这个:

选择一个子帖子

.post p img:first-child:nth-last-child(1) {
    width: 100%;
}
选择包含更多子项的帖子

/* Select the first of more */
.post p img:nth-child(1) {
    width:60%
}

/* Select others of more except the first */
.post p img:nth-child(n+2) {
    width: 10%;
}
.邮政{ 背景色:000; 边缘底部:20px; 颜色:fff; 宽度:100%; } .产后img:第一个孩子:第n个最后一个孩子1{ 宽度:100%; } .p后图像:N-child1{ 宽度:60% } .p后img:N个孩子n+2{ 宽度:10%; } 第一个职位

第二职位


当只有一个图像时,第一个和最后一个图像是相同的,因此您可以将其设置为100%或任何您想要的值。

在此处输入代码您可以使用Jquery确定每个img的宽度。对我来说,最简单的方法是:

对于let i=0;i<$邮政编码长度;i++{ 让items=$$”.post p'[i].children; items.css'width',100/items.length+'%'; } * { 保证金:0; 填充:0; 框大小:边框框; } 氢{ 文本对齐:居中; 文本阴影:1px1111; 填充:20px0; } p{ 填充:0; 显示器:flex; } .邮政{ 背景颜色:999; 边缘底部:20px; 颜色:fff; } .后img{ 填充:10px; } 第一个职位

第二职位


我想你可以用flexbox来做这个吗?@MohitBhardwaj,我想这是可以做到的,但我认为flexbox在现代浏览器中是受支持的,但我不介意去看看
.post p img:first-child, .post p img:last-child {
  width:50%;
}
.post p img:last-child:first-child {
    width:100%
}
   .post p img {
      width:50%;
    }
    .post p img:last-child:first-child {
        width:100%
    }