我正在尝试使用jQuery计算文本宽度.我不确定是什么,但我肯定做错了什么.
所以,这是代码:
var c = $('.calltoaction');
var cTxt = c.text();
var cWidth = cTxt.outerWidth();
c.css('width' , cWidth);
Run Code Online (Sandbox Code Playgroud) 我有一个div:
<div class="test" id="someElement" style="position: absolute"></div>
Run Code Online (Sandbox Code Playgroud)
有没有办法检查是否有某个元素:
$("#someElement")
Run Code Online (Sandbox Code Playgroud)
有一个特定的类(在我的情况下,"测试").
或者,有没有办法检查en元素是否具有某种风格?在这个例子中,我想知道元素是否有" position: absolute".
非常感谢你!
我一直在使用Twitter的bootstrap,我希望进度条上的文本无论值多少都集中在on栏上.
以下链接是我现在拥有的.我希望所有文本都与最底部的条形对齐.
截图:

我已经尽力使用纯CSS,我尽量避免使用JS,但如果这是最干净的方法,我愿意接受它.
<div class="progress">
<div class="bar" style="width: 86%">517/600</div>
</div>
Run Code Online (Sandbox Code Playgroud) 在这个页面上,我有第一个div作为暗图像,第二个作为浅色背景.
我希望侧边栏文字颜色在暗图像上亮,在灯光上暗.
我将如何根据div背景中的颜色设置颜色?只需要两种颜色选择.
这是我正在寻找的另一个例子http://www.acnestudios.com/ example html:
<div id="home_wrapper">
<div id="home_top_t_wrap"> <!-- DARK BACKGROUND -->
<h1 class="top_text_h1"> Shop New York Like Never Before </h1> <!-- TEXT THAT NEEDS TO GO FROM LIGHT TO DARK --> </div>
<div id="the_market_container"> <!-- LIGHT BACKGROUND --></div>
</div>
Run Code Online (Sandbox Code Playgroud) 我想为文本颜色创建一个变量,但取决于我设置的背景颜色。
:root {
--main-color-hue: 205;
--main-color-saturation: 73%;
--main-color-luminosity: 29%;
--main-color: hsla(var(--main-color-hue), var(--main-color-saturation), var(--main-color-luminosity), 1);
--main-dark-color: hsla(var(--main-color-hue), var(--main-color-saturation), calc(var(--main-color-luminosity) * 0.5), 1);
--main-light-color: hsla(var(--main-color-hue), var(--main-color-saturation), calc(var(--main-color-luminosity) * 1.5), 1);
--main-text-color: red; /* calculate white or black */
--main-dark-text-color: red; /* calculate white or black */
--main-light-text-color: red; /* calculate white or black */
}
button {
background-color: var(--main-color);
color: var(--main-text-color);
border: 0;
padding: 16px;
}
button.dark {
background-color: var(--main-dark-color);
color: var(--main-dark-text-color);
border: 0;
padding: 16px;
}
button.light {
background-color: var(--main-light-color);
color: …Run Code Online (Sandbox Code Playgroud)