Stacking images using CSS and HTML - html

In my code I have 5 div boxes lined up in a 900px container div. I'm have pictures inside the divs and text at the bottom. Both the pictures and text are in their own a href tags linking to the same place (because I wanted the text to :hover and this was the only way to do it).
So I need a SALE icon ONTOP of the pictures and on the edge (0px) of the border. The red sale icon is 100x100px (and at the very bottom, alone, in my sample HTML code). Everytime I use position: relative or position: absolute it pushed the picture and text in the div DOWN. How do I get the one on top of the other?? What am I doing wrong here? Here is the website right now: http://user2cis133.achins.com/final/
Here is some JSFiddle:
http://jsfiddle.net/gzbvejry/
Also I've read a shitton of articles on this and even copied and pasted their code and changed it for this and it still doesn't work.
#second {
background-color: #fff;
width: 210px;
height: 390px;
float: right;
border: 1px #000 solid;
border-radius: 10px 10px 10px 10px;
margin-left: 4px;
margin-top: 10px;
text-align: center;
}
a.hvr:link {
color: #696969;
}
a.hvr:hover {
color: #6495ED;
}
.brd {
position: abosolute;
margin: 5px;
}
#sale {
display: block;
left: 70px;
top: 0px;
}
<div id="second">
<a href="#">
<img class="brd" src="images/blue prom1.jpg" width="200px" heigth="380px" />
</a>
<a class="hvr" href="#">
Empire Waist Blue Prom Dress <br>
$150
</a>
</div>
<img src="images/sale.png" width="100px" height="100px"/>

give position:relative in #second{}.Also check the spelling of absolute in #sale, its wrong in the link
#second {
background-color: #fff;
width: 210px;
height: 390px;
float: right;
border: 1px #000 solid;
border-radius: 10px 10px 10px 10px;
margin-left: 4px;
margin-top: 10px;
text-align: center;
position:relative;
}
#sale {
position: absolute;
right: -49px;
top: -6px;
}

