如何为所选文本设置突出显示颜色

时间:2019-09-11 15:06:59

标签: css python-3.x gtk3

我有一个包含以下代码段的python3程序:

function show(){

ob_start(); // should usually start a shortcode with an output buffer

$args = array(
    'post_type' => 'attachment',
    'post_mime_type' => 'image',
    'orderby' => 'post_date',
    'order' => 'desc',
    'posts_per_page' => '30',
    'post_status'    => 'inherit'
     );

$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

$image = wp_get_attachment_image_src( get_the_ID() ); ?>

// You don't have to echo divs you can use html tags in PHP

     <div class="numbertext">1</div>
      <img src="<?php echo $image; ?>" />
       <div class="title"> 
         <?php the_title(); ?>
       </div>
     </div>

<?php
endwhile; 

// put the content in a variable creating from the output buffer
$content = ob_get_clean(); 

// return the content
return $content;

};
add_shortcode( 'imgshow', 'show' );

选择文本后,所选内容将不可见。要设置突出显示颜色和突出显示背景颜色,必须在“ css”语句中添加什么内容?

互联网搜索显示了许多HTML结果,但没有适合这种情况的示例。一个实际的例子会更好。

1 个答案:

答案 0 :(得分:0)

我可能会弄错,但是您可能需要添加css“选择”伪元素。

所以尝试这样的事情:

dmsg.set_selectable(True)
dmsg.set_name("sMsg")
style_provider = Gtk.CssProvider()
css = "#sMsg { background-color: #002348; color: white; padding: 4px 8px; } #sMsg::selection {color: red; background: yellow;}"
style_provider.load_from_data(bytes(css.encode()))
Gtk.StyleContext.add_provider_for_screen(
    Gdk.Screen.get_default(),
    style_provider,
    Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

有关更多信息,请参见here