在div中居中放置文本(链接)

时间:2019-03-21 19:09:04

标签: html css text hyperlink center

由于某种原因,我的文本(链接)被推到了div容器之外。我想让文本在div内,并且让我点击文本即可,而不是整个div。

HTML

<div class="title">
        <a href="http://www.google.com">Work</a>
    </div>

CSS

.title {

  position: absolute;
  background-color: red;
  z-index: 5;
  height: 15em;
}

.title a {

  height: 15em;
  font-size: 150px;
  text-decoration: none;
  font-family: 'Inknut Antiqua', serif;
}

在浏览器中进行检查时,由于某种原因,''极大。

谢谢。

.title {

  position: absolute;
  background-color: red;
  z-index: 5;
  height: 15em;
}

.title a {

  height: 15em;
  font-size: 150px;
  text-decoration: none;
  font-family: 'Inknut Antiqua', serif;
}
<link href="https://fonts.googleapis.com/css?family=Inknut+Antiqua" rel="stylesheet">

<div class="title">
			<a href="http://www.google.com">Work</a>
		</div>

2 个答案:

答案 0 :(得分:0)

150px字体的行高非常大,并导致溢出。调整行高以获得所需的效果:

public abstract class BaseActivity extends AppCompatActivity {

    Handler handler;
    Runnable r;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        handler = new Handler();
        r = new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                Toast.makeText(BaseActivity.this, "user is inactive from last 5 minutes",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(BaseActivity.this,
                        VendorHub.class);
                startActivity(intent);
                finish();
            }
        };
        startHandler();
    }
    @Override
    public void onUserInteraction() {
        // TODO Auto-generated method stub
        super.onUserInteraction();
        stopHandler();//stop first and then start
        startHandler();
    }
    public void stopHandler() {
        handler.removeCallbacks(r);
    }
    public void startHandler() {
        handler.postDelayed(r, 1*60*1000); //for 5 minutes
    }


}

https://jsfiddle.net/srza8bhk/

答案 1 :(得分:0)

从定位标记中删除Id:number Name:string 。并将其height:15em设置为

喜欢:

line-height