$(document).ready(function() {
$(window).resize(function() {
var altura = $(".textiu").height();
if (altura > 20) {
$('.logo').css("background-color", "yellow")
}
});
});
.logo {
background-color: gray;
height: 50px;
padding-top: 4%;
padding-bottom: 2%;
}
.menu {
display: flex;
justify-content: space-between;
align-content: center;
width: 100%;
}
.textiu {
display: block;
background-color: orange;
padding-top: 5%;
padding-bottom: 5%;
background-color: orange;
color: white;
transition: background-color, color, 1s;
}
.fotiu {
display: block;
background-color: white;
height: 60px;
}
.butt {
background-color: Transparent;
width: 100%;
padding: 0;
border: 0;
position: relative;
transition: background-color 1s;
border-right: 1px solid #e6e6ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="logo"></div>
<div class="menu">
<button class="butt"><span class="textiu">Quem Somos</span><span class="fotiu"></span>
</button>
<button class="butt"><span class="textiu">Portfólio</span><span class="fotiu"></span>
</button>
<button class="butt"><span class="textiu">Contato</span><span class="fotiu"> </span>
</button>
<button class="butt"><span class="textiu">Facebook</span><span class="fotiu"></span>
</button>
</div>
This is the fiddle. https://jsfiddle.net/ks6udwLc/
What I need:
I want to change the height of the span with text (
.textiu
), based on the first one's size (it's got two words, so on browser resizing it breaks into two lines and messes the layout).In the JavaScript I posted, it works on my browser (Chrome). Right now I'm changing another div's color just to check if it was working, since I don't know how to proceed. So I've got 3 questions:
How I can make the
.height
check without a fixed number? I was thinking of maybe getting the span height, and use something like if(altura > altura + 50% of altura or something like that). It is possible?How can I change the height of the other buttons? I would change height and add a
<br>
to get the text to the bottom of the space, just like the bigger one. Saw some use of (this) or similar in jQuery, but couldn't figure it out. All the buttons have the same class, by the way.Finally, is jQuery actually is the best way for this, or I should just use a media query for this?