- CSS DIV box transparent, text inside not transparent
- CSS Style
- HTML Body
- Related
- opacity
- Try it
- Syntax
- Values
- Description
- Accessibility concerns
- Formal definition
- Formal syntax
- Examples
- Setting opacity
- HTML
- CSS
- Result
- Setting opacity on hover
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- opacity
- Кратко
- Пример
- Как пишется
- Как понять
- Подсказки
- На практике
- Алёна Батицкая советует
CSS DIV box transparent, text inside not transparent
The following tutorial shows you how to use CSS to do «CSS DIV box transparent, text inside not transparent».
CSS Style
The CSS style to do «CSS DIV box transparent, text inside not transparent» is
div.finboks < position:absolute; width:1349px; height:115px; z-index:2; left:5px; top:102px; background-color:rgba(255,255,255,.4); -ms-filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#66FFFFFF,endColorstr=#66FFFFFF); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#66FFFFFF,endColorstr=#66FFFFFF); >
HTML Body
body> div >"finboks"> br> br> li>font size="3px">a href="index.html">HEIM li>font size="3px">a href="elevane.html">ELEVANE li>font size="3px">a href="tilsette.html">TILSETTE li>font size="3px">a href="Bilete.html">BILETE li>font size="3px">a href="kontakt.html">KONTAKT li>font size="3px">a href="omskulen.html">OM SKULEN select name="jumpMenu2" id="jumpMenu2" onchange="MM_jumpMenu('parent',this,0)"> option> LENKJER option value="https://fronter.com/sognfjordanegs/index.phtml">Fronter option value="https://www.gaular.kommune.no/Filnedlasting.aspx?MId1=39&FilId=335">Skuleruta 2012-13
The following iframe shows the result. You can view the full source code and open it in another tab.
html> head> meta name="viewport" content="width=device-width, initial-scale=1"> style id="compiled-css" type="text/css"> div.finboks< position: absolute; width: 1349px; height: 115px; z-index: 2;!-- w w w . d e mo 2 s . co m --> left: 5px; top: 102px; background-color:rgba(255,255,255,.4);/* modern browser */ -ms-filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#66FFFFFF,endColorstr=#66FFFFFF);/*IE fix */ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#66FFFFFF,endColorstr=#66FFFFFF); /* IE Fix */ > body> div >"finboks"> br>br> li>font size="3px">a href="index.html">HEIM li>font size="3px">a href="elevane.html">ELEVANE li>font size="3px">a href="tilsette.html">TILSETTE li>font size="3px">a href="Bilete.html">BILETE li>font size="3px">a href="kontakt.html">KONTAKT li>font size="3px">a href="omskulen.html">OM SKULEN select name="jumpMenu2" id="jumpMenu2" onchange="MM_jumpMenu('parent',this,0)"> option> LENKJER option value="https://fronter.com/sognfjordanegs/index.phtml">Fronter option value="https://www.gaular.kommune.no/Filnedlasting.aspx?MId1=39&FilId=335">Skuleruta 2012-13
Related
- CSS display text within a box using css (Demo 2)
- CSS display text within a box using css (Demo 3)
- CSS Displaying Textbox Value
- CSS DIV box transparent, text inside not transparent
- CSS div not showing above text box
- CSS div not showing above text box (Demo 2)
- CSS div not showing above text box (Demo 3)
demo2s.com | Email: | Demo Source and Support. All rights reserved.
opacity
The opacity CSS property sets the opacity of an element. Opacity is the degree to which content behind an element is hidden, and is the opposite of transparency.
Try it
Syntax
opacity: 0.9; opacity: 90%; /* Global values */ opacity: inherit; opacity: initial; opacity: revert; opacity: revert-layer; opacity: unset;
Values
Value | Meaning |
---|---|
0 | The element is fully transparent (that is, invisible). |
Any strictly between 0 and 1 | The element is translucent (that is, content behind the element can be seen). |
1 (default value) | The element is fully opaque (visually solid). |
Description
opacity applies to the element as a whole, including its contents, even though the value is not inherited by child elements. Thus, the element and its children all have the same opacity relative to the element’s background, even if they have different opacities relative to one another.
Using opacity with a value other than 1 places the element in a new stacking context.
To change the opacity of a background only, use the background property with a color value that allows for an alpha channel. For example:
Accessibility concerns
If text opacity is adjusted, it is important to ensure that the contrast ratio between the color of the text and the background the text is placed over is high enough that people experiencing low vision conditions will be able to read the content of the page.
Color contrast ratio is determined by comparing the luminosity of the opacity-adjusted text and background color values. In order to meet current Web Content Accessibility Guidelines (WCAG), a ratio of 4.5:1 is required for text content and 3:1 for larger text such as headings. Large text is defined as 18.66px and bold or larger, or 24px or larger.
Formal definition
Initial value | 1 |
---|---|
Applies to | all elements |
Inherited | no |
Percentages | map to the range [0,1] |
Computed value | The same as the specified value after clipping the to the range [0.0, 1.0]. |
Animation type | by computed value type |
Formal syntax
Examples
Setting opacity
The following example demonstrates how the opacity property changes the opacity of the entire element and content, thus making the text very hard to read.
HTML
div class="light">You can barely see this.div> div class="medium">This is easier to see.div> div class="heavy">This is very easy to see.div>
CSS
div background-color: yellow; font-weight: bold; font-size: 130%; > .light opacity: 0.2; /* Barely see the text over the background */ > .medium opacity: 0.5; /* See the text more clearly over the background */ > .heavy opacity: 0.9; /* See the text very clearly over the background */ >
Result
Setting opacity on hover
In the following example opacity is changed on hover, so the striped background image on the parent element shows through the image.
HTML
div class="wrapper"> img src="//interactive-examples.mdn.mozilla.net/media/dino.svg" alt="MDN Dino" width="128" height="146" class="opacity" /> div>
CSS
img.opacity opacity: 1; > img.opacity:hover opacity: 0.5; > .wrapper width: 200px; height: 160px; background-color: #f03cc3; background-image: linear-gradient( 90deg, transparent 50%, rgba(255, 255, 255, 0.5) 50% ); background-size: 20px 20px; >
Result
Specifications
Browser compatibility
BCD tables only load in the browser
Found a content problem with this page?
This page was last modified on Jul 18, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
opacity
Прячем элемент на странице, делая его полностью или частично прозрачным.
Время чтения: меньше 5 мин
Кратко
Скопировать ссылку «Кратко» Скопировано
Свойство opacity управляет прозрачностью элемента. С его помощью можно полностью спрятать текст или элемент. А можно сделать полупрозрачным — дизайнеры любят такой приём на современных сайтах.
Пример
Скопировать ссылку «Пример» Скопировано
Элемент станет прозрачным:
.selector opacity: 0;>
.selector opacity: 0; >
Элемент полупрозрачный, сквозь него видно фон:
.selector opacity: 0.5;>
.selector opacity: 0.5; >
Элемент совсем непрозрачный:
.selector opacity: 1;>
.selector opacity: 1; >
Как пишется
Скопировать ссылку «Как пишется» Скопировано
Свойство opacity принимает дробные или целые значения от 0 до 1 включительно. 0 будет означать полную прозрачность, а 1 полную непрозрачность (значение по умолчанию).
Как понять
Скопировать ссылку «Как понять» Скопировано
Можно представить, что 0 равен 0% видимости элемента, а 1 в свою очередь 100% видимости элемента. Указывая любые промежуточные значения вы гибко управляете видимостью.
Стоит быть внимательным с этим свойством: невидимый элемент всё равно остаётся на странице и продолжает влиять на поток документа. Грубо говоря, если вы скроете какой-то блок при помощи opacity , то он просто будет невидим, но не перестанет занимать своё место, его соседи не займут его место, а родитель не схлопнется, если это был единственный ребёнок.
Представьте, что элемент просто надевает Мантию-невидимку как у Гарри Поттера.
Подсказки
Скопировать ссылку «Подсказки» Скопировано
💡 Свойство прозрачности можно анимировать 🎉
💡 Элемент не пропадает со страницы, продолжает влиять на поток документа.
💡 Можно задавать любые дробные значения. Например, 0.33 или 0.1.
💡 Это не наследуемое свойство. НО! Если родителю задано это свойство, то и все дети вместе с ним будут становиться прозрачными.
💡 Вместо opacity : 0 можно использовать свойство visibility : visibility : hidden — будет тот же результат.
💡 В дробных значениях можно опустить первый ноль: opacity : . 5 . И всё равно будет работать 🧙♀️
На практике
Скопировать ссылку «На практике» Скопировано
Алёна Батицкая советует
Скопировать ссылку «Алёна Батицкая советует» Скопировано
🛠 Очень частый кейс — сделать полупрозрачную заливку поверх картинки. Это обычно называют оверлеем или вуалью. В этом случае не стоит применять свойство opacity , работайте с полупрозрачными цветами с альфа-каналом.
selector position: relative;> selector:before content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgb(0 0 0 / 0.5); /* или в формате HEX background-color: #00000080; */>
selector position: relative; > selector:before content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgb(0 0 0 / 0.5); /* или в формате HEX background-color: #00000080; */ >
🛠 Когда-то была популярна шутка, что если ваш заказчик не заплатил вам, то его можно шантажировать следующим способом: цепляете на сайт скрипт, который будет каждый день уменьшать opacity для body на 0.1 пока сайт полностью не пропадёт или пока заказчик не заплатит 😬
Если что, это не я вам рассказала 🤫