Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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
Html hack:Modifying:before在内联css中_Html_Css - Fatal编程技术网

Html hack:Modifying:before在内联css中

Html hack:Modifying:before在内联css中,html,css,Html,Css,我在ASP.NET(razor)页面中有一个“动态样式”(不要问为什么,就是这样) 每件事都很有魅力。但它提示我现在需要将url放在“.myClass:before”(通过myClass:before{height:100px;position:absolute;background image:url('@myUrl');z-index:-1;})裁剪背景图像高度) 此修改只能在CSS中完成,但@myUrl是一个动态值。。。我们还没有动态CSS。。。快速修复怎么办?对的背景图像使用继承关键

我在ASP.NET(razor)页面中有一个“动态样式”(不要问为什么,就是这样)


每件事都很有魅力。但它提示我现在需要将url放在“.myClass:before”(通过
myClass:before{height:100px;position:absolute;background image:url('@myUrl');z-index:-1;}
)裁剪背景图像高度)


此修改只能在CSS中完成,但
@myUrl
是一个动态值。。。我们还没有动态CSS。。。快速修复怎么办?

背景图像
使用
继承
关键字:在
伪元素之前,它将自动继承为
div定义的背景

同时将
背景大小:0 0
设置为div,这样图像就不会出现两次

div {
   background-size: 0 0;
}

div:before {
  content: "";
  display: block;
  background-image: inherit; 
  background-size: <your size here>;
  position: absolute;
  ...
}
div{
背景大小:0;
}
部门:以前{
内容:“;
显示:块;
背景图像:继承;
背景尺寸:;
位置:绝对位置;
...
}

示例:

伪元素之前的
背景图像
使用
继承
关键字,因此它将自动继承为
div定义的背景

同时将
背景大小:0 0
设置为div,这样图像就不会出现两次

div {
   background-size: 0 0;
}

div:before {
  content: "";
  display: block;
  background-image: inherit; 
  background-size: <your size here>;
  position: absolute;
  ...
}
div{
背景大小:0;
}
部门:以前{
内容:“;
显示:块;
背景图像:继承;
背景尺寸:;
位置:绝对位置;
...
}

示例:

您不能,主要是因为:before元素不是要操作的真正元素?AFAIK nothing。CSS无法检测内联样式并将其扩展到样式表中的某些内容。我理解,但正在搜索一个hack…添加一个
元素,用普通的旧CSS编写它并注入变量?局部视图,无法访问head元素。。。但是通过jquery可能…你不能,主要是因为:before元素不是一个真正的可操作元素?AFAIK nothing。CSS无法检测内联样式并将其扩展到样式表中的某些内容。我理解,但正在搜索一个hack…添加一个
元素,用普通的旧CSS编写它并注入变量?局部视图,无法访问head元素。。。但是通过jquery也许…这真的可以是一个解决方案(如果div背景不使用自映像),这真的可以是一个解决方案(如果div背景不使用自映像)