简体   繁体   English

是否有可能在CSS中执行这样的条件

[英]Is it possible to do conditionals like this in CSS

Let's say I have a CSS DIV that holds formatted syntax code. 假设我有一个CSS DIV,其中包含格式化的语法代码。 The DIV is set to a min-width:100; DIV设置为min-width:100; and a max-width:100; max-width:100;

This same DIV has another CSS declaration for when the DIV is Hovered, max-width: 135% !important; 当DIV悬停时,同一DIV还有另一个CSS声明, max-width: 135% !important; and min-width: 135%; min-width: 135%;

So if the DIV holding the formated code is wider then the DIV's width, it shows a scroll bar and when you hover over the DIV it expands the DIV to the width of the code not to exceed 135%, if the DIV's code does not exceed the width of the DIV then the DIV stays the same width. 因此,如果保存格式化代码的DIV宽于DIV的宽度,它会显示一个滚动条,当您将鼠标悬停在DIV上时,如果DIV的代码不超过135%,它会将DIV扩展到代码的宽度不超过135% DIV的宽度,则DIV保持相同的宽度。

My problem, is that when a div exceeds the 100% width, it expands to the width of the code inside but stays LESS then 135%, is there a way to make it expand to 135% even if the code is not 135% but is over 100%? 我的问题是,当div超过100%宽度时,它会扩展到内部代码的宽度,但保持LESS则为135%,有没有办法使它扩展到135%,即使代码不是135%而是超过100%?

Hopefully this makes sense 希望这有道理

I almost need some kind of conditional statement that says... 我几乎需要某种有条件的陈述,说...


If DIV contents are > 100% then make DIV 135% on Hover otherwise leave DIV at 100% 如果DIV含量> 100%,则在悬停时使DIV达到135%,否则将DIV保持为100%


Is this even possible? 这有可能吗?

Here is my full CSS 这是我的完整CSS

.syntax {
  min-width: 100%;
  max-width: 100%;
  margin: 1em 0 1em 0;
  position: relative;
  overflow-y: hidden;
  overflow-x: auto;
  font-size: .9em;
  display:inline-block;
}
.syntax:hover {
  max-width: 135% !important;
  min-width: 135%;
}

I'm not sure I'm getting waht you mean, but if I'm not mistaken, all you're leaving aside is this: 我不确定您的意思是什么,但是如果我没记错的话,您所要保留的就是:

min-width: 135% !important; 最小宽度:135%!重要;

you may need to adjust overflow depending on what you need 您可能需要根据需要调整溢出

A better option would be to use fixed sizes, but if you're working on adaptive layout environments guess that is a no go 更好的选择是使用固定大小,但是如果您在自适应布局环境中工作,那是不行的

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

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