Css查询选择由某个元素分隔的内联文本

时间:2016-05-27 12:57:05

标签: html css

如何通过CSS查询选择文本内容,由一些元素分隔,比如你有:

Some text content
<div>Another content</div>
And additional content

您想选择Some text contentAnd additional content

2 个答案:

答案 0 :(得分:0)

我认为您不能从CSS引用inline-text,因为您没有任何内容可以链接到它。您可以将一些样式应用于容器,然后在id内为您的文字添加div以使其与众不同。

在这种情况下,我使用根元素*,但如果将代码包装在容器中,行为将是相同的。

&#13;
&#13;
*{
  color: red;
}

#text{
  color: blue;
}
&#13;
Some text content
<div id="text">Another content</div>
And additional content
&#13;
&#13;
&#13;

编辑:您可以使用伪类创建具有不同样式的内容。

&#13;
&#13;
*{
  color: red;
}

div:before{
  content: "Some text content";
  display: block;
  color: blue;
}

div:after{
  content: "And additional content";
  display: block;
  color: blue;
}
&#13;
<div id="text">Another content</div>
&#13;
&#13;
&#13;

但在这种情况下,您没有创建内容,而是根据div创建内容。

答案 1 :(得分:0)

尝试此突出显示变化

public class MainActivity extends
AppCompatActivity implements GestureDetector.OnGestureListener ,  
GestureDetector.OnDoubleTapListener {

private TextView t;
private GestureDetectorCompat gd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    t=(TextView)findViewById(R.id.textView2);
    this.gd=new GestureDetectorCompat(this,this);
    gd.setOnDoubleTapListener(this);
}

@Override
public boolean onDown(MotionEvent e) {
    t.setText("on down");
    return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    t.setText("on Fling");
    return true;
}

@Override
public void onLongPress(MotionEvent e) {
    t.setText("on long press");

}

@Override
public void onShowPress(MotionEvent e) {
    t.setText("on show press");
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    t.setText("on scroll");
    return true;
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    t.setText("on single tap");
    return true;
}

@Override
public boolean onDoubleTap(MotionEvent e) {
    t.setText("on double tap");
    return true;
}

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    t.setText("on double tap event");
    return true;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    t.setText("on single tap confirmed");
    return true;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    this.gestureDetector.OnTouchEvent(event);
    return true;
}
        .paragraph-block {
            color: #aaa;
            margin-bottom: 10px;
            font-size: 15px;
        }

        .highlighted {
            color: green;
        }

        .highlighted.medium {
            /* color: blue; */ /* you can also add this if you want to change the color */
            font-size: 20px;
        }

        .highlighted.large {
            /* color: blue; */ /* you can also add this if you want to change the color */
            font-size: 28px;
        }