trying to make divs with a triangle shape with bootstrap and scss - html

image1
I am trying to make 3 divs in bootstrap like in this image.Now, I have the code but the problem is, that the before/after elements do not scale with its own div and text.I need to make them responsive, so in small screens, they go one under another.Here is a link withthe bootstrap and scss code: http://www.bootply.com/qYUhoNymFI

The scss code is not applied in your link, so I added classic CSS at the end to show you the way to follow to create triangle.
Here is the code I added :
.shipping,
.support {
position: relative;
background: #d7b789;
color: white;
text-align: center;
}
.returns {
position: relative;
background: black;
color: white;
text-align: center;
}
.shipping:before,
.returns:before,
.returns:after,
.support:after {
content: "";
display: block;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-o-transform: translateY(-50%);
transform: translateY(-50%);
border: solid 32px transparent;
width: 32px;
height: 32px;
}
.returns:before {
left: 0px;
border-left-color: white;
}
.returns:after {
right: 0px;
border-right-color: white;
}
.shipping:before {
right: -64px;
border-left-color: #d7b789;
z-index: 1;
}
.support:after {
left: -64px;
border-right-color: #d7b789;
z-index: 1;
}
Bootply
What I have done here is to set the background colors to match the example.
Then I set the a width, height (equal to the half of the parent div's height) and border to the before and after we want, and set their border-color to transparent.
On each 'before and after, you then define a border-color on the side you want to have the triangle to start.
You then have to place the left and right on the rights elements to place them where you want.
Notice the z-index I added on the first and last block so you are sure the triangles come over the middle block
Now you could translate this to scss to optimize the code.
For example make a mixin for the multiple transform prefixes so you don't have to repeat them everywhere.
Add a variable for the div's height (64px in the example), and use it also for the border-width ($height / 2), and replace the left: -64px; and right: -64px; using this variable too.

Related

CSS div content and font icon scaling

This question has 2 parts.
Part 1
I have the situation where I want to show an indicator:
HTML
<div class="alert-icon alarm">
<div class="hmi-icon-alarm"></div>
</div>
hmi-icon-alarm is an icon from a font file.
CSS
.alert-icon.alarm {
background-color: #c4262e;
border-style: solid;
border-color: #ffffff;
}
.alert-icon.alarm .hmi-icon-alarm {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
The above code works fine, but ideally to simplify things I would like to update the HTML to this:
<div class="alert-icon alarm"></div>
and based on the "alert-icon.alarm" class selector I would like to add the child div that sets the font icon. Similar to doing something like this:
.alert-icon.alarm::after {
content: '<div class="hmi-icon-alarm"></div>';
}
I know that this is not possible using content, but is there another (browser supported) way of doing this?
Part 2
Given the same html and css I want to be able to control the size of the font icon so that it is proportional to the width defined in the class .alert-icon (width and height will always be the same), so it can be scaled up and down and look the same (albeit a different size)
HTML
<div class="alert-icon alarm">
<div class="hmi-icon-alarm"></div>
</div>
hmi-icon-alarm is an icon from a font file.
CSS
.alert-icon {
width: 200px;
height: 200px;
}
.alert-icon.alarm {
background-color: #c4262e;
border-style: solid;
border-color: #ffffff;
}
.alert-icon.alarm .hmi-icon-alarm {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.alert-icon {
--size: 200; /* Icon width */
--scale-factor: 0.25 /* Icon size relative to container */;
width: calc(var(--size) * 1px)
}
.alert-icon.alarm::after {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
display: block;
font-size: calc(var(--size) / var(--scale-factor) * 1px);
transform: translate(-50%, -50%);
/* All other properties belonging to .hmi-icon-alarm */
}
NOTE: Maybe it will be not supported in IE.

What is the best way to avoid font-size scaling when transforming its container?

I am using css transform: scale to animate the entering of a modal. The problem is that the text scale with the <div> that contains it.
How can I avoid?
I want to use scale because it is the suggested way for obtaining smoother animations.
Without your code, it is hard to give you a working answer.
Basically, you cannot exclude a child element from its parent element being scaled. You can accomplish what you want by separating the two elements.
There is more information here.
What you can do is transform both the container and text.
The container is scaled up, while the text is scaled down - so it appears to stay the same.
Here is a very basic example:
button:focus + div {
transform: scale(2);
}
button:focus + div p {
transform: scale(.5);
}
div {
width: 200px;
margin: 0 auto;
text-align: center;
background: black;
color: white;
}
<button>Click to scale box</button>
<div>
<p>Do not scale this text</p>
</div>
#MalloreeEady answer, I just enhanced the answer from the post. Text that are related from the parent container usually get affected by any transformation. To able to avoid that, you may need to create another tag inside or use the pseudo-elements.
h2 {
color: #ffffff;
}
.box {
position: relative;
width: 50%;
height: 50%;
padding: 10px;
text-align: center;
margin: 50px auto;
}
.box::before {
content: '';
position: absolute;
top: 0; left: 0;
display: block;
background: #000;
width: 100%;
height: 100%;
z-index: -1;
}
.box:hover::before {
-webkit-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.3);
}
<div class="box">
<h2>TEST TEXT</h2>
</div>

CSS? How is this arrow made?

This is driving me insane. I've been using the Firefox inspector to try to figure out how this arrow was made (below) on the Headway site.
I've whittled away the code by deleting chunks via the inspector, and got it down to this:
No matter where I inspect, I can not find any such shape. No background image, no glyphs, nothing. It hardly even matters at this point, but I'm pulling my hair out trying to figure out how they did this!
Any CSS gurus care to take a look and chime in? For the sake of learning. :)
It's just a rotated square in the form of a ::before pseudo element.
As you can see, the element is a square (same height/width). The element is absolutely positioned with left: 50% and a negative margin-left of -31px (half the width) for horizontal centering. Finally, transform: rotate(-45deg) is used to rotate the square.
Here is the styling used:
.home-testimonial-wrapper:before
.home-cta-area::before, {
display: block;
width: 62px;
height: 62px;
background: #253031;
position: absolute;
top: -15px;
left: 50%;
margin: 0 0 0 -31px;
z-index: 5;
content: "";
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
transform: rotate(-45deg);
}
Aside from this, if you're interested in seeing how to make a triangle using CSS, see this answer.
You can make a triangle by playing with borders of a zero width/height div:
.triangleDiv {
width: 0;
height: 0;
border-style: solid;
border-width: 0 100px 100px 100px;
border-color: transparent transparent #000000 transparent;
}
<div class="triangleDiv"></div>
Just adjust the border-widths to get the size you want. No need for transforms. By adjusting which borders have width, you can 'rotate' the triangle.
The previous answers are good!
Just wanted to add, for design elements like that I always use one of two things.
Pseudo element to create the design feature ( as described above )
Pseudo element containing the design feature as an svg
Hope that helps!
You can do what they've done with rotating the square, but a more common solution is to use the border property:
.example {
position: relative;
}
.example:after {
content: '';
display: block;
position: absolute;
top: 0; /* or wherever */
left: 0; /* or wherever */
border: 10px solid transparent;
border-bottom-color: #000;
}

css turn right side of an image into an arrow

I have a rectangular sprite image that is 120px x 40px. When someone select the image I want the right side of the selected image to turn into an arrow pointing right.
I know how to use border-radius but that gives a curves whereas I want a point.
Using css how would I turn the right side of an image into a arrow?
Thanks
Basically I want to perform a border-radius only on the right side, but instead of curved pointed like an arrow.
.selected {
-webkit-border-radius: 0px 25px 25px 0px;
border-radius: 0px 25px 25px 0px;
}
If you can keep the white background here is a very simple solution:
jsFiddle here
Run the image in the background of the following example.
HTML
<div class="container"></div>
<div class="container"></div>
<div class="container"></div>
CSS
.container {
background: #333;
width: 200px;
height: 60px;
position: relative;
overflow: hidden;
margin-bottom: 10px;
}
.container:hover::after {
content: "";
position: absolute;
width: 70px;
height: 30px;
background: #fff;
top: -20px;
right: -20px;
z-index: 1;
transform: rotate(45deg);
}
.container:hover::before {
content: "";
position: absolute;
width: 70px;
height: 30px;
background: #fff;
bottom: -20px;
right: -20px;
z-index: 1;
transform: rotate(-45deg);
}
I do not know, i understood your question, but i think, what you want to achive, can be done by jQuery and css function with background-position
Basically, if you want to use a CSS Sprite image, background-position will indeed do it.
You may want to have a <div> positionned over your image, that will be displayed on hovering (CSS :hover) or click (jQuery click event) the image, depending on what you meant by "selecting" it.
Here is an example for hovering case (pure CSS) and here is an example for the clicking case (with 3 lines of jQuery).

CSS triangle with one constant dimension

I've used CSS border arrows quite regularly, but I don't know if what I want to achieve is possible with them, so I went another route and used pseudo elements instead. I know my solution relies on trigonometry but still don't know how to emplement it.
I need , regardless of the height of my .front div, to be able to maintain the 7PX width, thus, allowing for a flexible height with a fixed width:
.front{
height: 20px;
**width: 7px;**
background-color: darkred;
position: relative;
}
and that implies changing the transform angle in a mathematically controlled way:
.front:after{
content: " ";
height: 30px;
width: 15px;
background-color: lightgreen;
position: absolute;
top:0;
left: 0;
-webkit-transform-origin: top left;
transform-origin: top left;
-webkit-transform: rotate(-20deg);
transform: rotate(-20deg);
}
Is there a simpler way to achieve this? Images are obviously out of the question, because pixellation...
JsFiddle here.
Here's your fiddle with a triangle in the top right corner made purely of CSS. I'm sure that animating it is just a matter of resizing the two border widths.
#top_rt_tri {
position:absolute; top:0px;right:0px;width: 0px;
height: 0px;
border-style: solid;
border-width: 0 0 60px 60px;
border-color: transparent transparent #007bff transparent;}