How to arrange correctly? - html

I'm trying to create two banners with cropped corners, but I'm having problems with my code:
https://codepen.io/Jeerjmin/pen/VdBVKL
.container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background-color: white;
}
.banner-1 {
min-width: 200px;
max-width: 200px;
height: 300px;
margin: 70px;
background-color: white;
border: solid #01579B 4px;
border-radius: 15px;
overflow: hidden;
}
.banner-1:before {
position: absolute;
content: '';
min-width: 38px;
height: 60px;
top: 39px;
left: 303px;
background-color: white;
border-bottom: solid #01579B 4px;
transform: rotate(-45deg);
}
.banner-2 {
min-width: 200px;
max-width: 200px;
height: 300px;
margin: 70px;
background-color: white;
border: solid #01579B 4px;
border-radius: 15px;
overflow: hidden;
}
.banner-2:before {
position: absolute;
content: '';
min-width: 38px;
height: 60px;
top: 39px;
left: 652px;
background-color: white;
border-bottom: solid #01579B 4px;
transform: rotate(-45deg);
}
img {
position: relative;
top:100px;
left: 25px;
width: 200px;
height: 150px;
}
.dot {
height: 50px;
width: 50px;
background-color: deepskyblue;
border-radius: 50%;
position: relative;
left: -50px;
bottom: 100px;
text-align:center;
}
p {
text-align:center;
}
<div class="container">
<div class="banner-1">
<p>Card-1</p>
<img src="https://img2.goodfon.ru/original/1366x768/6/5e/koshka-kot-meyn-kun-belyy-fon-5567.jpg"></img>
<span class="dot dot-1">
<h1>0,5</h1>
<h5>кг</h5>
</span>
</div>
<div class="banner-2">
<p>Card-2</p>
<img src="https://img2.goodfon.ru/original/1366x768/6/5e/koshka-kot-meyn-kun-belyy-fon-5567.jpg"></img>
<span class="dot dot-2">
<h1>0,5</h1>
<h5>кг</h5>
</span>
</div>
</div>
Problem 1:
I'm trying to crop the top left corners of the banners, but the cards move around while the crops stay where they are.
Problem 2:
The span with class="dot" should form a colored circle, but does not.

Not sure what you meant in Problem 1. As for problem 2, you need to add display: block to your .dot class and you also can remove left property form it.

I had to make several changes to your code to get this working, so see the code snippet below for all the changes. However, here are a few key points:
To position your ::before pseudo-elements in correct relation to the banners, add relative positioning to the banners.
To make your blue dot work, and to align its contents correctly, Flexbox layout is a good solution.
To simplify your code, it's preferable to style similar items together. For that reason, I've given your banners shared styles.
<img> elements should not have a corresponding closing tag (the technical term for this kind of element is "self-closing"). That said, I changed your image to be a background image. The reason is that you can't both have overflow: hidden on your banners and put the clipped corner over its borders.
.container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background-color: white;
}
/* Target both banners together,
since they share styles */
.banner-1,
.banner-2 {
min-width: 200px;
max-width: 200px;
height: 300px;
margin: 70px;
border: 4px solid #01579B;
border-radius: 15px;
/* Relatively position the banner,
so that the clipped corners,
can be properly placed */
position: relative;
/* To have the image clip to
the banner, make it a
background image */
background: white no-repeat 10px bottom / auto 150px
url("https://img2.goodfon.ru/original/1366x768/6/5e/koshka-kot-meyn-kun-belyy-fon-5567.jpg");
}
.banner-1::before,
.banner-2::before {
content: "";
width: 22px;
height: 38px;
position: absolute;
left: 0;
top: -1px;
background-color: white;
border-right: 4px solid #01579B;
/* Adjust your transform origin,
to make the rotation easier */
transform-origin: top right;
transform: rotate(45deg);
}
.dot {
/* Use Flexbox to align the
content in your dot */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 80px;
width: 80px;
background-color: deepskyblue;
border-radius: 50%;
position: absolute;
left: 20px;
bottom: 100px;
}
h1, h5 {
/* Remove margins on
dot content */
margin: 0;
}
p {
text-align: center;
}
<div class="container">
<div class="banner-1">
<p>Card-1</p>
<span class="dot dot-1">
<h1>0,5</h1>
<h5>кг</h5>
</span>
</div>
<div class="banner-2">
<p>Card-2</p>
<span class="dot dot-2">
<h1>0,5</h1>
<h5>кг</h5>
</span>
</div>
</div>

