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

CSS選擇器用于選擇另一個元素之前的元素?

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

問題描述

我正在為我的網站創建一個登錄頁面,我想在文本框獲得焦點時將輸入框之前的標簽加粗.現在我有以下標記:

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" />

我可以使用相鄰選擇器選擇標簽after文本框,但我不能選擇它之前的元素.我可以使用這個 CSS 選擇器規則,但它只選擇后面的標簽,所以當用戶名文本框獲得焦點時,密碼標簽變為粗體.

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}

我能做些什么來完成這項工作嗎?我知道 JavaScript 可以很容易地做到這一點,但如果可能的話,我想使用一個純基于 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 之前.這是一個例子:

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,我個人會使用 javascript 來做到這一點)

(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>

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

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

相關文檔推薦

Style every third element?(每隔三個元素設置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個元素)
How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無 js)選擇所有其他 div 類元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
主站蜘蛛池模板: 色网站视频 | 日本网站免费在线观看 | 在线黄色网 | 色嗨嗨| 国产成人精品一区二区三 | 国产情侣一区 | 久草99| 综合精品在线 | 欧美日本一区 | 日本高清中文字幕 | 成人福利网站 | 久久久精品视频免费看 | 亚洲欧美日韩国产综合 | 国产精品美女www爽爽爽视频 | 一区二区三区日 | 不卡视频一区二区三区 | 午夜精品 | 午夜免费电影院 | 色免费在线视频 | 狠狠爱网址 | 久久99视频免费观看 | 二区视频| 欧美在线一区二区三区 | 久草资源 | 色综合美女| 国产高清一区二区 | 精品视频久久久 | 毛片一区二区 | 成人影院在线视频 | 成人久久网 | 色吊丝2288sds中文字幕 | 久久综合狠狠综合久久 | 精品国产鲁一鲁一区二区张丽 | 亚洲精品视频在线观看免费 | 亚洲精品久久久久久一区二区 | 九九热精品视频 | 最近最新中文字幕 | 亚洲理论在线观看电影 | 国产精品色 | 国产三级在线观看播放 | 精品日韩一区二区 |