<div id="second">
<div class="sticker sticker-new"></div>
<a href="#">
<img class="brd" src="http://user2cis133.achins.com/final/images/aquaprom.jpg" width="200px" heigth="380px" />
</a>
<a class="hvr" href="#">
Empire Waist Blue Prom Dress <br>
$150
</a>
#second {
background-color: #fff;
width: 210px;
height: 390px;
border: 1px #000 solid;
border-radius: 10px 10px 10px 10px;
margin-left: 4px;
margin-top: 10px;
text-align: center;
}
a.hvr:link {
color: #696969;
}
a.hvr:hover {
color: #6495ED;
}
.brd {
margin: 5px;
}
#sale {
position: relative;
display: block;
left: 70px;
top: 0px;
}
.sticker-new {
background: url(http://user2cis133.achins.com/final/images/sale.png) no-repeat;
left: auto;
right: 0;
}
.sticker {
position: absolute;
top: 0;
left: 68px;
width:171px;
height:171px;
}

Related

How to stick image to div block in CSS?

I'm trying to stick an image to div block in CSS. I couldn't move 'image' using margin... What can I do? Advice is appreciated. Thank you.
What I want to implement
.bottalk {
background-color: white;
height: 100px;
width: 200px;
margin-top: 20px;
margin-left: 280px;
border-radius: 1.5em;
}
.bottalk p {
padding-top: 5px;
padding-left: 15px;
}
.bot .bottalkwhite {
height: 40px;
margin-left: 250px;
margin-top: 0px;
}
.bottalk button {
background-color: yellow;
color: purple;
padding: 5px 5px;
border: none;
margin-left: 50px;
box-shadow: 3px 3px 2px #666666;
}
<div class="col-6 bot">
<div class="bottalk">
<p>Ready to get started?</p>
<button>Let's talk</button>
</div>
<img src="./img/bottalk.png" alt="bottalk" class="bottalkwhite" />
</div> </div>
Current view
Please ignore the background color: I snipped it from the second image!
I have moved the position of the image inside the div with class bottalk, then I absolutely positioned the image, then all you need to do is to set the top and left position based on the image, (Cropped the image online so please ignore the quality of the output), So now you can position this anywhere. Also I have added background-color:pink to the body to show the image, please ignore this too.
So to summarize. I set the parent div element with class bottalk as position:relative and the child image with class bottalkwhite to position:absolute so that it can be positioned inside the parent. Position absolute will take the position relative to the immediate parent with position:relative, I hope I made my summary clear.
body{
background-color:pink;
}
.bottalk {
position: relative;
background-color: white;
height: 100px;
width: 200px;
margin-top: 20px;
margin-left: 280px;
border-radius: 1.5em;
}
.bottalk p {
padding-top: 5px;
padding-left: 15px;
}
.bot .bottalkwhite {
height: 40px;
position: absolute;
top: 80%;
left: -30px;
}
.bottalk button {
background-color: yellow;
color: purple;
padding: 5px 5px;
border: none;
margin-left: 50px;
box-shadow: 3px 3px 2px #666666;
}
<div class="col-6 bot">
<div class="bottalk">
<p>Ready to get started?</p>
<button>Let's talk</button>
<img src="https://i.stack.imgur.com/7i9bY.gif" alt="bottalk" class="bottalkwhite" />
</div>
</div> </div>
You can use the position: relative; and adjust the values of the top and left properties, like the follow code:
.bottalk {
position: relative;
left: -5px;
top: 10px;
background-color: white;
height: 100px;
width: 200px;
margin-top: 20px;
margin-left: 280px;
border-radius: 1.5em;
}
.bottalk p {
padding-top: 5px;
padding-left: 15px;
}
.bot .bottalkwhite {
height: 40px;
margin-left: 250px;
margin-top: 0px;
}
.bottalk button {
background-color: yellow;
color: purple;
padding: 5px 5px;
border: none;
margin-left: 50px;
box-shadow: 3px 3px 2px #666666;
}
<div class="col-6 bot">
<div class="bottalk">
<p>Ready to get started?</p>
<button>Let's talk</button>
</div>
<img src="./img/bottalk.png" alt="bottalk" class="bottalkwhite" />
</div> </div>
In order to put a image into a exact position relative to its ancestor, you can set position property to absolute then using left-right-top-bottom properties, you can determine its exact position. like this:
.bottalkwhite{
position: absolute;
left: 250px;
top: 0px;
}
though in such a particular css rule definition using id selector instead of class selector sounds more appropriate.
Use position:relative on the wrapper element of the image and position the image via position: absolute, left: 0 and bottom: 0 in the bottom-left corner. Then adjust it's position via transform: translate, to get the desired effect.
Note: I moved the image into the div.botttalk container to position it relative to its parent.
Like this:
body {
background: #715886;
font-family: Open Sans, Arial, sans-serif;
}
.bottalk {
background-color: white;
width: 200px;
margin-top: 20px;
margin-left: 100px;
border-radius: 8px;
padding: 24px 16px;
position: relative;
text-align: center;
color: #715886;
}
.bottalk .bottalkwhite {
position: absolute;
left: 0;
bottom: 0;
height: 40px;
color: white;
transform: translate(-100%, 100%) translate(16px, -16px);
}
.bottalk h4 {
line-height: 1;
margin: 0 0 24px 0;
}
.bottalk button {
cursor: pointer;
color: #715886;
display: inline-block;
background-color: #fbcb33;
font-weight: bold;
padding: 0 32px;
border: none;
line-height: 40px;
font-size: 14px;
box-shadow: 0px 1px 2px #666666;
}
<div class="col-6 bot">
<div class="bottalk">
<h4>Ready to get started?</h4>
<button>Let's talk</button>
<img src="https://i.imgur.com/oeUdlld.png" alt="bottalk" class="bottalkwhite" />
</div>
</div>

Bottom to top, right to left position small rectangles inside a bigger one (calendar)

I'm building a calendar, and this is what I'm after:
http://postimg.org/image/vpd10bkqt/
So basically I want to show all the events as a small rectangle inside the
appropriate day's big rectangle.
The difficulty is the first element should be shown at the bottom right corner,
and should be filling form right to left and bottom to top.
I think the simplest solution would be if a rectangle would be a
span element with a solid border around it, and it contains a dot as text.
Here is a jsfiddle demo:
http://jsfiddle.net/jv392gmv/
CSS:
section#calendar {
width: 970px;
}
time {
display: inline-block;
width: 120px;
height: 120px;
margin: 4px;
text-align: right;
font-size: x-large;
font-weight: 900;
border: 1px solid #c3c7c7;
border-radius: 5px;
background: #fff;
}
time.notmonth {
background: #777;
}
section#calendar h1 {
text-align: center;
}
section#calendar time a {
display: inline-block;
width: 110px;
height: 110px;
margin: 5px 5px 0 0;
padding: 3px 3px 0 0;
color: #f55b2c;
text-decoration: none;
}
section#calendar time a:hover {
color: #000;
}
span.event {
top: 10%;
left: 7px;
position: relative;
border-color: #222;
border-style: solid;
border-radius: 5px;
border-width: 5px;
}
HTML:
<section id="calendar">
<h1>
←
July 2015
→
</h1>
<time datetime="2011-05-29">
29
<!-- <span class="event">.</span> -->
</time>
</section>
Anyone has any idea how to achieve it?
The original time tag idea came from here:
http://thenewcode.com/355/HTML5-Calendar-With-CSS3-and-Microdata
In the container, set a rotation of 180 deg.
In the children, rotate again to get them upright
.base {
width: 140px;
height: 140px;
border: solid 1px black;
position: relative;
}
.test {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
transform: rotate(180deg);
}
.children {
width: 40px;
height: 40px;
background-color: lightblue;
transform: rotate(180deg);
display: inline-block;
margin: 2px;
}
<div class="base">
<div >123</div>
<div class="test">
<div class="children">1</div>
<div class="children">2</div>
<div class="children">3</div>
<div class="children">4</div>
<div class="children">5</div>
<div class="children">6</div>
<div class="children">7</div>
</div>
</div>

