简体   繁体   中英

How to vertically align a text in a div which has overflow hidden?

I have a gridView in asp which will generate a table. As I need to show only fixed number of lines in a TD looking around I came to decision to place a div inside a td so then I could achieve my goal.

table.XDataGridView td div.inner-table-div {
height: 32px;
padding: 1px;
overflow: hidden;
display: block;
}

.rfTaskExecutionWrapper td {
    min-width: 100px;
    font-size: 12px;
}

这是当前行为

I want that first column to be vertically aligned on center, same for second column. I also wish to show only 2 or 3 lines of text. For that I've limited the height though it seems that I still see some text of third line - which I don't want.

The solution has to work on chrome and on Internet Explorer 7(on windows CE).

Vertically aligning the content of a table cell can be done using vertical-align: middle on your td.

If you want to make sure there's only two lines visible in your second colomn, use line-height. The height of your div is 32 pixels. you have a padding of 1 pixel on the top and the bottom so that leaves 30 pixels. (asuming you're using the standard box-sizing) That means that if you add line-height: 15px to your div, you will only see two lines and no trailing third line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM