Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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
使用JSOUP Java更改CSS_Java_Css_Jsoup - Fatal编程技术网

使用JSOUP Java更改CSS

使用JSOUP Java更改CSS,java,css,jsoup,Java,Css,Jsoup,我有这个字符串,它由HTML语法组成,但也有一些CSS标记,例如: <style type='text/css'> #gallery-1 { margin: auto; } #gallery-1 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 25%; } #gallery-1 img { border: 2px solid #cfcfcf; } #gallery-1 .gallery

我有这个字符串,它由HTML语法组成,但也有一些CSS标记,例如:

<style type='text/css'> #gallery-1 { margin: auto; } #gallery-1 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 25%; } #gallery-1 img { border: 2px solid #cfcfcf; } #gallery-1 .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */ </style> 
#gallery-1{margin:auto;}#gallery-1.gallery项{float:left;margin top:10px;文本对齐:居中;宽度:25%;}#gallery-1 img{border:2px solid#cfcfcfcf};#gallery-1.gallery标题{margin left:0;}/*请参见wp includes media.php*中的gallery#u shortcode()

我想更改
宽度:25%至<代码>宽度:100%在JSOUP的帮助下。我怎样才能像这样访问字符串中的CSS标记

Jsoup不解析CSS,但是如果您只关心这个特定页面,您可以更改元素的文本:
element.text(element.text().replace(“宽度:25%;”,“宽度:100%;”))

对于更一般的CSS转换,您需要一个实际的CSS解析器,如Shahrukh评论中建议的那样。

试试这个