I am trying to style a blockquote and child cite elements to replicate the appearance of a fieldset and legend element, where there is a border around the fieldset, and the legend label is inset in the top of the border -- if you've seen a fieldset you'll know what I mean.
I have a solution in which I give the cite a background-color, but this will only work when placed on a similar colored background. I need a solution that will work on all backgrounds, bg images, etc. in IE8+
Assume the following markup (cannot be changed from this. no additional elements allowed):
<blockquote class="quote">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas rem, animi
facere illum deserunt nam ipsa, et sapiente quisquam sed repudiandae aliquam
delectus. Reiciendis repellat illo, et natus earum odit!
<cite class="attribution">Mr. Jefferson</cite>
</blockquote>
CSS I have so far:
.quote {
border: 4px solid black;
padding: 1rem;
position: relative;
}
.attribution {
position: absolute;
top: 0;
left: 1rem;
margin-top: -0.65rem;
padding: 0 1rem;
background: white; /* this works, but breaks if the background isn't white. I need a solution that works for all possible page bg colors */
}
This is what I have so far: http://jsbin.com/viqegerivi/edit?html,css,output
I have to admit, I enjoyed this one. Used absolutely positioned :befores and :afters, didn't touch your HTML markup but, as expected, went wild on CSS. Cheers!
fieldset {
border: 4px solid black;
padding: 1rem 2rem;
}
legend {
font-style: italic;
padding: 0 1rem;
}
.quote {
border-bottom: 4px solid black;
padding: 2.6rem calc(2rem + 6px) 1rem;
position: relative;
overflow: hidden;
margin: 0;
}
.quote:before,
.quote:after {
content: ' ';
position: absolute;
width: 4px;
height: 100%;
background-color: black;
bottom: 0;
top: 1rem;
}
.quote:after {
left: 0;
}
.quote:before {
right: 0;
}
.attribution {
position: absolute;
top: 0;
left: 0;
margin-left: 2.4rem;
margin-top: .35rem;
padding: 0 1rem;
background: transparent;
}
.attribution:before,
.attribution:after {
position: absolute;
content: ' ';
bottom: calc(50% - 1px);
height: 4px;
background-color: black;
width: 100vw;
}
.attribution:before {
right: 100%;
}
.attribution:after {
left: 100%;
}
<p>Desired Look:</p>
<fieldset>
<legend>Mr. Jefferson</legend>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas rem, animi facere illum deserunt nam ipsa, et sapiente quisquam sed repudiandae aliquam delectus. Reiciendis repellat illo, et natus earum odit!
</fieldset>
<p>What I currently have:</p>
<blockquote class="quote">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas rem, animi facere illum deserunt nam ipsa, et sapiente quisquam sed repudiandae aliquam delectus. Reiciendis repellat illo, et natus earum odit!
<cite class="attribution">Mr. Jefferson</cite>
</blockquote>
EDIT: As Mr Lister spotted, there is a differece between this and the fieldbox title model: the background of the blockquote runs above (what looks like) top border.
I personally don't consider it a significant problem as
it can be easily overcome by adding an extra wrapper for background-clipping, so it's achievable, but requires a slightly more complex markup.
I don't think many will use this model with a background color that is different from that of the page. My personal oppinion is that this model looks best when used with transparent background (that's why we interrupt the line, right?).
Also, the intial challenge I set for myself was to achieve the effect without touching the markup.
I tried this out, works well:
html {background:blue}
fieldset {
border: 4px solid black;
padding: 1rem 2rem;
}
legend {
font-style: italic;
padding: 0 1rem;
}
.quote {
border: 4px solid black;
padding: 1rem;
width:auto;
margin:0;
position: relative;
}
.attribution {
position: absolute;
top: 0;
left: 1rem;
margin-top: -0.65rem;
padding: 0 1rem;
background:blue
}
Related
.container{
max-width: 80%;
margin:auto;
}
.section1{
background: #541A81;
padding: 60px 0;
}
.content{
background:#ffffff;
/* clip-path: polygon(0 90px, 100% 0, 100% 100%, 0 100%); */
border: 7px dashed #FFFD54;
border-radius: 50px;
padding: 168px 60px 92px;
transform: skew(10deg, 0);
}
<div class="section1">
<div class="container">
<div class="content">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit ad hic distinctio laboriosam iste neque quibusdam, adipisci sed magni explicabo nemo delectus nesciunt numquam non ducimus enim voluptatem ipsam! Esse!
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus dolorum unde debitis quos velit repudiandae. Explicabo, veniam, totam? Consectetur eum ab veniam, consequatur nemo, beatae soluta blanditiis quas quos dicta.</p>
</div>
</div>
</div>
I tried skewing it, but it seems to be skewing the whole axis, I have also tried the clip-path approach (code is commented there), however, this clip method is also removing the border as well.
I certainly wouldn't recommend this, however you theoretically could achieve something similar using pseudo elements - albeit it could get a bit messy with the perspective css property to skew in 3D.
Using pseudo elements, you could stop the actual text becoming skewed as you only apply these to the pseudo elements rather than the whole element.
body {
background: #541A81;
}
.wrap,
.light {
perspective: 300px;
}
.light {
position: absolute;
top: 50px;
left: 50px;
display: inline-block;
min-height: 200px;
width: 500px;
border-radius: 30px;
padding: 30px;
}
.light:before,
.light:after {
content: "";
position: absolute;
border-radius: inherit;
}
.light:after {
top: 30px;
left: 10px;
height: calc(100% - 20px);
width: 90%;
background: rgba(0, 0, 0, 0.8);
transform: rotateY(10deg) rotate(5deg);
z-index: -5;
}
.light:before {
top: 0;
left: -50px;
height: 100%;
width: calc(100% + 55px);
background: white;
border: 7px dashed #FFFD54;
box-sizing: border-box;
transform: rotateY(-5deg) rotateX(2deg);
z-index: -2;
}
<div class="wrap">
<div class="light">
hello! This text won't be skewed or messed up.
</div>
</div>
I'm trying to show message within a div with icon on the left.
Expected result is icon should always adjacent to text and together they need to be aligned at bottom-center of div.
I'm using :after pseudo element. Keeping position: absolute of icon didn't help since that needs manually adjusting the icon position relative to text.
Here is the CSS.
.parent{
font-weight: 500;
height: 65px;
text-align: center;
padding: 15px 0 10px;
margin: auto;
display: block;
width: 80%;
font-size: 12px;
overflow: hidden;
position: relative;
}
.parent > div {
float: none;
/* display: table-cell; */
vertical-align: middle;
position: absolute;
bottom: 0;
width: 100%;
}
.msg:after {
content: '';
background: url(data:image/...);
height: 16px;
width: 16px;
display: block;
position: absolute;
top: 0;
padding-right: 5px;
left: 108px;
}
And markup:
<div class="parent">
<div class="msg">text goes here</div>
</div>
Flexbox can do that:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
::before,
::after {
box-sizing: inherit;
}
.parent {
font-weight: 500;
margin: auto;
padding: 1em;
width: 80%;
font-size: 12px;
overflow: hidden;
position: relative;
border: 1px solid red;
}
.msg {
display: flex;
}
.msg p {
padding-left: 1em;
}
.msg:before {
content: "";
height: 16px;
flex: 0 0 16px;
background: red;
border-radius: 100%;
}
<div class="parent">
<div class="msg">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae numquam unde, eum sequi expedita fugiat ipsa exercitationem nesciunt libero repellendus aperiam excepturi, dolorem repudiandae eveniet alias perspiciatis, vero veniam tempora natus magnam
itaque quos. Nemo sit nisi, veniam mollitia fugit eaque reiciendis ex doloribus rem et suscipit debitis commodi sapiente.</p>
</div>
</div>
I want to centre the content on my page. I have a button and a paragraph of text on my page.
I'm new to css so I don't know what I should try.
body {
margin: 0 auto;
}
button {
top: 921px;
left: 400px;
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
top: 2639px;
left: 1014px;
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis
necessitatibus sed officiis repellat illo ratione libero recusandae
tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum
officiis exercitationem esse!
</p>
You can use display: flex;
body,
html {
height: 100%;
}
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
p {
text-align: center;
}
button {
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
<div class="container">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis necessitatibus sed officiis repellat illo ratione libero recusandae tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum officiis exercitationem esse!
</p>
</div>
Used flexbox for that:
body {
margin: 0 auto;
}
.wrapper {
display: flex;
align-items:center;
flex-direction: column;
justify-content: center;
height: 100vh;
}
button {
top: 921px;
left: 400px;
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
top: 2639px;
left: 1014px;
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<div class="wrapper">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis
necessitatibus sed officiis repellat illo ratione libero recusandae
tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum
officiis exercitationem esse!
</p>
</div>
You can use flexbox. Take a look at this https://css-tricks.com/snippets/css/a-guide-to-flexbox/.
Here is the solution for your current problem.
html,body, .wrapper {
margin: 0;
height: 100%;
}
.wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
button {
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<div class="wrapper">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis necessitatibus sed officiis repellat illo ratione libero recusandae tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum officiis exercitationem esse!
</p>
</div>
You can use flexbox technique as they say in other comments or you can add some lines to you code.
Add to body text-align: center; and add to p.text margin: 0 auto;
Your CSS code will become like that:
body {
margin: 0 auto;
text-align: center;
}
button {
top: 921px;
left: 400px;
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
margin: 0 auto;
top: 2639px;
left: 1014px;
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
See demo here
Just add
text-align: center;
and remember to remove the
text-align: left;
from your p.text
Some things to consider;
You are using top and left rules without giving a position rule value other than static (the default value). In your case you should use position: absolute
Don't use positioning with absolute values, if you don't need to. Absolute values (px unit) are not flexible enough to adjust to window size. Use relative units like % or vw/vh
For your contents to act as a group of elements, you should wrap it with a container element, which you then position accordingly (I used <div class="center"></div>)
I positioned this center container element absolutely using top: 50vh and left: 50vw. 100vh is 100 per cent of the view height, i.e. the inner window height and 100vw is 100 per cent of the view width likewise
This positioning is not enough, because it will position the top left corner of the .center element at the center of the window. We need to have a correction. I use transform: translate(-50%, -50%). This will shift an element 50% of its width to the left and 50% of its height to the top, making it perfectly centered.
There are alternatives like flexbox mentioned in the other posts, but this one is a little bit more straightforward for a beginner like you. Nonetheless it is recommended to learn flexbox. You might want to read A complete guide to flexbox on css-tricks.com
body {
margin: 0 auto;
}
.center {
position: absolute;
top: 50vh;
left: 50vw;
transform: translate(-50%, -50%);
}
button {
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<div class="center">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis necessitatibus sed officiis repellat illo ratione libero recusandae tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum officiis exercitationem esse!
</p>
</div>
On my page the footer is right under the content, which makes perfect technical sense. However, since the content is short and doesn't fill the whole page, only half of it, this leaves the footer in the middle of the screen. I was wondering how to have the footer at the bottom of the page for whatever screen size it's viewed on. I know this can be done with padding to the body content, or margin on the footer, however I don't know if I could do that to adapt to every screen size. Any help would be appreciated!
CSS
footer {
background-color: #242424;
color: #fff;
margin-top: 50px;
padding-top: 20px;
padding-bottom: 5px;
}
.search_wrapper {
display: inline-flex;
margin-top: 50px;
}
.search_ins {
font-size: 25px;
border: 1px solid #a6a6a6;
border-radius: 25px 0px 0px 25px;
padding: 3.2px 30px;
outline: 0;
width: 600px;
height: 100px;
}
.search_ins:hover .search_ins:focus {
border-color: #a6a6a6;
}
.search_button {
font-size: 30px;
border: 1px solid #a6a6a6;
border-left: 0;
padding: 0 12px;
color: #fff;
outline: 0;
border-radius: 0px 25px 25px 0px;
background-color: #fff;
cursor: pointer;
}
Easiest way to do this is using the vh unit for height of your main content. Assuming a structure similar to the below...
<main>Your content</main>
<footer>Footer</footer>
Set a min-height on your main content that's equal to 100% of you window minus your footer height.
main { min-height: calc(100vh - 60px); }
footer { height: 60px; }
Bam! Footer's always at the bottom, and you don't have to worry about padding, margins, or absolute positioning!
You need to display the parent of the footer as a column flexbox (column is a must because you need the flex items to stack vertically not horizontally); then set the margin-top of the footer to auto.
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
body {
font-family: Arial, sans-serif;
}
.text-center {
text-align: center;
}
.page-wrapper {
min-height: 100%;
display: flex;
flex-direction: column;
}
main {
padding: 0 15px;
}
footer {
background-color: #242424;
color: #fff;
padding: 15px 0;
margin-top: auto;
}
<div class="page-wrapper">
<main id="main">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis, dicta. Aut aspernatur ratione, eligendi quis inventore tempore aliquid sequi architecto, natus id deserunt perferendis excepturi sint blanditiis, similique aperiam dicta.</p>
<p>Earum incidunt distinctio repellendus, sequi, voluptate sint aperiam necessitatibus ut, a ipsa officiis ab quasi, odio soluta quos amet praesentium? Nesciunt repudiandae maiores in vel nulla magni aperiam omnis placeat!</p>
</main>
<footer class="text-center">Lorem ipsum dolor</footer>
</div>
I need to create the following shape on the image. Where is the photo there will variable content as a slider. What I tried so far is create it with border-width, but the problem is that I'm not able to put the small triangle under photo because of the bigger triangle.
What I've done you can find here on live demo. Maybe I have to use other approaches? Does someone how to solve it?
.header {
float: left;
width: 100%;
background: red;
padding-top: 50px;
padding-bottom: 200px; }
.content {
float: left;
width: 100%;
background: blue;
padding: 50px 0; }
.shape {
position: relative;
float: left;
width: 100%; }
.shape--1:before {
border-top-color: yellow;
border-right-color: transparent;
border-left-color: transparent;
border-bottom-color: transparent;
border-style: solid;
border-width: 160px 330px 0 0;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 30; }
.shape--2:before {
background: transparent;
border-bottom-color: transparent;
border-left-color: blue;
border-right-color: transparent;
border-style: solid;
border-top-color: transparent;
border-width: 130px 0 0 100vw;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 20; }
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod? - There will be slider with different background, same color should be also in the shape.
</div>
<div class="shape">
<div class="shape--1"></div>
<div class="shape--2"></div>
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
What I did is first create the element that holds the photo, then I created a rectangular shape in the body background color, rotated it and made it overflown. Then inside of it I placed another rectangular block that I rotated in the opposite way of the original triangle:
HTML:
<div class="photo"></div>
<div class="triangle"></div>
CSS:
body {
background: #fff;
overflow:hidden;
padding: 0;
margin: 0;
}
.photo {
width: 100%;
height: 200px;
background: red;
}
.triangle {
position: absolute;
background: #fff;
left: -100px;
right: -100px;
height: 300px;
transform: rotate(5deg);
transform-origin: 100% 100%;
overflow: hidden;
}
.triangle:after {
content: "";
display: block;
width: 400px;
height: 200px;
position: absolute;
background: orange;
left: 0;
top: -180px;
transform: rotate(-20deg)
}
And here is a working fiddle:
https://jsfiddle.net/62o7wqom/2/
Edit: Added overflow:hidden to the body tag to avoid having a horizontal scrollbar because of the absolutely positioned element...overflowing the body.
The easiest way of doing it would be setting a background-color on a containing div and use clip-path on the actual image. That would give you the effect you're looking for.
If you don't want the triangle to move with the slider you can either create another wrapper div or just create a pseudo after-element and position it on top of the image.
you may use some Pythagore stuff to calculate more precisely angles and sizes, but the idea is here.
.shape {
width: 100%;
height: 5em;
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 0, 25% 0, 0 100%);
}
.header {
text-align: center;
font-variant: small-caps;
font-size: 2em;
}
<div class=header>
<div class=shape style="background-image: url('http://backgrounds.mysitemyway.com/wp-content/uploads/2009/03/bamboo-001126-asparagus-fern-green.jpg')"></div>
awesome header
</div>
<div class=content>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
One posibility using an inner element to contain the image.
This element is rotated, and inside a pseudo there is the image, counter-rotated.
.test {
font-size: 30px;
width: 400px;
height: 200px;
border: solid blue 1px;
background-size: 200px 200px;
background-repeat: no-repeat;
position: relative;
}
.inner {
position: absolute;
width: 140%;
height: 140%;
bottom: 0px;
right: 0px;
z-index: -1;
transform: rotate(26.4deg);
transform-origin: right bottom;
overflow: hidden;
}
.inner:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-image: url(http://lorempixel.com/800/400);
background-size: cover;
transform: rotate(-26.4deg);
transform-origin: right bottom;
}
.triangle {
position: absolute;
width: 200px;
height: 200px;
top: 0px;
left: 0px;
background-image: linear-gradient(to right bottom, red 50%, transparent 50%);
z-index: -2;
}
<div class="test">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..
<div class="inner"></div>
<div class="triangle"></div>
</div>
Here I made a jsfiddle take a look just with your answer I made some css changes. Hope it helps.
.shape-1{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 160px solid transparent;
border-left: 0vw solid green;
border-right: 97vw solid green;
position:relative;
top: -130px;
}
.shape-2{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 130px solid transparent;
border-left: 42vw solid yellow;
border-right: 0vw solid yellow;
position:relative;
top:0px;
}
.header{
position: absolute;
z-index: 1;
}
<div class="shape">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam
accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod?
</div>
<div class="shape-2"></div>
<div class="shape-1"></div>
</div>
I noticed that you have already accepted an answer, but I figured I would still post some code that could help. This would require some fine tuning given what else you may have going on in your project, but it could get the job done.
.LeftT {
position: absolute;
top: 0rem;
left: 0rem;
border-left: 30rem solid #02A698;
border-right: 6rem solid transparent;
border-bottom: 8rem solid transparent;
border-top: 0rem solid transparent;
}
.RightT {
position: absolute;
top: 0rem;
left: -5rem;
border-top: 0rem solid #004F49;
border-left: 0rem solid transparent;
border-bottom: 8rem solid transparent;
border-right: 45rem solid #004F49;
}
p{
position: absolute;
top: 0rem;
left: 15rem;
z-index: 1;
}
<div class="LeftT"></div>
<div class="RightT"></div>
<p style="color:white;text-align:right;padding-right:1rem;font-size:1.1rem;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in turpis velit.
</p>