Bootstrap 4 and css transform rotation - css

I want to make a diamond with lines beside. It works when it's a square, but when I apply transform: rotation(45deg); on the square, the two lines are crossing the diamond.
https://jsfiddle.net/0kty2fLw/

CSS transforms don't affect the position of any other elements. Initial sizes and positions of all elements are set before any CSS transforms are applied, then CSS transforms are applied, affecting only the transformed elements. This means that when your square is rotated 45 degrees, the lines on each side are still the same length they were before the rotation. After the transform, the rotated square is now wider than it was before the rotation, so the lines are overlapping the left & right points of your 'diamond'.
The quickest way to deal with this is to set a background colour (white would work with your example) on your square to cover the lines, and ensure the lines are set with z-index to go behind the rotated square. Alternatively, if you need the square/diamond to be transparent, you could reduce the width of the lines using the left & right margins to prevent the overlap.
As a side note, your Bootstrap structure is not correct: you shouldn't have a .container inside a .container. I would also avoid using Bootstrap grid elements for something like this. It adds unnecessary structural complexity to HTML that should be much more straightforward. If you need this to fit inside a Bootstrap layout, I'd just do the whole line / diamond design inside one full width .col and deal with the sizing & responsiveness independently.

Edited
check this.
#ligne1{
margin-right: -5vw;
}
#ligne2{
margin-left: -5vw;
}
It'll maintain the responsive design

Just increase left and right margin.
Here is jsfiddle: https://jsfiddle.net/0kty2fLw/4/
#ligne1{
margin-right: 35px;
}
#ligne2{
margin-left: 35px;
}
And remove col-2 class
<div class="container">
<div class="row ">
<div class="ligne col my-auto" id="ligne1"></div>
<div>
<div class="container">
<div class="row justify-content-center">
<div class="square my-auto">
<div class="circle">
</div>
</div>
</div>
</div>
</div>
<div class="ligne col my-auto" id="ligne2"></div>
</div>

Related

CSS layout with stretching background

I have this design layout that has a gradient background in the content container.
the gradient is a solid color on the left and right and gradient to white near the center. (horizontal gradient)
I have three images left-solid.png and a right-solid.png for extending the left and right of the content area if the viewing area is larger. I have main-gradient.png as the background for the main content and is a fixed size of 900px
Is there a way to lay this out without using a html table?
It looks like I need three columns of some sort
[leftcolumn][contentcolumn][rightcolumn]
rightcontent= can stretch and filled with right-solid.png repeat-x
content = 900px filled with main-gradient.png as background no repeat
leftcontent = canstrech and filled with left-solid.png repeat-y
any suggestions?
There are a number of ways you can achieve a multi-column layout without using tables. In fact, using tables is semantically incorrect. This very thing is one of the reasons CSS was created.
Using the following HTML structure:
<div class="container">
<div class="left">
</div>
<div class="middle">
</div>
<div class="right">
</div>
</div>
Then you could do this in CSS:
.left, .middle, .right {
display: inline-block;
}
This will tell the div's to appear next to each other. Additional CSS styles will be needed as well, like width properties for each column (preferable to use percents).
Another option for CSS would be:
.left, .middle, .right {
float: left;
}
This will also tell the div's to appear next to each other, but it does it a very different way.
A further note is that you don't need to use images for your gradient. You can do gradients using CSS. Take a look at http://www.colorzilla.com

CSS Positioning: Creating exact overlap with negative margin is off by several pixels

I have 2 divs I want to exactly overlap horizontally using negative margin-left.
HTML:
<div id=one></div>
<div id=two></div>
CSS:
body{margin:0px;padding:0px,border:0px}
#one {width:100px;height:100px;background-color:red;}
#two {width:100px;height: 50px;background-color:blue;}
#one,#two{display:inline-block;}
#two{margin-left:-100px;}
Before negative margin each div is 100px wide:
After negative margin the divs are 4px from overlapping exactly:
Why does setting a negative margin on the second div not cause it to exactly overlap the first div?
BTW, I'm just experimenting with margin-left...I know I can absolutely position the 2 divs inside a relative wrapper.
Thanks in advance for any enlightenment!
Inline elements are sensitive to their structure in your HTML. Since both divs are separated by a line break, they have a small "margin" between them like letters in a sentence would (which is pretty much the point of inline elements).
<div id=one></div> <!-- Here -->
<div id=two></div>
Change the structure of your HTML to remove this space:
<div id=one></div><div id=two></div>
Or you can use comments to negate the line break:
<div id=one></div><!--
--><div id=two></div>
Inline block has weird "bug" you could call it, that applies a 4px space between elements assuming a default font-size. This is created from the line-break between your div's. You'll find that you can fix this quite simply by making your negative higher.
margin-left: -104px;
This will fix your issue, but it's also not the only way to fix it.
You could do this... Instead of:
<div id=one></div>
<div id=two></div>
Delete the line-break between the div's so they are this:
<div id=one></div><div id=two></div>
This will also fix the issue.
You could alternatively set the font-size of their containing element to 0.
HTML:
<div class="container">
<div id=one></div>
<div id=two></div>
</div>
CSS:
.container { font-size: 0; }
But wait! There is more. You could comment out the line-break.
<div id=one></div><!--
--><div id=two></div>
You could drop the ending > to the beginning of the next element.
<div id=one></div
><div id=two></div>