Related

How do I make a containing div overflow hidden inside it's containing div

I'm trying to give this simple calculator app I'm making a 'light sheen', like what you'd see on a phone screen under light. What I've done is I've put a div for the light sheen inside the containing div which is the phone shape, but I can't make it so overflow is hidden for the light sheen div.
Hopefully the current code snippets help:
<div class="phone-container">
<div class="light-sheen"></div>
<div class="upper-icons">
.phone-container {
height: 750px;
width: 400px;
background: rgb(0, 0, 0);
border-radius: 60px;
border: 5px solid rgb(172, 172, 172);
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 20px;
padding-bottom: 50px;
overflow: hidden;
}
.light-sheen {
width: 900px;
height: 450px;
background-color: white;
position: absolute;
bottom: 0px;
transform: rotateZ(-35deg);
opacity: 0.1;
}
Any help is appreciated, thanks!
Since you use position: absolute; on light-sheen, it's not possible to hide the overflow part.
Make light-sheen position: relative; instead.
.light-sheen {
width: 900px;
height: 450px;
background-color: white;
position: relative;
bottom: 0px;
transform: rotateZ(-35deg);
opacity: 0.1;
}

How do I right-align a <span> within a <p> and keep the text inside the <p> centered? (HTML) [duplicate]

This question already has answers here:
Center one and right/left align other flexbox element
(11 answers)
Closed 2 years ago.
It's hard to ask this question without a visual reference, so I included a picture below (as well as a code snippet). I'm trying to achieve two things:
right-align the blue <span> circle inside the yellow <p> box
keep the text centered in the <p> box, independent of the blue circle
This is my code:
.circle {
height: 20px;
width: 20px;
background-color: blue;
border-radius: 50%;
display: inline-block
}
.box {
background-color: yellow;
height: 30px;
width: 500px;
text-align: center;
margin: 10px
}
<p class='box'>This is centered</p>
<p class='box'>This is not<span class='circle'></span></p>
I'm not super familiar with HTML, but I tried doing align-self: right for the circle, but nothing happened. Not sure what to do.
Here is a picture of what I'm trying to achieve:
just float:right and add margin to center
.circle {
height: 20px;
width: 20px;
background-color: blue;
border-radius: 50%;
display: inline-block;
float: right;
margin: 5px;
}
.box {
background-color: yellow;
height: 30px;
width: 500px;
text-align: center;
margin: 10px;
box-sizing: border-box;
}
.box2 {
padding-left: 30px; /* circle width (20px) + circle margin-left (5px) + margin-right (5px) = 30px */
}
<p class='box'>This is centered</p>
<p class='box box2'>This is not<span class='circle'></span></p>
You can use absolute position.
.circle {
height: 20px;
width: 20px;
background-color: blue;
border-radius: 50%;
display: inline-block;
/* added */
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 10px;
}
.box {
background-color: yellow;
height: 30px;
width: 500px;
text-align: center;
margin: 10px;
position: relative; /* should be relative */
}
<p class='box'>This is centered</p>
<p class='box'>This is not<span class='circle'></span></p>
To center the text vertically and horizontally:
.circle {
height: 20px;
width: 20px;
background-color: blue;
border-radius: 50%;
display: inline-block;
/* added */
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 10px;
}
.box {
background-color: yellow;
height: 30px;
width: 500px;
text-align: center;
margin: 10px;
position: relative; /* should be relative */
/* add these to center text vertically and horizontally */
display:flex;
align-items:center;
justify-content: center;
}
<p class='box'>This is centered</p>
<p class='box'>This is not<span class='circle'></span></p>

Display 'SALE' tag before an image

