How to make elements automatically adjust?

Asked

Viewed 50 times

1

So I have this button screen:

inserir a descrição da imagem aqui

These buttons, when clicked, redirect the user to email, maps, phone, finally...

When the user DOES NOT have one of these data, logically, tbm will not have the button, as I put of example the image above.

The first user has all the data, the second has no link to share and the third has only phone.

My question is:

How do I automatically adjust these buttons?

It would be pretty stupid of me to go testing all the data for myself to adjust in the hand, as the image below, when the user only has phone:

inserir a descrição da imagem aqui

if(!email){
    if(!localizacao){
        if(!compartilhar){
           $('#' + id + '.telefone').css('width', '83.1%');

        }
     }
 }

I just can’t think of any other way to do it...

Here is the HTML of the buttons:

$(".listagem-cartoes").append(
        `<div class="item-display">
            <div class="item draggable ui-widget-content">
                <div class="side info lista-cartoneira foto" id=${id}>
                    <div class="avatar">
                        <img src="${capa}" alt="" class="circle responsive-img"> 
                    </div>
                    <div class="nomes">
                        <div class="nome-empresa lista-cartoneira"><h1>${empresa}</h1></div>        
                        <div class="nome lista-cartoneira"><h2>${nome}</h2></div>        
                    </div>
                    </div>
                    <div class="side buttons">
                        <div class="atalhos-cartoneira col s4 botaoCompartilhar${id}" id=${id} style="background-color: #00BFA5;">
                            <i class="material-icons compartilhar" id=${id}>open_in_new</i>
                        </div>                    
                    <div class="atalhos-cartoneira col s4 botaoLocalizacao${id}" id=${id} style="background-color: #757575;">
                        <i class="material-icons localizacao" id=${id}>place</i>
                    </div>
                    <div class="atalhos-cartoneira col s4 botaoEmail${id}" id=${id} style="background-color: #ffb74d;">
                        <i class="material-icons email" id=${id}>email</i>
                    </div>
                    <div class="atalhos-cartoneira col s4 botaoTelefone" id=${id} style="background-color: #00b0ff;">
                        <i class="material-icons telefone" id=${id}>phone</i>
                    </div>
                </div>
            </div>            
        </div>`
    );  

I’m using Materialize 0.100.2.

I didn’t add anything else to the css, so I think it’s unnecessary to add the css here, because it’s not related to anything in the buttons.

  • It would be interesting to ride a [mcve]. Your problem consists only of HTML and CSS, so you can play your situation smoothly without relying on your application’s logic.

  • By the way, in the buttons HTML there are always the 4 elements, so in which part of the code you check which should be visible? And why did you use the class s4 to display 4 elements? If the grid has 12 columns, 4 elements with .s4 will exceed the width.

  • @Andersoncarloswoss I put as an example there... I make a query in the database and check the data, which does not have I remove the button

  • In my opinion it is not duplicated, the AP is looking for a solution using the framework mentioned in the question. You may have something ready (just like Bootstrap has) without applying custom css to change components.

  • @Renan see that the version of Materialize that he is using Grid is based on floats and fixed values (even if in %) for the columns http://archives.materializecss.com/0.100.2/grid.html. And on helpers framework classes do not exist for this type of adaptation http://archives.materializecss.com/0.100.2/helpers.html. So he will need a customized CSS solution, which leads us to mark this question as duplicate, since in the other question there is an option that can solve the problem https://answall.com/a/57414/97477.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.