Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use css to shrink text to automatically fit the size of the div

Tags:

html

css

ejs

I have been working on a project and there is one page where it would show several divs (using ejs), but if one div has 3 lines and the other has 2, one would be a lot bigger than the other.

enter image description here

And here is my code for the HTML / ejs file:

<div id = "home" class = "container">
<h1 class="polls-head">Polls</h1>
<div class="main-aligner">        
    <% for(var i = 0; i < allPolls.length; i++){ %>
    <div class="title" id="dynamicDiv">
        <div class="poll-name" id="dynamicSpan">
        <%= allPolls[i].title %>
    </div>
    <div class="poll-link">
        <div class= "poll-view">
            <a href="polls/<%= allPolls[i]._id %>" class="btn button view">View Poll</a>
        </div>
        <div class="createdBy">
            <p>Created by: <%=allPolls[i].createdBy %></p>
        </div>
    </div>
    </div>
    <%}%>
</div>
</div>

And for the CSS file

.title
{
    font-family: "Lato";
    width: 365px;
    height: auto;
    min-height: 150%;
    background-color: #dfdce3;
    display: inline-block;
    margin-top: 10px;
    margin-right: 5px;
    margin-left: 5px;
    text-align: center;
}
.poll-name
{
    font-size: 50px;   
}

Is it possible to shrink the size of the text automatically if it is longer than 2 lines? Or is there any way I can make all the boxes the same size so the boxes are always the same size as the box with the most lines?

like image 970
Elisa L Avatar asked Jul 19 '17 03:07

Elisa L


People also ask

How do I automatically adjust font size in CSS?

The font-size-adjust property of CSS tells the browser to adjust the font size of the text to the same size regardless of font family. When the first chosen font is not available, the font-size-adjust property allows you more control over the font size.

How do I shrink text in HTML?

The HTML <small> element is found within the <body> tag. The <small> tag is used to make the text one size smaller (ie: from x-large to large, large to medium, medium to small). The <small> tag can not make the text smaller than the browser's minimum font size.

Which CSS property is used for the text size?

The font-size CSS property sets the size of the font.


1 Answers

You can try to use this code below

.poll-name {
  overflow: hidden;
  text-overflow: ellipsis;
  word-wrap: break-word;
  display: block;
  line-height: 1em; /* a */
  max-height: 2em; /* a x number of line to show (ex : 2 line)  */
}

Cheers!

like image 130
Spartan Avatar answered Oct 14 '22 00:10

Spartan