I am looking to display a 'SALE' tag just before an image, I have tried to do this using the 'before' pseudo element however nothing seems to be displaying on the screen.
I am trying to create the 'SALE' tag inside a circle with black background.
Below is the code that I have used
<span class"bag-image">
<img src="https://images-na.ssl-images-
amazon.com/images/I/71lDa7EbWSL._UY395_.jpg" class="image">
</span>
.bag-image::before{
background-color: #red;
content: 'SALE';
border-radius: 500px;
display: inline-block;
width: 100px;
height: 100px;
}
For visual reference:
LIKE THIS
https://codepen.io/anon/pen/rgLPdp
Make the bag-image class position: relative;
Make the bag-image:before position: absolute; and position it with top/left or margins and set the line-height to vertically center the SALE text.
You can give the pseudo-class a lower z-index so that only the top half is visible, e.g. z-index: -1;
You can use margin-top: -2.5em; margin-left: 175px; in the pseudo-code to position it.
div.bag-image {
display: inline-block;
/* just so that we can see in the example */
margin-top: 3em;
}
div.bag-image:before {
position: absolute;
background-color: #ff0000;
content: 'SALE';
text-align: center;
color: #ffffff;
margin-top: -2.5em;
margin-left: 175px;
/* optionally make it a circle */
border-radius: 9999px;
height: 3em;
padding: 1em;
line-height: 3em;
}
/* just for clarity */
img.image {
border: 1px solid #ccc;
}
<div class="bag-image">
<img src="https://images-na.ssl-images-amazon.com/images/I/71lDa7EbWSL._UY395_.jpg" class="image">
</div>
I think you want this. Also check the codepen.Codepen
<style>
.bag-image{
text-align:center;
}
.bag-image::before{
content: 'SALE';
border-radius: 50px;
background: red;
display: inline-block;
width: 100px;
height: 100px;
position: absolute;
line-height: 100px;
color: #fff;
}
</style>
In summary, you need to add the position: relative property to the span, and the position: absolute property to the ::after element. Something like this:
.bag-image {
position: relative;
display: block;
}
.bag-image::after {
background-color: red;
content: 'SALE';
border-radius: 500px;
display: block;
width: 100px;
height: 100px;
position: absolute;
top: 0px;
text-align: center;
left: 100px;
}
<span class="bag-image">
<img src="https://images-na.ssl-images-amazon.com/images/I/71lDa7EbWSL._UY395_.jpg" class="image">
</span>
Play with the left (and maybe the top) property to place the text in the desired position.
You can try this code:
your code background-color: #red; is the wrong to declared #red it's instant of only red.
the sale is a position by my self parent relatively, you can learn about more position https://www.w3schools.com/css/css_positioning.asp .
here also write a shadow element related to some code for needed your answer.
maybe it solves your problem.
=== Thanks ===
.bag-image {
margin-top: 50px;
position: relative;
border: 1px solid red;
}
.bag-image img {
display: block;
max-width: 100%;
height: auto;
margin: 0 auto;
}
.bag-image::before{
background-color: red;
content: 'SALE';
border-radius: 500px;
display: inline-block;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
color: #fff;
position:absolute;
top: 0;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="bag-image">
<img src="https://images-na.ssl-images-amazon.com/images/I/71lDa7EbWSL._UY395_.jpg" class="image">
</div>

png icon with circle border - CSS

I've got a PNG image icon with un-even sides (64px x 42px) and I'd like to create a circle border around it.
My html looks like this:
<span class="cat_circle">
<div class="cat_icon">
<img src="https://cdn.pbrd.co/images/GNK97WG.png">
</div>
</span>
I created a circle border around the image, but I just can't get the icon to the exact middle of the circle. The icon sits on the bottom right of the circle.
Here is my CSS for the circle border:
.cat_circle {
border: 3px solid #7E9CC2;
border-radius: 50%;
width: 25px;
height: 25px;
overflow: hidden;
position: absolute;
padding: 30px;
left: 10px;
top: 10px;
text-align: center;
vertical-align: middle;
}
I then started fiddling with the actual png image and I gave it negative margins like this:
.cat_icon {
margin-top: -10px;
margin-left: -18px;
}
I mean it seems to work and I have my icon in the middle of the circle, but is this the right way I should be approaching this??
Here is my fiddle: https://jsfiddle.net/ox0anvL7/
You can do that a lot simpler. I added three flexbox properties for the centering, but erased one HTML wrapper and quite a few of the (too complicated) CSS settings:
.cat_circle {
border: 3px solid #7E9CC2;
border-radius: 50%;
width: 70px;
height: 70px;
display: flex;
justify-content: center;
align-items: center;
}
.cat_circle img {
width: 80%;
height: auto;
}
<span class="cat_circle">
<img src="https://cdn.pbrd.co/images/GNK97WG.png">
</span>
This is a pretty good way to do it. This works for all cases too when trying to center something inside a div.
It can be better than using flex as I believe that flex is only available in versions of IE 10 onwards (source here).
.cat_circle {
position: absolute;
display: inline-block;
border: 3px solid #7E9CC2;
border-radius: 50%;
width: 70px;
height: 70px;
}
.cat_circle img {
position: absolute;
top: 50%; left: 50%;
width: 80%;
transform: translate(-50%, -50%);
}
<span class="cat_circle">
<img src="https://cdn.pbrd.co/images/GNK97WG.png">
</span>
You Can Try this way !!
<div class="image-circle">
<div>
<img class="img" src="https://cdn.pbrd.co/images/GNK97WG.png">
</div>
</div>
.image-circle {
width:25%;
}
.image-circle:after {
content: "";
background: #4679BD;
padding-bottom: 100%;
border-radius: 50%;
display: block;
width: 100%;
height:0;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
}
.image-circle div {
float:left;
width:100%;
line-height:1em;
margin-top:-0.5em;
padding-top:40%;
text-align:center;
}
I'd suggest flexbox, simplifies and reduces the need of another class.
.cat_circle {
border: 3px solid #7E9CC2;
border-radius: 50%;
width: 25px;
height: 25px;
overflow: hidden;
position: absolute;
padding: 30px;
left: 10px;
top: 10px;
/* new */
display: flex;
justify-content: center;
align-items: center;
}
<span class="cat_circle">
<img src="https://cdn.pbrd.co/images/GNK97WG.png">
</span>

CSS Make a div curved at top and bottom but straight at the left and right sides

Hey guys I've been wondering if it was possible to do this, I've tried with border-radius but it only makes curves to the left and right sides apparently...
Here's what I need:
This would be the working div:
#mainbox {
width: 115px;
height: 24px;
background-color: gray;
border: 1px solid #000000;
text-align: center;
}
<div id="mainbox">
<div id="secondbox">test</div>
</div>
Any possible ideas?
Something like this can be achieved but it's troublesome. SVG will be better for this.
Referenced from this question on SO.
body {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
#mainbox {
width: 200px;
height: 130px;
overflow: hidden;
position: relative;
display: flex;
align-items: flex-end;
justify-content: center;
}
#mainbox::before,
#mainbox::after {
content: "";
display: block;
position: absolute;
height: 100px;
/* equal to inner curvedbox */
border-left: 5px solid black;
bottom: 0;
z-index: 1;
}
#mainbox::before {
left: 0;
}
#mainbox::after {
right: 0;
}
#curvedbox {
position: relative;
width: 100%;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
}
#curvedbox::before,
#curvedbox::after {
display: block;
content: "";
width: 140%;
height: 200%;
border: solid 5px #000;
border-color: #000 transparent transparent transparent;
border-radius: 100%;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
#curvedbox::before {
top: -30%;
}
#curvedbox::after {
top: 69%;
}
#secondbox {
transform: translateY(-140%);
}
<div id="mainbox">
<div id="curvedbox">
<div id="secondbox">test</div>
</div>
</div>
A few possible ideas:
You can try using
border-top-left-radius: 30%;
border-top-right-radius: 30%;. The problems with this are twofold: You'll see that it does end up curving the corners too when the percentages get higher (which isn't what you want), and it also doesn't support inverted, so you won't be able to use it for the bottom of the div.
Or, you can mess around with the clip-path property, like this: clip-path: polygon(0 0, 100% 0, 100% 96%, 0 100%); This article https://www.viget.com/articles/angled-edges-with-css-masks-and-transforms talks about how he uses that css property to make slanted divs.
Take a look at the methods presented in Invert rounded corner in CSS?. The point there was to try to make an inverted rounded corner, and a lot of the solutions presented pretty creative ways to manipulate the borders of a div.
I know this isn't a complete answer, but I hope it helps anyways :)