简体   繁体   English

使用flex-direction列的CSS转换比例

[英]CSS transform scale with flex-direction column

I'm trying to use CSS transform: scale(1.5); 我正在尝试使用CSS transform: scale(1.5); within a flex container. 在flex容器中。 I need the hidden content to be displayed above and centered to the original text, so to do this I am using flex-direction: column; 我需要hidden内容显示在上面,并以原始文本为中心,所以为了做到这一点,我使用flex-direction: column; which works. 哪个有效。

The issue is when the transform executes, the sibling html element grows too. 问题是当transform执行时,同级html元素也会增长。 (You can see the behavior within the code snippet) (您可以在代码段中看到行为)

I'm sure I'm missing something simple but I've tried several solutions can't figure out why this is happening. 我确定我错过了一些简单的东西,但我已经尝试了几种解决方案无法弄清楚为什么会发生这种情况。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

 $(document).ready(function() { $('[data-action="clickable"]').mousedown(function(item) { $(item.currentTarget).addClass('flex-item-blowout'); $(item.currentTarget).find('.hidden').addClass('displayed'); $(item.currentTarget).find('.hidden').removeClass('hidden'); }); $('[data-action="clickable"]').mouseup(function(item) { $(item.currentTarget).removeClass('flex-item-blowout'); $(item.currentTarget).find('.displayed').addClass('hidden'); $(item.currentTarget).find('.displayed').removeClass('displayed'); }); $('[data-action="clickable"]').mouseleave(function(item) { $(item.currentTarget).removeClass('flex-item-blowout'); $(item.currentTarget).find('.displayed').addClass('hidden'); $(item.currentTarget).find('.displayed').removeClass('displayed'); }); }); 
 .flex-container { padding: 0; margin: 0; list-style: none; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-flex-flow: row; line-height: 30px; } .flex-item { background: burlywood; color: white; margin: 3px; font-weight: bold; font-size: 1.5em; min-width: 20%; max-width: 20%; display: flex; justify-content: center; flex-direction: column; text-align: center; min-height: 50px; user-select: none; } .flex-item-blowout { transform: scale(1.5); background-color: coral; } .hidden { display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="flex-container"> <div class="flex-item" data-action="clickable"> <span class="hidden">2</span><span>1 + 1</span> </div> <div class="flex-item" data-action="clickable"> <span class="hidden">3</span><span>1 + 2</span> </div> </div> 

Just add align-items: flex-start to the .flex-container , which will prevent the default behavior of the value stretch . 只需将align-items: flex-start.flex-container ,这将阻止值stretch默认行为。

 $(document).ready(function() { $('[data-action="clickable"]').mousedown(function(item) { $(item.currentTarget).addClass('flex-item-blowout'); $(item.currentTarget).find('.hidden').addClass('displayed'); $(item.currentTarget).find('.hidden').removeClass('hidden'); }); $('[data-action="clickable"]').mouseup(function(item) { $(item.currentTarget).removeClass('flex-item-blowout'); $(item.currentTarget).find('.displayed').addClass('hidden'); $(item.currentTarget).find('.displayed').removeClass('displayed'); }); $('[data-action="clickable"]').mouseleave(function(item) { $(item.currentTarget).removeClass('flex-item-blowout'); $(item.currentTarget).find('.displayed').addClass('hidden'); $(item.currentTarget).find('.displayed').removeClass('displayed'); }); }); 
 .flex-container { padding: 0; margin: 0; list-style: none; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-flex-flow: row; line-height: 30px; align-items: flex-start; } .flex-item { background: burlywood; color: white; margin: 3px; font-weight: bold; font-size: 1.5em; min-width: 20%; max-width: 20%; display: flex; justify-content: center; flex-direction: column; text-align: center; min-height: 50px; user-select: none; } .flex-item-blowout { transform: scale(1.5); background-color: coral; } .hidden { display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="flex-container"> <div class="flex-item" data-action="clickable"> <span class="hidden">2</span><span>1 + 1</span> </div> <div class="flex-item" data-action="clickable"> <span class="hidden">3</span><span>1 + 2</span> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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