How to change div background on dragover when also contains image - css

I have a dropzone where user can drop an image, it has some associated CSS that makes the dropzone background go grey as they drag the image, giving a visual cue.
Html
<div>
<figure>
<div id="dropzone">
</div>
</figure>
</div>
CSS
#dropzone {
border: 3px solid black;
min-width:300px;
min-height:100px;
max-width:300px;
max-height:100px;
}
#dropzone.dragover {
background: rgba(0, 0, 0, .5);
}
But I don't want the dropzone to be empty I would like it to have a starting image (which says something like 'Drop Files Here')
<div>
<figure>
<div id="dropzone">
<img src="dropzone.jpg"/>
</div>
</figure>
</div>
and if I add this, then the dropzone doesnt grey out when drag an image over, how do I fix this?

Try setting the background image with CSS property background-image
#dropzone{
background-image: url(path/to/your/image);
/* rest of the css goes here*/
}
#dropzone {
border: 3px solid black;
min-width:300px;
min-height:100px;
max-width:300px;
max-height:100px;
background-image:url(https://images.pexels.com/photos/577775/pexels-photo-577775.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940);
background-repeat: no-repeat;
background-position: center;
background-size: auto;
}
#dropzone.dragover {
background: rgba(0, 0, 0, .5);
}
<div>
<figure>
<div id="dropzone">
</div>
</figure>
</div>

I got two solutions for you:
First I display the image as a background-image and then I filter it in the fist solution to be grayscale (More about filter here) and in the second solution I just overwrite the background to just be gray.
#dropzone1,
#dropzone2 {
border: 3px solid black;
min-width: 300px;
min-height: 100px;
max-width: 300px;
max-height: 100px;
background-image: url(https://picsum.photos/300/300);
background-repeat: no-repeat;
background-position: center;
background-size: auto;
}
#dropzone1:hover {
filter: grayscale(100%);
}
#dropzone2:hover {
background: rgba(0, 0, 0, .5);
}
<div>
<figure>
<div id="dropzone1">
</div>
</figure>
</div>
<div>
<figure>
<div id="dropzone2">
</div>
</figure>
</div>

You can use opacity on the dropzone.
#dropzone.dragover {opacity:0.5}
Because background is only the background-color of the element.

Related

How can I make a gradient top border with a radius?

