<div style="border-radius:50px 10px;width:60%;border: 1px solid #123467;background:linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);display:inline-block;float:right">
<div style="align:center;border-radius:10px 50px;margin-top:5%;text-align:center;width:60%;border: 1px solid #ffffff;background:linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%)">
<br/>
<h3 style="color:black">Running from</h3>
</div>
<br/>
</div>
The blue, pink, violet div isn't center despite I insert the align tag also in style (CSS). Why?
Thanks
Andrea
Your float: right is the main problem which forces the outer DIV to the right side. Remove that. To horizontally center it, you can make it a block element and add auto for margin-right and left.
So, you should apply display:block; margin: 0 auto; to both DIVs and remove the float (actually, to keep your 5% margin-top, the margin setting for the inner DIV has to be margin: 5% auto 0;)
<div style="border-radius:50px 10px;width:60%;border: 1px solid #123467;background:linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);display:block;margin: 0 auto;">
<div style="align:center;border-radius:10px 50px;text-align:center;width:60%;border: 1px solid #ffffff;display:block;margin: 5% auto 0;background:linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%)">
<br/>
<h3 style="color:black">Running from</h3>
</div>
<br/>
</div>
There is no such CSS property "align". Instead, use the margin property and set its values to 0 (for top and bottom), as well as auto (for left and right). This will center the element.
.outer {
border-radius: 50px 10px;
width: 60%;
border: 1px solid #123467;
background: linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);
display: inline-block;
float: right;
}
.inner {
margin: 0 auto;
border-radius: 10px 50px;
margin-top: 5%;
text-align: center;
width: 60%;
border: 1px solid #ffffff;
background: linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%);
}
<div class="outer">
<div class="inner">
<br/>
<h3 style="color:black">Running from</h3>
</div>
<br/>
</div>
you could add margin: 5% auto; to your inner DIV:
<style>
#firstDiv
{
border-radius:50px 10px;
width:60%;
border: 1px solid #123467;
background:linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);
display:inline-block;
float:right;
}
#secondDiv {
border-radius:10px 50px;
margin: 5% auto;
width:60%;
border: 1px solid #ffffff;
background:linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%);
text-align: center;
}
#secondDiv h3 {
color: black;
}
</style>
<div id="firstDiv" style="">
<div id="secondDiv" style="">
<h3>Running from</h3>
</div>
</div>
However I suggest separating styles and html.
Related
I need to create a dashed border gradient like in this picture. Here's my CSS code.
.Rectangle-5 {
margin: 51px 0px 0px 35px;
display: inline-block;
width: 370px;
height: 280px;
border-radius: 3px;
border: 1px dashed;
border-image-source: linear-gradient(to bottom, #4fc3f7, #ab5ca4 49%, #ff512f);
border-image-slice: 1;
}
New answer
Here is an improvement version of the initial answer with less of code. The idea is to rely on multiple background and adjust background-clip of each one.
.container {
display:inline-block;
height: 200px;
width: 200px;
margin: 20px;
border-radius:3px;
border: 2px dotted #fff;
background:
linear-gradient(#fff 0 0) padding-box,
linear-gradient(to bottom, #4fc3f7, #ab5ca4 49%, #ff512f) border-box;
}
.alt {
border: 2px dashed #fff;
}
<div class="container">
</div>
<div class="container alt">
</div>
Old answer
You can apply linear-gradient as a background to an extern container and then use dotted or dashed border on inner container. As per your needs you have to use the white as color for the border and also as the background of the content like this :
.container {
display:inline-block;
height: 200px;
width: 200px;
margin: 20px;
background-image: linear-gradient(to bottom, #4fc3f7, #ab5ca4 49%, #ff512f);
}
.inner {
border: 2px dotted #fff;
height: calc(100% - 4px);
}
.inner-alt {
border: 2px dashed #fff;
height: calc(100% - 4px);
}
.content {
background: #fff;
height: 100%;
}
<div class="container">
<div class="inner">
<div class="content"></div>
</div>
</div>
<div class="container">
<div class="inner-alt">
<div class="content"></div>
</div>
</div>
You need to pay attention to the height of the inner container. It should be 100% but don't forget the border in calculation, that's why i used calc(100% - 4px) (2px for top border and 2px for bottom border).
So if you change border height value you need also to update the height accordingly.
Add the following rule to your CSS
.Rectangle-5{
border: 2px dotted #fff;
background: linear-gradient(#fff,#fff) padding-box,
linear-gradient(92.35deg, #3370fe 1.28%, #00e599 98.95%) border-box;
}
Hi all,
I would like to insert a <button> in my code that has a gap in border-top and border-bottom. I have seen some examples where it is possible to remove a part with it, but it's not exactly what I am looking for. Do you have an idea on how to get something like the above mentioned picture?
Thanks in advance for your replies!
EDIT:
I add more information: the best is that the background of the button is transparent and that the border-size is customisable.
Use pseudo elements
.brd {
font-size: 30px;
padding: 4px 20px;
position: relative;
border: none;
background-color: white;
}
.brd:before,
.brd:after {
content: ' ';
position: absolute;
border: 1px solid black;
top: 0;
bottom: 0;
width: 10px;
}
.brd:before {
border-right: 0;
left: 0;
}
.brd:after {
border-left: 0;
right: 0;
}
<span class="brd">Title</span>
<button class="brd">Title</button>
Another possible solution is to use gradient as border-image. Look at the snippet below
.box{
display:inline-block;
margin: auto;
padding: 10px;
border: 3px solid transparent;
-moz-border-image: -moz-linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
-webkit-border-image: -webkit-linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
border-image: linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
border-image-slice: 1;
}
<div class="box" >TITLE HERE</div>
If you want the top and bottom border parts to be exactly X pixels, you can change the percents with pixels like this:
border-image: linear-gradient(to right, #aaa 20px, #fff 20px, #fff calc(100% - 20px), #aaa calc(100% - 20px));
A simple way would be using a custom made image as the background of your button, tho it wouldn't scale well on different screen sizes.
Another idea would be to have a div underneath with a normal border, and then your smaller button on top of it, with the same height and a white border, so as to hide the top and bottom part.
I've created a JSFiddle for you: enter link description here
HTML:
<div class="back-with-border">
<div class="front-no-border">
Title Here
</div>
</div>
CSS:
.back-with-border{
border:1px solid gray;
width:200px;
height:100px;
position: relative;
}
.front-no-border{
display:flex;
justify-content:center;
align-items:center;
border:0px;
background-color:white;
position: absolute;
width:110px;
height:110px;
top:-1px;
left:45px
}
Check this [JSFiddle][1], hope this will solve your problem
body {
background-color: white;
}
.parent {
border: 1px solid black;
width: 200px;
height: 100px;
position: relative;
background-color: white;
}
.child {
display: flex;
justify-content: center;
align-items: center;
border: 0px;
background-color: white;
position: absolute;
width: 150px;
height: 103px;
top: -1px;
left: 25px
}
<div class="parent">
<div class="child">
Write your text here
</div>
</div>
[1]: https://jsfiddle.net/anshul24mehta/eocst0uv/3/
This question already has answers here:
How to center the <legend> element - what to use instead of align:center attribute?
(10 answers)
Closed 7 years ago.
How to put some text on a border div so that text has a transparent background that it matches the image behind?
The problem is that the background-image has some shapes and multiple colors, so I can't put just some background color the the text because it won't fit.
Example:
html,
body {
width: 100%;
height: 100%;
}
body {
margin: 0;
background: url(http://wallpoper.com/images/00/45/05/47/green-background-2_00450547.jpg);
}
#main {
margin-top: 100px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
border: 1px solid #000000;
}
#main h2 {
font-size: 60px;
font-weight: 700;
text-align: center;
margin: -40px 0 0;
background: transparent; /* somehow remove the border behind the text */
padding: 0 20px;
}
<div id="main">
<h2>Star players</h2>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</div>
JSFiddle
You can use a fieldset instead of a div:
HTML:
<fieldset>
<legend>Test</legend>
</fieldset>
CSS:
legend {
text-align: center;
width: 100%;
}
So you want to see one thing 2 layers behind the text but not the other thing that is between the two...that in itself is rather counter-intuitive. Not sure you will be able to do it unless you use a border image and css gradient which is always a little complicated and this won't be dependant on the size/width of the text.
e.g.
HTML
<div class="gradborder-box"><div class="inner"><h2>Hello WORLD</h2></div></div>
CSS
.gradborder-box{
margin: auto;
width: 350px;
background: transparent;
border: 2px solid transparent;
-webkit-border-image: -webkit-linear-gradient(left, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 68%, rgba(0,0,0,1) 100%);
border-image: linear-gradient(to left, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 68%, rgba(0,0,0,1) 100%);
border-image-slice: 1;
}
h2{font-size: 1.2em; text-align: center; margin-top: -10px;}
.inner{height: 150px; width: 100%; border-bottom: 2px solid #000; margin-bottom: -2px;}
CodePen
This has been done for CHROME - you will need to add in the correct border image tags for the other browsers (-moz-border-image, etc). This is CSS3 only.
I'm trying to format my css properly, to display two divs horizontally. The first div contains 3 divs, which looks good, like this, on the left of the screen:
You can see my code below.
Now I'm trying to get div4, image2, to fill that big white space.
But I just don't get it. I've tried lots of stuff from this site - overflow:hidden;, clear-both - but the best I can get is the image appearing on the right, ok, but below the baseline of #character_and_bubbles - not in the space I want. Any help please?
My markup code:
<div id = "character_and_bubbles">
<div id = "top_bubble_div">
<div id="top_bubble">
bubble text here
</div>
</div>
<div id = "p_mechanic">
mechanic image here
</div>
<div id = "right_bubble_div">
<span id="right_bubble">
bubble text here
</span>
</div>
</div>
<div id="image2">
# how do I position this image in the big white space?
</div>
And my Sass:
#character_and_bubbles {
margin-top:80px;
#top_bubble_div {
#top_bubble {
background-color: #fff0a0;
background-image: -webkit-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: -moz-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: -ms-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: -o-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
border-radius: 5px;
box-shadow: inset 0 1px 1px hsla(0,0%,100%,.5),
3px 3px 0 hsla(0,0%,0%,.1);
color: #333;
display: inline-block;
font: 16px/25px sans-serif;
width: 500px;
padding: 15px 25px;
position: relative;
text-shadow: 0 1px 1px hsla(0,0%,100%,.5);
}
#top_bubble:after, #top_bubble:before {
border-bottom: 25px solid transparent;
border-right: 25px solid #fff0a0;
bottom: -25px;
content: '';
position: absolute;
right: 475px;
}
#top_bubble:before {
border-right: 25px solid hsla(0,0%,0%,.1);
bottom: -28px;
right: 472px;
}
}
#p_mechanic {
padding:20px;
float:left;
}
#right_bubble_div {
padding:20px;
#right_bubble {
background-color: #fff0a0;
background-image: -webkit-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: -moz-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: -ms-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: -o-linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
background-image: linear-gradient(top, hsla(0,0%,100%,.5), hsla(0,0%,100%,0));
border-radius: 5px;
box-shadow: inset 0 1px 1px hsla(0,0%,100%,.5),
3px 3px 0 hsla(0,0%,0%,.1);
color: #333;
display: inline-block;
font: 16px/25px sans-serif;
width: 282px;
padding: 15px 25px;
position: relative;
text-shadow: 0 1px 1px hsla(0,0%,100%,.5);
}
#right_bubble:after, #right_bubble:before {
border-bottom: 25px solid transparent;
border-right: 25px solid #fff0a0;
bottom: 68px;
content: '';
position: absolute;
right: 332px;
}
}
}
#image2{
/* how do I get this to fill that big white space? */
float:right;
}
You need to move <div id="image2"> above the rest of the content in the source order. In its current position, it's rendered below the other content.
For example:
<div id="image2"># how do I position this image in the big white space?</div>
<div id="character_and_bubbles">
<div id="top_bubble_div">
<div id="top_bubble">bubble text here</div>
</div>
<div id="p_mechanic">mechanic image here</div>
<div id="right_bubble_div">
<span id="right_bubble">bubble text here</span>
</div>
</div>
You also need to give it a height - either by filling it with content or with height: 300px;. Otherwise the browser renders it as empty / no dimensions.
http://jsfiddle.net/sTvGx/3/
But if your #image element is just there to hold a background image (non-semantic), why not make it a background element on the parent of all those divs, like the body?
I've assumed that you've provided Sass instead of CSS.
I need to create a gradient border around the text within my page, I have four columns and I need the border to go around the outside and inside of the columns and be the same width.
For example I have added an image:
The border needs to be the same as above.
This is the HTML I am using below, the problem so far is that where the columns join the borders are adding both borders to it and border-left:none; does not work. I also need to know if this is the best way to do this, and other ways.
<html>
<head>
<style>
.border{
padding: 15px 20px;
border-top: 20px solid #000;
border-bottom: 20px solid #FF0000;
<!--margin: 40px auto;-->
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#FF0000));
background-image: -webkit-linear-gradient(#000, #FF0000);
background-image:
-moz-linear-gradient(#808, #FF0000),
-moz-linear-gradient(#000, #FF0000)
;
background-image:
-o-linear-gradient(#000, #FF0000),
-o-linear-gradient(#000, #FF0000)
;
background-image:
linear-gradient(#000, #FF0000),
linear-gradient(#000, #FF0000)
;
-moz-background-size:17px 100%;
background-size:20px 100%;
background-position:0 0, 100% 0;
background-repeat:no-repeat;
}
#primary {
float: left;
width: 200px;
}
#content {
float: left;
width: 200px;
}
#secondary {
float: left;
width: 250px;
}
#third {
float: left;
width: 250px;
}
</style>
</head>
<body>
<div id="primary" class="border">
<p>Column information</p>
</div>
<div id="content" class="border">
<p >Column information</p>
</div>
<div id="secondary" class="border">
<p >Column information</p>
</div>
<div id="third" class="border">
<p >Column information</p>
</div>
</body>
</html>
Gradient borders or not (yet) widely supported. The easy solution here would be to add a wrapper div with the gradient, and give each column div a background color to mask the background of the wrapper. Something like this:
<div class='wrapper'>
<div class='col'>...</div>
<div class='col'>...</div>
<div class='col'>...</div>
<div class='col'>...</div>
</div>
and the css:
.wrapper {
float: left; /* no need to be wider then the content */
overflow: hidden; /* clearfix */
padding: 10px 10px 0 0; /* no padding left / bottom, the margin left on the cols takes care of that */
background: linear-gradient(to bottom, #ff3232 0%,#000000 100%); /* don't forget to add prefixes here */
}
.col {
width: 150px; /* just some width, any number will do */
float: left; /* make them appear as columns */
margin: 0 0 10px 10px; /* same margin as the padding on the wrapper, but only left/bottom */
background-color: #fff; /* a color to mask the gradient */
padding: 5px;
}
To see a live example: http://jsfiddle.net/Pevara/6vDmH/