Is it possible to have a transparent border? - html

I have this code for my border:
border: 1px solid #CCC;
Is it possible to have some similar CSS where the border has a width but it's not visible. In other words if there's a blue background then that would show right through the border?

A margin occupies space and is transparent. The space a margin occupies is on the outside of the element, so it takes the background color of the parent element. If you want it to be space with the same background color as the element you are modifying, you would want to use padding.
This is a great resource that shows you what you will probably want:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model

Yes, it's entirely possible.
Normally, a transparent border would show the background color of the element beneath it.
This can be overcome by restricting the background to the "box" holding the padding & content using background-clip:padding-box (or optionally content-box which would clip the background to the content area only).
Then you can add a boxshadow (for instance) which will sit outside the transparent border.
body {
background: linear-gradient(to bottom, orange, pink);
}
div {
width: 200px;
height: 200px;
box-sizing: border-box;
background: rebeccapurple;
margin: 2em auto;
border: 10px solid transparent;
box-shadow: 0 0 5px 5px green;
background-clip: padding-box;
}
<div></div>

You can just set the border-color to transparent

Yes it is possible to have transparent border. Just use rgba color defination like so:
border: 10px solid rgba(50,50,50,.5);
The last value 0.5 goes from 0 to 1 and is a opacity (or alpha) value for the color
Working example (see how the border transparency changes on hover): jsFiddle

Related

How to set a margin for a html button background color

I have a bootstrap button with dimensions of 46 x 96px and border radius of 22px, when I hover this button I want to set the background color up to 40 x 90px. (I do not want to fill the entire button)
I know this can be done using a box-shadow but I have different pages with different page colors where this button is used, so I do not want to change the box-shadow color page by page to match page's background color.
Any easy way to do this?
You can leverage this with the backgroud-clip property.
The background-clip CSS property sets whether an element's background extends underneath its border box, padding box, or content box.
MDN
Make the size of your button 40px x 90px and add 3px of padding.
Then on hover, set background-clip: content-box and the background color will be restricted to just the content and not the padding.
Exaggerated example below:
body {
background: lightgreen;
}
.button {
height: 30px;
width: 80px;
border-radius: 22px;
background: blue;
display: flex;
justify-content: center;
align-items: center;
margin: 2em;
padding: 8px;
border: 1px solid red;
color: white;
}
.button:hover {
background-clip: content-box;
}
<div class="button">Button</div>
As you can see from the border the button size does not change but rather the background just does not extend to the border from the content.
On hover, try adding a transparent border matching the button's background of size 6px, and change the background-color as needed. This will give the intended effect, but will also visually reduce the size of the button. From your question it was not clear whether that was an acceptable side-effect.
Check out this link to implement fully transparent borders.

offset background color outside border with css?

I have an responsive container (Wordpress with visual composer) with a background color and border. If I want the background a little outside the container. (like a offset print error) How to achive this. I have dabbled with background-position. But can't get it to work in WP and dosn't seem to work with negative?
Background and border offset
You could replace border with outline, and use a negative outline-offset value.
*Note that this is not supported by Internet Explorer
div {
background: black;
outline: 5px solid yellow;
outline-offset: -10px;
width: 300px;
height: 300px;
}
<div></div>

How do i make a nested div translucent to show body tag's background image? [duplicate]