CSS arrow. Only a portion of the arrow is being displayed

I am trying to display a few words inside of a CSS styled arrow. I have figured out how to create an arrow with CSS which works fine. however, when I place the arrow within <h2>, complete arrow is not being displayed.
The source code is as follows
HTML
<div style="background-color: yellow;">
<h2><span style="background: green;">This is what I want</span><span class="arrow-right"></span><span style="margin-left: 50px;">is this what you want?</span></h2>
</div>
STYLE
<style>
.arrow-right::after{
content: "";
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid green;
}
</style>
The output is as follows
The arrow pointer is not being displayed completely. Am I using the elements wrongly? I will need the div / h2 height to be bigger later, but at least that is not my concern right now since the arrow itself is not being displayed as desired.
Edit:
Sorry for my bad drawing. This sample below is what I want but of course the arrow would be lots nicer I just used paints to give it a quick draw.
Is this what you're looking for?
http://jsfiddle.net/61tc5em9/2/
HTML
<div id="container">
<div id="arrow">text text text</div>
<div id="content">text text text text</div>
</div>
CSS
#container {
height: 75px;
background-color: black;
position: relative;
white-space: nowrap;
}
#arrow {
width: 30%;
background-color: red;
text-align: center;
font-size: 1.5em;
line-height: 75px;
}
#arrow::after {
content: "";
border-top: 37px solid transparent;
border-bottom: 38px solid transparent;
border-left: 50px solid red;
position: absolute;
left: 30%;
}
#content {
color: yellow;
font-size: 1.5em;
position: absolute;
left: 50%;
top: 25px;
}
Hope this helps. Let me know if you need any changes.
You need font-size:0; for the arrow.
.arrow-right::after {
content: "";
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid green;
font-size: 0;
position: relative;
top: -8px;
}
span{
display: inline-block;
}
<div style="background-color: yellow;">
<h2><span style="background: green;">This is what I want</span><span class="arrow-right"></span><span style="margin-left: 50px;">is this what you want?</span></h2>
</div>
Recommendations for improving your code and make it more dynamic:
Use :after in the statement element itself (this way you will avoid
the extra code in html and you can position the arrow relative to the element).
Align it to the right using left: 100% (so it is always position to
the right regardless of the width of the arrow).
Use top: 50% and margin-top: -(height/2)px to center it vertically.
Just like this:
.wrapper {
padding: 2px 0;
background: yellow;
}
.statement {
position: relative;
background: green;
}
.statement:after {
content:"";
border-top: 15px solid transparent; /*change the border width to set the desired hieght of the arrow*/
border-bottom: 15px solid transparent;
border-left: 15px solid green; /*change the border width to set the desired width of the arrow*/
position: absolute;
left: 100%;
top: 50%;
margin-top: -15px; /*the element has height= 30px (border-top + border-bottom) to center it -height /2 */
}
h2{
margin: 0;
}
<div class="wrapper">
<h2>
<span class="statement">This is what I want</span>
<span style="margin-left: 50px;">is this what you want?</span>
</h2>
</div>
Note that in this way you have a more semantic code because you don't have dummy element in your html and if you want more statement it will put the arrow behind automatically like this:
.wrapper {
padding: 2px 0;
background: yellow;
margin-bottom: 10px;
}
.statement {
position: relative;
background: green;
}
.statement:after {
content:"";
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid green;
position: absolute;
left: 100%;
top: 50%;
margin-top: -15px; /*the element has height= 30px (border-top + border-bottom) to center it -height /2 */
}
h2{
margin: 0;
}
<div class="wrapper">
<h2>
<span class="statement">One statement</span>
<span style="margin-left: 50px;">Good</span>
<span class="statement">Two statement</span>
<span style="margin-left: 50px;">Great</span>
</h2>
</div>
<div class="wrapper">
<h2>
<span class="statement">Where is the arrow?</span>
<span style="margin-left: 50px;">Do not worry about it</span>
</h2>
</div>

