久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CSS選擇器用于選擇另一個(gè)元素之前的元素?

CSS Selector for selecting an element that comes BEFORE another element?(CSS選擇器用于選擇另一個(gè)元素之前的元素?)
本文介紹了CSS選擇器用于選擇另一個(gè)元素之前的元素?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在為我的網(wǎng)站創(chuàng)建一個(gè)登錄頁(yè)面,我想在文本框獲得焦點(diǎn)時(shí)將輸入框之前的標(biāo)簽加粗.現(xiàn)在我有以下標(biāo)記:

I'm working on a login page for my website and I want to bold the label that comes before the input box when the text box gains focus. Right now I have the following markup:

<label for="username">Username:</label>
<input type="textbox" id="username" />

<label for="password">Password:</label>
<input type="textbox" id="password" />

我可以使用相鄰選擇器選擇標(biāo)簽after文本框,但我不能選擇它之前的元素.我可以使用這個(gè) CSS 選擇器規(guī)則,但它只選擇后面的標(biāo)簽,所以當(dāng)用戶名文本框獲得焦點(diǎn)時(shí),密碼標(biāo)簽變?yōu)榇煮w.

I can use the adjacent selector to select the label after the text box, but I can't select the element before it. I can use this CSS selector rule, but it only selects the label after, so when the username text box gains focus, the password label becomes bold.

input:focus + label {font-weight: bold}

我能做些什么來(lái)完成這項(xiàng)工作嗎?我知道 JavaScript 可以很容易地做到這一點(diǎn),但如果可能的話,我想使用一個(gè)純基于 CSS 的解決方案,我只是想不出辦法.

Is there anything I can do to make this work? I know JavaScript could be used to easily do this, but I'd like to use a purely CSS-based solution if possible, I just can't figure out a way to do it.

推薦答案

如果 inputlabel 之前,則可以使用相鄰兄弟選擇器".只需將 input 放在 label 之前,然后修改布局將 label 放在 input 之前.這是一個(gè)例子:

It would be possible to use the 'adjacent sibling selector' if the input was before the label. Just put the input before the label, and then modify the layout to put label before the input. Here's an example:

<head runat="server">
    <title></title>
    <style type="text/css">
    input:focus + label {font-weight: bold}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="direction:rtl">
        <input type="text" id="username" />
        <label for="username">Username:</label>
    </div>
    <div style="direction:rtl">
        <input type="password" id="password" />
        <label for="password">Password:</label>
    </div>
    </form>
</body>

(這是一種 hack,我個(gè)人會(huì)使用 javascript 來(lái)做到這一點(diǎn))

(It's kind of a hack, I would personally use javascript to do this)

input:focus + label {font-weight: bold}

<form id="form1" runat="server">
  <div style="direction:rtl">
    <input type="text" id="username" />
    <label for="username">Username:</label>
  </div>
  <div style="direction:rtl">
    <input type="password" id="password" />
    <label for="password">Password:</label>
  </div>
</form>

這篇關(guān)于CSS選擇器用于選擇另一個(gè)元素之前的元素?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Style every third element?(每隔三個(gè)元素設(shè)置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應(yīng)該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個(gè)元素)
How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無(wú) js)選擇所有其他 div 類(lèi)元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
主站蜘蛛池模板: 亚洲国产欧美在线 | 国产精品一区二区三区免费 | 日韩欧美视频在线 | 欧美日韩激情 | 国产黄网 | 亚洲精品成人网 | 国产日韩欧美亚洲 | 国产视频一区在线观看 | 欧美日韩专区 | 久久伊人国产 | 艳妇诱春(第5部分)(h) | 中文字幕av在线 | 99热最新 | 日韩理论视频 | 草草视频在线 | 欧美在线网址 | 国产视频a| 加勒比综合 | 在线看亚洲 | 亚洲一二区 | 一级黄色免费 | 在线精品一区 | 中文字幕在线观看免费视频 | 美日韩精品 | 夜夜狠狠擅视频 | 青娱乐福利视频 | 成人激情在线 | 黄色片免费 | 国产伦精品一区二区 | 在线网站免费观看18 | 日韩性视频 | 日狠狠| 久草免费福利 | 中文字幕丰满人伦在线 | 国产成人午夜高潮毛片 | 亚洲美女一区 | 天天色影院 | 精品国产99 | 精品福利一区 | brazzers疯狂作爱 | 欧美日韩国 |