:after class doesn't work as expected - html

I need to place the div content before the element, so I have used :before class. But it doesn't work. What could be the reason for it? Is there something incorrect with css?
.led {
/* Yellow LED */
margin-top: 3px;
width: 14px;
height: 14px;
background-color: #FF0;
border-radius: 50%;
box-shadow: rgba(0, 0, 0, 0.2) 0 3px 7px 0px, inset #808002 0 0px 9px, #D4D400 0 2px 12px;
margin-left: 80%;
}
.led:before {
content: "Connecting";
padding-left: 18px;
font-size: 11px;
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif !important;
}
<div class='led'> </div>

Everything is fine with CSS. As I understand :before and :after, it will add a content inside your div element. So, it will look something like this:
<div class="led">
<!-- content added with :before, Connecting in your case -->
Your div content
<!-- content added with :after -->
</div>
Problem that you are facing is that there is no content inside .led div, so :before and :after seem to have the same result. Your css defines .led div to have width of only 14px, so there is no place for Connecting text. You can try something like this for a quick (and ugly) fix:
.led:before {
content: 'Connecting';
margin-left: -60px; /* CHANGED */
font-size: 11px;
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif !important;
}
.led {
/* Yellow LED */
margin-top: 3px;
width: 14px;
height: 14px;
background-color: #FF0;
border-radius: 50%;
box-shadow: rgba(0, 0, 0, 0.2) 0 3px 7px 0px, inset #808002 0 0px 9px, #D4D400 0 2px 12px;
margin-left: 80%;
}
<div class="led"></div>
Better solution might be to enclose .led div with another one and add :before to that parent div, something like this:
.holder {
margin-left: 80%;
}
.holder:before {
content: 'Connecting';
font-size: 11px;
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif !important;
}
.led {
/* Yellow LED */
margin-top: 3px;
width: 14px;
height: 14px;
background-color: #FF0;
border-radius: 50%;
display: inline-block;
box-shadow: rgba(0, 0, 0, 0.2) 0 3px 7px 0px, inset #808002 0 0px 9px, #D4D400 0 2px 12px;
}
<div class="holder"><div class="led"></div></div>

Related

How to add box-shadow css property only to the bottom for the div element using css?