This question already has answers here:
How do I reduce the opacity of an element's background using CSS?
(29 answers)
Closed 7 years ago.
I have a div thats inside the container div. Now i want to make the inner-most-divs translucent to show the bodies background image. Or can this be done?
To make my question clearer, i used a green border for the div i want to target. I want this div to be slightly translucent so that the body tag's background is visible only in this div. Im thinking z-index should be used here but im not sure how
.forum-column{
border: 2px solid green;
/*background-image: url(http://kenstonlocal.org/kenston/wp-content/uploads/2014/12/css_code.jpg);
background-size: cover;*/
background-color: rgb(35,35,35);
overflow: hidden;
height: 50px;
margin-bottom: 5px;
}
https://jsfiddle.net/jmann1622/hgm0gzs0/2/
I'm aware of opacity and rgba. But my problem is that my target(green border) is inside another div(orange border) which itself is inside another div(red border). Now i do not want any of the other divs to be transparent, only the green bordered div.And i want this (green bordered div) to be translucent so that the body tag's sky image can be seen. Sorry for the confusion, noob here
option-1: Use css property opacity:[0-1]
.forum-column{
border: 2px solid green;
/*background-image: url(http://kenstonlocal.org/kenston/wp-content/uploads/2014/12/css_code.jpg);
background-size: cover;*/
background-color: rgb(35,35,35);
overflow: hidden;
opacity:0.4;
height: 50px;
margin-bottom: 5px;
}
option-2: Use rgba(red,green,blue,alpha) for background-color where alpha is from 0-1 and specifies the translucency
.forum-column{
border: 2px solid green;
/*background-image: url(http://kenstonlocal.org/kenston/wp-content/uploads/2014/12/css_code.jpg);
background-size: cover;*/
background-color: rgba(35,35,35,0.4);
overflow: hidden;
height: 50px;
margin-bottom: 5px;
}
Use rgba for most browsers..
rgba(35,35,35,.8) the last part is a number from 0-1 to indicate transparency level..
Just use rgba for background color.
.innerDiv {
background-color: rgba(35, 35, 35, .5);
}
The last value for a (alpha) can be between 0(100% transparent) to 1(100% opaque).
This will make the innermost div tranparent and the background divs will remain visible through it.
Hope it helps.

Border to margin in HTML

I am new to HTML programming. Is it possible to make a border to the margin instead of the padding? I need this just for design purposes only.
Is it possible to make a border to the margin instead of the padding?
Yes. The closest way I can think of to achieve this effect is using the CSS background-clip property:
background-clip: padding-box;
This clips any backgrounds in the element not to be rendered in the border region, thus treating it like a margin rather than padding.
Below is an example of the difference:
div {
border: 5px dashed #000; /* to see through border */
background-color: #0FF; /* to show extent of background */
padding: 5px;
margin: 10px;
}
.adjusted {
background-clip: padding-box; /* corrects extent of background */
}
<div>Default Border</div>
<div class="adjusted">Corrected Border</div>
In the "corrected" div, the border becomes part of the margin visually rather than part of the padding.
Make your padding the size your your current padding + margin, then set your margin to 0 pixels. This will have the same effect.
I don't think this is possible but if you want to enclose the margin within a border then there can be a workaround.
Enclose the element with span and set the border for that span element as,
.inner{
padding: 5px;
margin: 5px;
}
.outer{
border: 1px solid black;
}
<div class="outer">
<p class="inner">Hello</p>
</div>
Here is a demo

How to have border with rounded corners as an image and inner background colour to see through?

I have div border with inner rounded corners that I want to replace with an image. The image will have opacity, gradient and other Photoshop effects applied to it.
I also want to have the inner div's background colour to see through so that the image of the body is visible. Basically I am after a transparent background in the .inner div.
JSFiddle: http://jsfiddle.net/EN2XZ/2/
This is my HTML:
<body>
<div class="outer">
<div class="inner">
....
....
</div>
</div>
</body>
CSS:
body {
background-image:url('image-url');
background-size:cover;
background-repeat:no-repeat;
padding:50px;
}
.outer {
background-color:#000;
padding:10px;
}
.inner {
border-radius:10px;
background-color:#fff;
padding:5px 15px;
color:#0000ff;
}
Am not clear about the image requirement description you gave
To get a transparent background give background color in rgba
Rewrite the inner class as
.inner {
border-radius:10px;
background-color:rgba(0,0,0,0.2);
padding:5px 15px;
color:#0000ff;
}
where the rgba last parameter is the opacity
Currently, .inner can not be transparent to body because .outer is the next layer behind it, and is solid black, so .inner would be transparent to black.
You could remove .outer or set background-color: transparent; on it, then set .inner to background-color: rgba(255, 255, 255, .7);
However that leaves no border. You could add a simple black border with rounded edge by adding it to the .inner class: border: 1px solid #000;
If you are set on having the outer black box have no radius, and inner have a radius, and have fancy effects, then you can certainly just use an image as you originally intended.
In Photoshop, make sure your image has some transparency, and save it as a PNG-24 with transparency enabled. The PNG-24 format allows for each pixel to carry over its alpha value.