howto make divs expand around fixed-sized div?

I want to frame a div surrounding divs having higher z-index.
(The framed div will contain a slideshow with elements, animated and with wierd margins, and the masking divs are supposed to hide the the texts being animated from the side.)
I'm thinking something like:
<div class="fullwith mask"></div>
<div class="mask leftpadding"></div>
<div id="slideshow" style="width:640px;height:405px;"></div>
<div class="mask rightpadding"></div>
<div class="fullwith mask"></div>
I've created this fiddle that by no means work, please fill the gap or tell me if I'm off the mark here.

How do I make the left and right gutters different colors with 960.gs?

How do I make the left and right gutters different colors with 960.gs? When I try something simple like:
<div style="background-color: green">
<div class="container_16">
<div class="grid_16">
test
</div>
</div>
</div>
<div style="background-color: cyan">
<div class="container_16">
<div class="grid_16">
test
</div>
</div>
</div>
The green and cyan colors are ignored. Seems like the "grid_16" class removes the color for some reason? My goal is being able to have different sections of the page in different colors all the way across the page, even past 960 pixels. So if someone makes their browser 1200px the left and right sides have the right color and the rest of the grid system is all contained within the 960 pixels in the middle.
I could add a background color to 'body' to do this for just 1 color, but I want multiple colors in the page. Like different colored horizontal stripes. Thanks.
Well, to understand the reason you need to understand how the grid layout works.
The thing is that when you tell the grid to be a certain width it also makes it floating.
Which means that your outer divs have the height of 0px.
So, in short. It doesn't remove the background colour, it just doesn't show it, because there is nothing to show (your grid is floating on top of it, so the actual size doesn't matter.
To solve it, just add a clearfix in the container and it should be solved. However, you also need to think about that the divs inherit the background colour per default.
<div style="background-color: green">
<div class="container_16 clearfix" style="background:white">
<div class="grid_16">
test
</div>
</div>
</div>
<div style="background-color: cyan">
<div class="container_16 clearfix" style="background:white">
<div class="grid_16">
test
</div>
</div>
</div>
Sticking two grid containers side-by-side is not a very smart way to produce horizontal stripes. If you want some containers to break past the grid's boundaries then adjust their margins appropriately, or put them behind (and outside) the grid entirely.

Putting some Images in a line

Here's a picture of my current situation :
alt text http://grab.by/FUM
But I don't want the images below each other, I want them in a line, a straight horizontal line.
This is the code I have currently:
<span title="Milestones" class="tl-icon">
<span class="tl-msg">
<span class="tl-msg-inside">
<div class="slice1"></div>
<div class="slice2"></div>
<div class="slice3"></div>
<div class="slice4"></div>
<div class="slice5"></div>
<div class="slice6"></div>
<div class="slice7"></div>
<div class="slice8"></div>
<div class="slice9"></div>
<div class="slice10"></div>
<div class="slice11"></div>
</span>
So how would I make all the images be in a straight line?
Try floating the images to the left. For example:
.image {
float: left;
}
You should set the class for all the divs to the same class, something like slices, and then go with:
.slices {
display: inline;
}
DIVs are block level elements and will cause each slice to be on it's own line. You can either change the display property of those divs to be inline, or use SPANs instead.
There's solutions to your problem, and then there's solutions to your problem.
The immediate fixup is to make the divs display:inline or float:left. Divs are naturally block which means each one will fill the entire width of their container, so they stack below each other. Inline makes them act like text and shrink to the size of their content, and sit next to each other. Floating works more-or-less similarly.
The better fixup is to avoid those divs altogether. Can you just use <img>? That's usually ideal.

Resources