i want to add box-shadow only to the bottom of the div element using css.
below is the picture of what i am trying to do?
i want to get the line marked in red.
below is my code,
<div class="wrapper">
<div class="container"> //this needs box-shadow bottom
<span class="text">sometext</span>
<div class="description">some big description</div>
</div>
</div>
.wrapper {
position: absolute;
bottom: 32px;
width: 316px;
height: 225px;
background: white;
box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.29);
border-radius: 16px;
display: flex;
flex-direction: column;
opacity: 1;
}
.container {
height: 101px;
width: 316px;
padding-top: 16px;
padding-left: 16px;
border-radius: 16px 16px 0 0;
box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.29); //this adds boxshadow to all sides
}
.description {
height: 42px;
width: 289px;
margin-top: 8px;
color: black;
display: flex;
font-size: 12px;
font-weight: 400;
margin-bottom: 16px;
`;
As you see the container class adds boxshadow to all sides. i want to add only for the bottom how can i do it? could someone help me with this. thanks.
Try making your .container CSS like this:
.container {
height: 101px;
width: 316px;
padding-top: 16px;
padding-left: 16px;
border-radius: 16px 16px 0 0;
-webkit-box-shadow: 0px 10px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 10px 5px 0px rgba(0,0,0,0.75);
box-shadow: 0px 10px 5px 0px rgba(0,0,0,0.75);
}
Let me know how it goes.

How do I use pseudo-elements to display content after the main item? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to achieve the following look:
I want to place the heart on the top right of the price box. And I've managed to create it but the placement of the heart is hardwired. And if I change $89k to something bigger, the price box increases in width and the heart is misplaced.
Is there a way that :before or :after pseudo-element can know (or inherit) the width of the price box and place itself accordingly?
Or am I going about this in a wrong manner?
body {
background-color: lightsalmon;
transform: scale(3.0);
transform-origin: 0 0;
}
.home-price {
color: white;
border-width: 1px;
border-style: solid;
/* width: 50px; */
text-align: center;
border-radius: 2px;
font-family: Helvetica, Arial;
font-size: 14px;
font-weight: 300;
display: inline-block;
position: relative;
padding-left: 5px;
padding-right: 5px;
}
/* Favorite Marker */
.home-price:before {
content: "♥";
color: red;
display: inline-block;
position: absolute;
left: 39px;
top: -8px;
text-shadow: white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px;
}
.home-hot {
background-color: #C81845;
border-color: #F5F2F3;
}
<div style="height: 25px;margin-top: 30px;">
<div class="home-price home-hot">
$89K
</div>
</div>
</div>
In this case you can just use right: 0; instead of using hardcoded pixels for left, since you always want the icon to be displayed in the right corner anyway. There is no need to know the exact width of the element.
body {
background-color: lightsalmon;
transform: scale(3.0);
transform-origin: 0 0;
}
.home-price {
color: white;
border-width: 1px;
border-style: solid;
/* width: 50px; */
text-align: center;
border-radius: 2px;
font-family: Helvetica, Arial;
font-size: 14px;
font-weight: 300;
display: inline-block;
position: relative;
padding-left: 5px;
padding-right: 5px;
}
/* Favorite Marker */
.home-price:before {
content: "♥";
color: red;
display: inline-block;
position: absolute;
right: 0px;
top: -8px;
text-shadow: white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px,
white 0px 0px 1px;
}
.home-hot {
background-color: #C81845;
border-color: #F5F2F3;
}
<div class="home-price home-hot">
$80009K
</div>
<div class="home-price home-hot">
$89K
</div>
<div class="home-price home-hot">
$80009,99K
</div>

Floating DIV fit over another DIV

I need to get it so the div containing the date is at the top of the full_card div and expands to the full width of the card. Currently it is much lower and not expanding the full width.
p {
font-weight: bold;
font-family: Arial;
}
#container {
width: full;
}
.full_card {
float: left;
background-color: #d1ccff;
border-radius: 25px;
border: 5px solid #404266;
margin: 10px;
padding: 10px 30px 10px 30px;
width: 150px;
height: 250px;
}
#event {
font-size: 18px;
font-style: italic;
color: white;
text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}
#tag {
font-size: 18px;
text-align: center;
color: #000;
}
.date_back {
background-color: #404266;
border-radius: 25px 25px 0px 0px;
min-width: 150px;
height: 40px;
}
#date {
font-size: 26px;
text-align: center;
color: #fff;
}
<div id="container">
<div class="full_card">
<div class="date_back">
<p id="date">1981</p>
</div>
<p id="event">Voldemort murders Lily and James Potter</p>
<hr>
<p id="tag">Harry Potter</p>
</div>
</div>
Modified your code to show you how this is done.
The padding on the .full_card element affected everything inside of it, including the purple date "tab". I commented out this padding so the tab wouldn't be pushed down and inward.
By default, <p> elements have margin on the top and bottom. You need to override this if you don't want it - I added margin: 0; to stop the #date element from moving down.
Since we removed padding in step 1 (30px from both sides), I added 60px of width to the .full_card element to bring it to 210px wide, and then added 30px of padding to the sides inside the #event element.
To get the border-radius working properly on the purple element, I added overflow: hidden to .full_card (to "trim" anything inside to its shape), and removed the unneeded border-radius that was on the .date_back element.
Hope this helps!
p {
font-weight: bold;
font-family: Arial;
}
#container {
width: full;
}
.full_card {
float: left;
background-color: #d1ccff;
border-radius: 25px;
border: 5px solid #404266;
margin: 10px;
/*padding: 10px 30px; */
width: 210px; /* added 60px */
height: 250px;
overflow: hidden; /* added this for radius */
}
#event {
font-size: 18px;
font-style: italic;
color: white;
text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
padding: 0 30px; /* added this */
}
#tag {
font-size: 18px;
text-align: center;
color: #000;
}
.date_back {
background-color: #404266;
/* border-radius: 25px 25px 0px 0px; */
min-width: 150px;
height: 40px;
}
#date {
font-size: 26px;
text-align: center;
color: #fff;
margin: 0; /* added this */
}
<div id="container">
<div class="full_card">
<div class="date_back">
<p id="date">1981</p>
</div>
<p id="event">Voldemort murders Lily and James Potter</p>
<hr>
<p id="tag">Harry Potter</p>
</div>
</div>

Can element ignore height values of properties before it?

I have 2 elements sharing the same class .cta. The CTA inside of .casino-box looks great, however the one inside of .header-box is accounting for the 165px of space taken up by .top-nav-bar and .nav-bar.
How can I get the top CTA to ignore the added spacing of those two nav bars, without having to split the css code for the CTAs?
Link to CodePen
.cta {
max-width: 600px;
margin: 0 auto;
text-align: center;
position: relative;
top: 50%;
margin-top: -80px;
}
.cta h1 {
color: #fff;
weight: 500;
text-shadow: 0px 0px 4px black;
}
.cta .button {
color: #fff;
border-color: #fff;
font-weight: bold;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.7);
text-shadow: 0px 0px 4px black;
}
.cta .button:hover {
color: #90281F;
background: #fff;
text-shadow: none;
}
.cta hr {
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.7);
}
You have to set negative margin-top with the height of .top-nav-bar and .nav-bar plus your normal margin so the two div could be aligned in center. In this case it would probably be as following:
.header-box .cta {
margin-top: -205px;
}

Button width in css3

I have a button and I want it to be a particular size
html
<a class="button icon Raise"
onclick="raiseButtonAction(realPlayer, gameState)" id="nupp1" href="#"><span>RAISE</span></a>
css
.button {
position: absolute;
border-top: 1px solid #96d1f8;
background: #65a9d7;
background: -webkit-gradient(linear, left top, left bottom, from(#3e779d),
to(#65a9d7) );
background: -moz-linear-gradient(top, #3e779d, #65a9d7);
padding: 5px 10px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: rgba(0, 0, 0, 1) 0 1px 0;
-moz-box-shadow: rgba(0, 0, 0, 1) 0 1px 0;
box-shadow: rgba(0, 0, 0, 1) 0 1px 0;
text-shadow: rgba(0, 0, 0, .4) 0 1px 0;
color: white;
font-size: 19px;
font-weight: bold;
font-family: Segoe;
text-decoration: none;
vertical-align: middle;
But if I put for example width:100px; it doesn't change in size.
Am I doing something wrong or you just can't change the size of a premade button?
Try this..
.button {
display:inline-block;
min-width: 50px;
width: 80px;
padding:5px 10px;
}
That style is on an a element, which is an inline and won't accept a width. You could change it to be inline-block or block and then you'll have control over the width.
You need to make your <a> into a block level element. Here's an example of it working.
I just added this to your CSS for .button:
display: block;
width: 200px;
text-align: center;
Missing
display: block;
Have to set display to block if you want to set a fixed width on an inline element