I have the 3 div with 3 different of color and a paragraph. And i do a little manipulating with the paragraph so it can be moved anywhere with
p {
width: 50%;
border: 1px solid black;
margin: 0 auto;
position: relative;
bottom: 350px;
}
But after it moved, the problem is the last position of the block of paragraph still there and i want it to completely remove. How can i do that?
I will provide the SS so you can understand what i want.
When using position:relative and move the element, its first place (the space it takes) remain unchanged. As you can read here :
Setting the top, right, bottom, and left properties of a
relatively-positioned element will cause it to be adjusted away from
its normal position. Other content will not be adjusted to fit into
any gap left by the element.
div.red {
background: red;
height:120px;
}
div.blue {
background: blue;
height:120px;
}
p {
color: #fff;
padding: 20px;
position: relative;
top: -100px;
}
<div class="red">
</div>
<p>lorem ipusme lorem ipusmelorem ipusmelorem ipusme</p>
<div class="blue">
</div>
Instead you need to use position:absolute and add position:relative to the parent container to still be able to move the element relatively to its initial place.
div.red {
background: red;
height: 120px;
}
div.blue {
background: blue;
height: 120px;
}
div {
position: relative;
}
p {
color: #fff;
padding: 20px;
position: absolute;
top: -100px;
}
<div class="red">
</div>
<div>
<p>lorem ipusme lorem ipusmelorem ipusmelorem ipusme</p>
</div>
<div class="blue">
</div>
Related
I am trying to achieve these opposing skewed rectangles with text inside in css:
The first rectangle is set around the text container with the text skewing the opposite way of the rectangle.
HTML
<div class="col-lg-12 col-md-6">
<div class="container-fluid md">
<div class="rectangles rectangle-1">
<div class="text_container">
<?php if ($text) { ?> <div class="text WYSIWYG-styles"> <?= $text ?> </div> <?php } ?>
</div>
</div>
</div>
</div>
SCSS
display: block;
border: 1px solid $primary-color-2;
padding: 60px;
text-align: center;
&.rectangle-1 {
transform:skew(10deg, 10deg);
}
&.rectangle-2 {
transform: skew(-10deg, 10deg);
}
}
.text_container {
.text {
display: block;
transform: skew(-10deg, -10deg);
}
}
}
The problem is getting the second rectangle to skew the opposite way on the same plane. I thought about about using a pseudo element. I don't think that would work. Obviously, another inner div will just create an inner rectangle.
This is what I have so far:
Any help would be greatly appreciated.
I thought about using a pseudo element
Yea, you can use pseudo elements like this:
.double-skew {
position: relative;
text-align: center;
padding: 2rem;
max-width: 80%;
margin: 0 auto;
}
.double-skew:before, .double-skew:after {
content: "";
position: absolute;
border: 1px solid black;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
.double-skew:before {
transform: skew(30deg);
}
.double-skew:after {
transform: skew(-30deg);
}
<div class="double-skew">
Just wow!
</div>
You really only need the first argument in the skew transform to achieve this effect. The second argument will skew it vertically, which isn't what you want if you're trying to match your spec image.
I created this element using a parent div with relative positioning. Inside I have two spans that act as the border elements and a single p element which contains the text. The spans are absolutely positioned so they don't affect the p's position and can be placed on top of each other. Finally the outer div is a table and the inner p is a table-cell so I can easily align the contents of the p to the vertical and horizontal center.
This is done with plain CSS so it can be shown in a snippet, but you could just as well convert it to SASS.
div
{
display: table;
width: 400px;
height: 100px;
position: relative;
margin-left: 50px;
}
div span
{
display: block;
position: absolute;
width: 100%;
height: 100%;
box-sizing: border-box;
border: 2px solid black;
}
div span.left
{
transform: skew(30deg);
}
div span.right
{
transform: skew(-30deg);
}
div p
{
display: table-cell;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
text-align: center;
vertical-align: middle;
}
<div>
<span class="left"></span>
<span class="right"></span>
<p>Lorem ipsum dolor sit amet.</p>
</div>
I have something like this
<div class="container">
<div class="img-container">
<img class="thumbnail" src="https://via.placeholder.com/250x250" />
<div classe="img-icon-container">
<i class="photo-icon fas fa-camera-retro" />
<span>10</span>
</div>
</div>
</div>
.container{
height: 200px;
display: flex;
margin-bottom: 20px;
.img-container {
position: relative;
.thumbnail {
height: 100%;
}
.img-icon-container {
position: absolute;
bottom: 0;
width: 100%;
left: 0;
background-color: rgba(110, 110, 110, 0.8);
i {
margin-left: 5px;
margin-right: 5px;
font-size: 20px;
color: white;
}
&:hover {
background-color: blue;
}
}
}
}
In chrome it looks as I wanted.
but in IE 11 & FF
What do I need to add to keep the gray bar contained in the div?
Instead of width:100%; just add right:0;. This will always keep the edges of the inner box against the left and right sides.
The problem is the fixed height of the .container. If you have control of the sizing of these images I would just remove the fixed height of the .container and display: block; on the image to remove the spacing under it.
If you need it to accomodate varying aspect ratios then it's more complicated and there's never a perfect solution that looks neat.
I have a block <div> I want to define with precise pixel coordinates via position: absolute, but I want to position a heading above its parent <div>. If the font-size changes (or the user enlarges the text), the block <div> must stay in exactly the same place, but the heading may move up/down to accommodate the larger/smaller text.
Here is some sample code that, honestly, doesn't come close, but may help to illustrate the problem. It's just one of the variations I tried:
<!doctype html>
<html>
<head>
<title>Positioning Test</title>
<style>
#box1 { border: red 1px solid; }
#box1 h4 { margin: 0; color: blue }
.inner_box {
background: #aaf;
width: 400px;
height: 50px;
}
.target_pos {
position: absolute;
top: 50px;
left: 100px;
}
#marker {
width: 10px;
height: 10px;
background: red;
}
</style>
</head>
<body>
<div id="box1">
<h4>Heading</h4>
<div class="inner_box target_pos">
This is the <strong>inner_box</strong>.
</div>
</div>
<!-- Marks where the inner_box should begin -->
<div id="marker" class="target_pos"></div>
</body>
</html>
The idea is the blue inner_box must be positioned exactly at the marker (which it is), but the Heading text must be directly above it, and the red 1px border should enclose everything.
Here is how it looks in Firefox:
And here's how I would like it to look instead:
Since I have several of these boxes to work with, and their positions may change depending on viewport size, and the heading font/text will vary, I need a dynamic solution, here. I would prefer pure CSS3, but if JS is required, I could live with that.
I have created a fiddle for you that works for any font size, position and number of boxes.
http://jsfiddle.net/y73sqdr9/3/
Also
HTML
<div class="box target">
<h1>Headingggggggggg</h1>
<div class="inner">
This is the <strong>inner_box</strong>.
</div>
</div>
<div class="square target"></div>
<div class="box target2">
<h1>Headingggggggggg</h1>
<div class="inner">
This is the <strong>inner_box</strong>.
</div>
</div>
<div class="square target2"></div>
CSS
.box {
position: absolute;
border: 1px solid red;
border-top: none; }
.box h1 {
margin: -2em -1px -1px;
padding: .5em;
border: 1px solid red;
border-bottom: none;
line-height: 1; }
.box .inner {
padding: 1em;
background: #CCF; }
.square {
position: absolute;
width: 16px;
height: 16px;
background: red; }
.target { left: 100px; top: 150px; }
.target2 { left: 120px; top: 280px; }
I hope to have helped you!
How this is done:
The position id gives the position of the entire element.
The box class defines the width and height of the box and only has borders for bottom left and right leaving the top open because the header will be there
The header class height is set to zero as to not influence the box's position and is moved up 18 px
The h4 has borders on top left and right but not on the bottom so it will not block out the box
The html:
<!DOCTYPE html>
<html>
<head>
<title>Positioning Test</title>
<style>
.header{
position: relative;
bottom: 18px;
right:1px;
background: white;
height:0px;
}
.header h4{
width: 400px;
margin:0;
padding:0;
border: 1px red solid;
border-bottom:none;
}
.box{
border: 1px red solid;
border-top:none;
width: 400px;
height: 300px;
background: #aaf;
}
#position1 {
position: absolute;
top: 50px;
left: 100px;
}
</style>
</head>
<body>
<div id="position1" class="box">
<div class="header">
<h4>Title</h4>
</div>
<div class="inner">
I'm inside!
</div>
</div>
</body>
<html>
Firstly your body tags are are not wrapping your code.
Secondly your red box div should wrap all the other divs and be closed last. It closes early
I'm trying to create a solid box-shadow type effect without using CSS3. I'm constrained by a rich text editor's inflexible nature, and the need to have all styling in-line
Essentially, I need to place one div over another, slightly offset down, and right, div and have both centered and expand vertically with the amount of text I place withinin the top div.
I've included my best try at making it work here: jsfiddle example
CSS :
#firstDiv {
clear:left;
margin-top:30px;
padding: 0 30 0 30;
}
#secondDiv {
display: table;
clear:left; position: relative;
margin:auto;
width:70%;
padding:60 50 60 20;
background: #ccc;
}
#thirdDiv {
width:100%;
position: absolute;
top: -20px;
bottom: 20px;
right: 20px;
padding: 20px;
background: #fff;
border: 2px solid #ccc;
clear: left;
}
HTML :
<div id="#firstDiv">
<div id="#secondDiv">
<div id="#thirdDiv">
<!--My long Text-->
<p style="text-align: center">Lorem ipsum ...</p>
<p style="text-align: center">Lorem ipsum ...</p>
<p style="text-align: center">Lorem ipsum ...</p>
<p style="text-align: center">Lorem ipsum ...</p>
<p style="text-align: center">Lorem ipsum ...</p>
</div>
</div>
</div>
Unless I'm missing something...this should suit you very fine. Just insert this css inline in your html. http://jsfiddle.net/XfPNB/3/
We cannot use pseudo-elements (inline css restricts us). So, just add some div to the one containing all your text/content. Set position: relative; on your top div, then on the one that will be its shadow:
background: grey;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
Basically make sure it's exactly the same size as your main div, and then put it /under/ it (z-index). Grey (or yellow?) background. That's your shadow.
I was able to achieve your desired effect with two relative DIVs:
<div style="width: 70%; margin: 30px auto; position: relative; background-color: #ccc;">
<div style="position: relative; top: -20px; right: 20px; bottom: 20px; left: -20px; padding: 20px; background: #fff; border: 2px solid #ccc;">
JSFiddle
How do I position 2 divs that overlap plus a third div just to the right of those overlapping divs (but the third not floated all the way right)?
<div id=one>I overlap id=two.</div>
<div id=two>I overlap id=one.</div>
<div id=three>I am just to the right of one and two.</div>
The desired layout is:
| one-overlaps-two | three |
http://i.imgur.com/4CMNaUh.png
I know I can overlap the first 2 divs using a wrapper div that's position:relative and setting divs one & two to position:absolute
<div id="wrapper">
<div id=one>I overlap id=two.</div>
<div id=two>I overlap id=one.</div>
</div>
#wrapper{position:relative;}
#one,#two{position:absolute;}
But how can I get div id=three just to the right of overlapping divs one & two?
What I've got so far: http://jsfiddle.net/justAsking/cXrBA/
A solution can be as follows:
http://jsfiddle.net/cXrBA/2/
HTML
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
CSS
.wrapper {
padding-left: 100px;
width: 100px;
height: 100px;
position: relative;
}
.one , .two {
width: 100px;
position: absolute;
left: 0;
}
.one {
background-color: blue;
height: 50px;
top: 0;
z-index: 1;
}
.two {
background-color: red;
height: 100px;
top: 0;
}
.three {
background-color: green;
width: 100px;
height: 100px;
}
Give the second div a negative margin-left;
http://jsfiddle.net/HXH76/
div {
display: inline-block;
}
#one {
background: hsla(0,100%, 50%, 0.50);
}
#two {
background: hsla(90,100%, 50%, 0.50);
margin-left: -40px;
}
#three {
background: hsla(180,100%, 50%, 0.50);
}