overlaping text with different styles over image, prevent text of one style to be shown on top of the text of another style

I know how to place some text over an image, but when that text contains different classes, different text styles, text lines overlap one on top of another.
Here is the simple html code with only one text style that works:
<li style="" class="portfolio-content-CV">
<div class="contentCV"><img src="images/backgr.png" height="500" width="510">
<p class="auto-style2"><span lang="es">yada yada</span></p>
</div>
</li>
Here is the code that doesn't work:
<li style="" class="portfolio-content-CV">
<div class="contentCV"><img src="images/backgr.png" height="500" width="510">
<p class="auto-style2"><span lang="es">yada yada</span></p>
<p class="auto-style1"><span lang="es">bla bla bla</span></p>
</div>
</li>
The css is formated as follows:
#portfolio-list .portfolio-content-CV a{
width: 510px;
float: left;
height:500px;
display:?table;
border:0.5px solid grey;
}
.contentCV {
width: 510px;
position: relative;
float: left;
cursor: pointer;
padding: 0px 0px 0px 0px;
background: #FFF;
border: 0px solid #E2E2E2;
margin-right: 10px;
margin-bottom: 10px;
display:table-cell;
vertical-align:bottom;
}
.contentCV a.titlesmall { display: none; }
.auto-style2 {
margin-left: 20px;
font-family: "AGENCYR";
font-size: 0.5em;
position: absolute;
top: 6px;
left: -8px;
width: 100%;
color: #000000;
}
.auto-style1{
margin-left: 16px;
font-family: "AGENCYR";
font-size: 0.5em;
position: absolute;
top: 6px;
left: -8px;
width: 100%;
color: #000000;
}
Any idea how can I get a complex text with different text styles to overlap over an image? o_O
The reason they overlap is because they have the same positioning:
top: 6px;
left: -8px;
and absolute positioned elements tend to overlap each other.
So you can create a div wrapper and put the p tags in it:
<div class="textWrapper">
<p class="auto-style2"><span lang="es">yada yada</span></p>
<p class="auto-style1"><span lang="es">bla bla bla</span></p>
</div>
css:
.textWrapper{
position: absolute;
top: 6px;
left: -8px;
}
Make sure to remove the position absolute from the <p> tags

Height issue for nested divs

Having a bit of trouble getting my nested divs lined up properly. You can see an example of the code I'm working with on Dabblet:
http://dabblet.com/gist/6125817
I've run into the following issues:
The wrapper scrolls vertically. I can live with this, but ideally I would rather it not.
The content needs to fill up most of the box. If the wrapper takes up the screen, then the content needs to take up most of the space.
The footer needs to align itself to the bottom of the wrapper (plus bottom margin), not bottom: 0.
Everything I try seems to make something else fall out of whack. I've been able to do parts of this when disabling other css classes. Just can't get them to all work at the same time.
Just in case the link isn't working:
body, html {
}
body {
background-image: url('/bground_home.png');
background-size: 100%;
background-repeat: no-repeat;
font-family: 'LegacySansUltra';
font-size: 20px;
}
.wrapper {
width: 90%;
height: 90%;
background-color: white;
border: solid 1px #666;
box-shadow: 10px 10px 5px #888888;
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.header {
font-size: 27px;
margin: 10px;
background-color: Black;
border-top-right-radius: 15px;
-moz-border-radius-topright: 15px;
color: White;
}
.content {
width: 90%;
height: 70%;
position: relative;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
background-color: #effbfb;
border-radius: 15px;
-moz-border-radius: 15px;
border: 3px solid #e0f8fd;
font-size: 25px;
}
.footer {
background-color: black;
padding: 5px;
color: White;
margin: 10px;
border-bottom-right-radius: 15px;
-moz-border-radius-bottomright: 15px;
height: 50px;
}
<div class="wrapper">
<div class="header">
<div style="position: relative; float:left; width: {#logowidth}; height: {#logoheight}; padding: 0px 10px;">
<img src="{#logo}" height="{#logoheight}" width="{#logowidth}" alt="{#name}" border="1" />
</div>
<div style="position: relative; float:left; padding-top: 20px;">
{#name}
</div>
<div style="clear: both;"></div>
</div>
<div class="content">
<div class="links">{#links}</div>
</div>
<div class="footer"></div>
</div>
Use this code:
overflow: hidden;