I've been trying to make a gradient top border for a box with a radius. The gradient border should only be at the top of the box, and it needs to have the same radius (5px) as the rest of the box. The end result should look like this:
My current code:
.card {
text-align: center;
margin: 0 1%;
background-color: #252a41;
border-radius: 5px;
border: none;
width: 25%;
padding: 3% 0;
}
.instagram {
border-top: 3px solid rgb(243, 242, 241);
border-radius: 5px;
border-image: linear-gradient(to right, #fdc468, #ffa263, #ff806c, #f9607f, #df4996) 1 / 3px 0px 0px 0px / 0px 0px 0px 0px round;
position: relative;
}
<div class="card instagram">
<div class="row">
<img src="images/icon-instagram.svg" alt="instagram icon" />
<span class="small-text username">#realnathanf</span>
</div>
<h1 class="followers-count">11k</h1>
<p class="small-text followers">FOLLOWERS</p>
<div class="row">
<img src="images/icon-up.svg" alt="icon up" />
<span class="change change-up">1099 Today</span>
</div>
</div>
Apparently the border-image property isn't compatible with border radius, so I have to make a before/after pseudo-element. However I couldn't figure out how to make one for the desired result.
You can do it with only background:
.box {
width:200px;
height:200px;
border-radius:5px;
background:
linear-gradient(to right, #fdc468, #ffa263, #ff806c, #f9607f, #df4996) top/100% 5px no-repeat,
#000;
}
<div class="box">
</div>

CSS half circle background

What I am trying to achieve:
image link
What my code currently looks like:
.half-circle {
background-color: white;
}
<div style="background-color: black;">
<div class="half-circle">
<img src="https://i.imgur.com/WBtkahj.png" />
</div>
</div>
<div>Some text here that should't be moved</div>
I've tried using padding with a white background and 500 radius, but it pushes the text down.
You can take a look at radial-gradient() and tune a bit the sizing
.half-circle {
min-height: 12vw;
padding-bottom: 4%;
background: radial-gradient(circle at top, white 17vw, transparent 17.1vw)
}
.half-circle img {
display: block;
margin: auto;
max-width: 15vw
}
<div style="background-color: black;">
<div class="half-circle">
<img src="https://i.imgur.com/WBtkahj.png" />
</div>
</div>
<div>Some text here that should'nt be moved</div>
This can be achieved with CSS if you give your .half-circle a border-bottom-left-radius and border-bottom-right-radius. That will round the bottom corners of the shape into a half circle. I also added some extra style to match your screenshot a little better.
.container {
padding-bottom: 10px;
text-align: center;
}
.half-circle {
background-color: white;
margin: 0 auto;
height: 100px;
width: 400px;
border-bottom-left-radius: 800px;
border-bottom-right-radius: 800px;
padding: 10px 0 20px;
text-align: center;
}
img {
max-height: 100%;
width: auto;
}
<div class="container" style="background-color: #000;">
<div class="half-circle">
<img src="https://i.imgur.com/WBtkahj.png" />
</div>
</div>
<div>Some text here that should't be moved</div>

place 2 inline columns vertically to middle of background

you can help me with UIkit or css manually!
i am using UIkit framework and the problem is that i really don't understand how to place two inline columns at middle of background(vertically)!
here is screenshot what i have, i think then you will understand my problem]1
this is code of this section with columns:
<section id="header" class="gradient bg bg-gradient ">
<div uk-grid style="margin: 0 auto;" class="uk-flex uk-flex-middle uk-flex-space-between uk-grid-item-match">
<div class="uk-width-3-5#m">
<div class="uk-flex-inline">
<hr class="uk-divider-small">
<p>DISTRIBUTED LEDGER TECHNOLOGY</p>
</div>
<p>
<h1><span style="color: #6d6d6d">BRINGING</span> <span style="color: white">A GOLD STANDART TO THE</span>
<span style="color: rgba(4,149,247,1);">BLOCKCHAIN</span></h1></p>
</div>
<div class="uk-width-expand#m uk-flex">
<video loop muted playsinline uk-video="autoplay: inview">
<source src="https://quirksmode.org/html5/videos/big_buck_bunny.mp4" type="video/mp4">
<source src="https://quirksmode.org/html5/videos/big_buck_bunny.ogv" type="video/ogg">
</video>
</div>
</div>
</section>
here is my main.css
.gradient {
height: 900px;
width: 100%;
background: linear-gradient(180deg, #092436 0%, rgba(13, 17, 22, 0) 100%);
box-shadow: 0 2px 4px 0 rgba(255, 255, 255, 0.12);
}
.bg {
height: 900px;
width: 100%;
background-color: #0D1116;
box-shadow: 0 2px 4px 0 rgba(255, 255, 255, 0.12);
}
.bg-gradient{
position:absolute;
top:0px;
z-index: -1;
}
.thin-text{
font-weight: 200;
}
html,body{
letter-spacing: 2px;
}
.uk-button-text {
letter-spacing: 2px;
padding:5px;
}
.uk-navbar{
border-bottom: 1px solid rgba(4,149,247,0.1);
}
.hover{
transition: 0.3s;
}
.hover:hover{
background-color: rgba(4,149,247,0.1);
}
.padding-header {
padding: 200px 100px 100px 100px;
}
my 2 columns are inside .bg and .gradient!
<section id="header" class="gradient bg bg-gradient uk-flex">
<div class="uk-margin-auto uk-margin-auto-vertical">
<div uk-grid>
</div>
</div>
</section>
You can use the following solution to place two inline columns vertically in the middle of the background:
.uk-width-expand#m {
margin: 0 auto;
}

Why do the elements below also move to the right with this css?

The code below displays some text (#_EVENTEXCERPT) and displays a picture (#_EVENTIMAGE). I want it so the text is on the left and the image on the right, so they are next to each other, as this code does. Below this there is a <a href="#_EVENTURL with lots of css which makes this link into an orange button. Currently, this orange button is being moved right with the image. I don't want this to happen, how can I move the image next to the text (as is currently), but leave the <a href to the left?
from style sheet:
#eventexcandimage {
width: 100%;
}
from .php file:
<div id="eventexcandimage">
<span style="width: 50%; float: left; "> #_EVENTEXCERPT </span>
#_EVENTIMAGE </div>
</li>
<li>
<span style="width:50%; " > <a href="#_EVENTURL" style=" -moz-box-shadow:inset 0px 1px 0px 0px #ed834e;
-webkit-box-shadow:inset 0px 1px 0px 0px #ed834e;
box-shadow:inset 0px 1px 0px 0px #ed834e;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ed834e), color-stop(1, #ed834e) );
background:-moz-linear-gradient( center top, #ed834e 5%, #ed834e 100% );
background-color:#ed834e;
-webkit-border-top-left-radius:0px;
-moz-border-radius-topleft:0px;
border-top-left-radius:0px;
-webkit-border-top-right-radius:0px;
-moz-border-radius-topright:0px;
border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-radius-bottomright:0px;
border-bottom-right-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-radius-bottomleft:0px;
border-bottom-left-radius:0px;
text-indent:0px;
display:inline-block;
color:#fffffb;
font-family:Arial;
font-size:13px;
font-weight:bold;
font-style:normal;
height:35px;
line-height:35px;
width:111px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ed834e;
"> More Info / Book</a> </span>
Thank-you!
UPDATE: YI want the button to be on a new line below the text/image. It is currently above the image on the right, I don't know why.
Okay so I took your code and hopefully made it work the way you wanted it to(?)..Maybe.
Also just below your code I rewrote it not using span or li but rather div's as they're better for positioning than the former two. Here is link to the Fiddle as well it attached as a snippet.
.btn {
-moz-box-shadow:inset 0px 1px 0px 0px #ed834e;
-webkit-box-shadow:inset 0px 1px 0px 0px #ed834e;
box-shadow:inset 0px 1px 0px 0px #ed834e;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ed834e), color-stop(1, #ed834e) );
background:-moz-linear-gradient( center top, #ed834e 5%, #ed834e 100% );
background-color:#ed834e;
-webkit-border-top-left-radius:0px;
-moz-border-radius-topleft:0px;
border-top-left-radius:0px;
-webkit-border-top-right-radius:0px;
-moz-border-radius-topright:0px;
border-top-right-radius:0px;
-webkit-border-bottom-right-radius:0px;
-moz-border-radius-bottomright:0px;
border-bottom-right-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-radius-bottomleft:0px;
border-bottom-left-radius:0px;
text-indent:0px;
display:inline-block;
color:#fffffb;
font-family:Arial;
font-size:13px;
font-weight:bold;
font-style:normal;
height:35px;
line-height:35px;
width:111px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ed834e;
}
.event {
width: 100%;
margin-top: 25px;
}
.event_info {
width: 100%;
margin-bottom: 5px;
}
.event-text {
float: left;
width: 50%;
}
.event-text > h3 {
margin: 0;
padding: 0;
}
.event-img {
width: 50%;
float: left;
}
.img {
width: 100%;
height: 125px;
background: red;
display: block;
}
<ul>
<li>
<div id="eventexcandimage">
<span style="width: 50%; float: left; ">
#_EVENTEXCERPT
</span>
<div style="width: 50%; float: left;">
<img class="img" src="" />
</div>
</div>
</li>
<li style="clear: both;"> <span style="width:50%; "> More Info / Book </span>
</li>
</ul>
<div class="event">
<div class="event-info">
<div class="event-text">
<h3>Event Title</h3>
<p>Text about your event</p>
</div>
<div class="event-img">
<img class="img" src="" />
</div>
</div> <!-- End event-info -->
<div style="clear: both;">
More Info / Book
</div>
</div>
I'm going to assume that your provided HTML has been cut off because some of your tags are not properly opened nor closed, but that's irrelevant as to why you're seeing the behavior you are.
span by default is displayed inline (everything naturally flowing on a line). You have your button in a span which means it's trying to stay on the same line as the things before it, which is doing what you're seeing. So what can you do? Well, the quickest fix is to make this button start on a new line. Change the display on the button to display:block. Block level elements take up the entire width, which will force a line break since something that is full width can't share the line with other things.

Extend image below its containing div

I have an image which is inside a div. It appears as expected, within the div. When margin-top is added, the background for this div extends downwards. I don't want to have this behavior. How can I change this?
My code is as follows :
<div id="content">
<div class="page">
<div class="half">
<p>Text goes here.</p>
</div>
<div class="half">
<img src="imghere.png" alt="img" />
</div>
</div>
</div>
CSS
.page {
width:500px;
margin:0 auto;
padding: 5px;
}
.half {
display:inline-block;
width:44%;
margin:0 2%;
}
This ensures that the column with the <p> tag goes on the left side of the screen, and the column with the image goes on the right, and it resizes as you resize the window :).
How can I make this webpage go from
-----div-----------
Text Image
-----/div-----------
to
-----div------------
Text
--/div--Image----
Image illustrating what I would like :
Edit:
I originally skipped over the fact that you provided some HTML and CSS in the question, so in my original answer I just went off the image provided. Looking at the HTML and CSS you provided, the only thing you'd have to do to get the desired result is set a negative bottom margin in your CSS on the img tag. Here's a jsFiddle using your original markup with the only significant addition to the CSS being the negative bottom margin set on the img tag.
The added benefit of doing it this way is that the image will stay in the desired spot (extended slightly below the div that contains it), even when adding more lines of text to the paragraph (p) changes the height of the containing element (.page div).
CSS
.page {
width:500px;
margin:0 auto;
padding: 5px;
width: 100%;
background-color: #ED1C24;
border-top: 3px solid black;
border-bottom: 3px solid black;
text-align: center;
}
.half {
display:inline-block;
width:44%;
margin:0 2%;
}
img {
margin-bottom:-50px;
}
Original answer:
You could just position the image below the text, float the image, and set a negative top margin on the image to make it cut back into the element containing the text. This way, the image will keep sitting in the right spot, even when adding more lines of text changes the height of the containing element.
Here's a jsFiddle
HTML
<p>Text
<br/>Text
<br/>Text
<br/>Text
<br/>Text
<br/>Text
<br/>Text
<br/>Text
<br/>
<img />
</p>
CSS
p {
width: 100%;
background-color: #ED1C24;
border-top: 3px solid black;
border-bottom: 3px solid black;
text-align: center;
}
img {
width: 100px;
height: 100px;
background-color: yellow;
border: 3px solid black;
float: right;
margin: -70px 100px;
}
I don't quite understand the question completely, but I coded what you wanted in css with your HTML untouched. Hopefully that helps. Check out the JSFiddle.
http://jsfiddle.net/bH8qA/
HTML:
<div id="content">
<div class="page">
<div class="half">
<p>Text goes here.</p>
</div>
<div class="half">
<img src="imghere.png" alt="img" />
</div>
</div>
</div>
CSS:
.page{
background-color:#cc0000;
border-top:4px solid #000;
border-bottom:4px solid #000;
width:500px;
margin:0 auto;
padding: 5px;
position:relative;
}
.half{
display:inline-block;
width:44%;
vertical-align:top;
text-align:right;
}
.half + .half{
position:absolute;
top:20px;
text-align:left;
margin-left:4%;
}
.half > img{
display:block;
height:100px;
background-color:#F5EB00;
border:4px solid #000;
}
use css and use the overflow: hidden on the parent of that div.
Something like this? http://codepen.io/pageaffairs/pen/urGnL
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style media="all">
.page {
width:500px;
margin:0 auto;
padding: 5px;
background: red;
}
.half{
width:44%;
margin:0 2%;
}
.float {
float: right;
}
.page, img {
border: 5px solid black;
}
img {
width: 100px;
height: 100px;
background: yellow;
}
</style>
</head>
<body>
<div id="content">
<div class="page">
<div class="half float">
<img src="imghere.png" alt="img" />
</div>
<div class="half">
<p>Text</p>
</div>
</div>
</div>
</body>
</html>

Resources