Calc() alternative to fixed side bar with content? - css

I have a fixed side bar on the left and a right content area. Is there an alternative to calculating the content width other than calc()? I wanted a more browser safe method.
.left-sidebar {
width: 160px;
height: 100%;
border-right: 1px solid black;
position: fixed;
top: 72px;
}
.right-content {
position: absolute;
left: 160px;
top: 72px;
width: calc(100% - 160px);
overflow: hidden;
}

I have already done a similar example, which I would like to share. You need to use positioning for this case. This is a case of fixed-fluid:
+-------+-----------+
| FIXED | FLUUUUUID |
+-------+-----------+
Or
+-------+-----------+
| FIXED | FLUUUUUID |
| | FLUUUUUID |
+-------+-----------+
Fixed-Fluid Model. In my snippet, I have demonstrated two kinds of examples. In the first case, the fluid is less in size. And the next has too long content.
Snippet
.parent {position: relative; margin: 0 0 15px; border: 1px solid #999; padding: 5px; padding-left: 100px;}
.parent .fixed {position: absolute; left: 5px; width: 90px; background-color: #99f;}
.parent .fluid {background-color: #f99;}
<div class="parent">
<div class="fixed">Fixed</div>
<div class="fluid">Fluid</div>
</div>
<div class="parent">
<div class="fixed">Fixed</div>
<div class="fluid">Fluid Lorem ipsum dolor sit amet, consectetur adipisicing elit. Itaque animi placeat, expedita tempora explicabo facilis nulla fuga recusandae officia, maiores porro eaque, dolore et modi in sapiente accusamus id aut.</div>
</div>
For a better fixed fluid, I have done with the same kind for you:
.main-content {border: 1px solid #999; padding: 5px; position: relative; min-height: 200px; padding-left: 125px;}
.left-sidebar {position: absolute; left: 0; top: 0px; width: 120px; background-color: #eee; height: 100%;}
<div class="main-content">
<div class="left-sidebar"></div>
<div class="right-fluid">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum libero iure facere quam iste, nostrum laborum in, dolorum beatae optio rem explicabo voluptates qui quos eius accusamus! Accusamus blanditiis, et!
</div>
</div>

Related

Setting width of div element in a flex container [duplicate]

This question already has an answer here:
Why is a flex item limited to parent size?
(1 answer)
Closed 4 months ago.
So I have a flex container with 2 children. And I want to assign a fixed width to the first child. But If I set width: 200px, for some reason it does not work.
Here's my code:
.carousel {
background-color: #087f5b;
color: white;
padding: 32px;
width: 800px;
display: flex;
gap: 88px;
position: relative;
}
.img-container {
width: 200px;
height: 200px;
border: 1px solid;
}
<div class="carousel">
<div class="img-container"> </div>
<blockquote>
<p class="testimonial-text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum,
sapiente labore! Accusantium, voluptas omnis dicta facere, porro
mollitia minus ad ut debitis consequuntur.
</p>
</blockquote>
</div>
However, if I use min-width instead of just width, it works alright.
I also found out that if I delete some text from the blockquote, then it works fine.
.carousel {
background-color: #087f5b;
color: white;
padding: 32px;
width: 800px;
display: flex;
gap: 88px;
position: relative;
}
.img-container {
width: 200px;
height: 200px;
border: 1px solid;
}
.carousel blockquote {
flex: 1;
}
<div class="carousel">
<div class="img-container"> </div>
<blockquote>
<p class="testimonial-text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum,
sapiente labore! Accusantium, voluptas omnis dicta facere, porro
mollitia minus ad ut debitis consequuntur.
</p>
</blockquote>
</div>

Gradient borders with radius solution isn't working with tailwindcss

I have seen the gradient borders with radius work on css-tricks with this particular code snippet.
<div class="fem">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum neque debitis at ad fugit, esse sequi rem ab consequatur id sint veniam ex quam adipisci. Ab itaque officia atque id!
</p>
</div>
.fem {
padding: 1rem;
position: relative;
background: #000;
color: white;
border-radius: 8px;
}
.fem:before {
content: "";
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
width: calc(100% + 10px);
height: calc(100% + 10px);
z-index: -1;
border-radius: 12px;
background: linear-gradient(130deg,#ff7a18,#af002d 41.07%,#319197 76.05%);
}
I have tested this code on jsbin and it seems to be working perfectly fine.
Now, I'm working on a tailwind application and this same code isn't working for me.
I feel that some of the base styles might be causing this erratic behaviour. I can't seem to figure out how to correct it.
Here is the link to tailwind play
On tailwind, I'm seeing invisible gradient borders
<div class="main">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quia ullam fugit quaerat voluptates culpa dolores id
veritatis suscipit quo officia minus, ex totam velit praesentium explicabo, exercitationem blanditiis numquam
doloremque?
</div>
<style>
.main {
background-color: black;
max-width: 80%;
padding: 1rem;
position: relative;
color: white;
border-radius: 8px;
}
.main:before {
content: "";
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
width: calc(100% + 10px);
height: calc(100% + 10px);
z-index: -1;
border-radius: 12px;
background: linear-gradient(130deg, #ff7a18, #af002d 41.07%, #319197 76.05%);
}
</style>

absolute responsive image background

I have a little question due to position of background image in my footer.
As You can see on the picture, my current background image (green dotted line with ball - it is svg image) is placed in the middle if the footer.
I would like to place it in the position of the red line, staying there while resizing window.
Code of it is:
footer{
position: relative;
/* START OF IMAGE BG */
&:before{
content: "";
position: absolute;
display: block;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url("/wp-content/themes/company/static/img/line.svg");
-moz-background-size:90%;
background-size:90%;
background-repeat: no-repeat;
}
/* END OF IMG BG */
padding: rem-calc(45 20);
#media #{$medium-up}{
padding: rem-calc(85);
}
background-color: $bluedark;
color: $white;
min-height: rem-calc(500);
p{
font-size: rem-calc(12);
#media #{$medium-up}{
font-size: rem-calc(16);
}
font-weight: 300;
&.section-header{
text-transform: uppercase;
font-weight: 600;
}
&.bold{
font-weight: 600;
}
&.green{
color: $green;
}
}
.social-media{
img{
display: inline-block;
margin: rem-calc(0 5 20 5);
max-height: rem-calc(20);
#media #{$medium-up}{
max-height: rem-calc(40);
}
}
}
.underline{
margin-top: rem-calc(50);
border-top: 1px solid $bluegrey;
padding-top: rem-calc(20);
.logo{
float: left;
width: rem-calc(200);
height: rem-calc(45);
background: url("/wp-content/themes/company/static/img/logo_light.svg");
background-size: contain;
background-repeat: no-repeat;
}
select{
float: right;
}
}
}
And html is:
<footer>
<div class="line"></div>
<div class="flex">
<div class="row">
<div class="large-3 columns">
<p class="section-header">O nas</p>
<p>O Firmie</p>
<p>Zespół</p>
<p class="green">Blog</p>
</div>
<div class="large-3 columns">
<p class="section-header">Pomoc</p>
<p>FAQ</p>
<p>Regulamin</p>
<p>Polityka prywatności</p>
</div>
<div class="large-3 columns">
<p class="section-header">Social Media</p>
<div class="social-media">
<img src="{{site.theme.link}}/static/img/social-media/facebook.png">
<img src="{{site.theme.link}}/static/img/social-media/twitter.png">
<img src="{{site.theme.link}}/static/img/social-media/instagram.png">
</div>
</div>
<div class="large-3 columns">
<p class="section-header">Kontrakt</p>
<div class="button green">Formularz kontaktowy</div>
</div>
</div>
<div class="row underline">
<div class="logo"></div><span>
<select>
<option value="Polski">Polski</option>
<option value="English">English</option>
</select>
</div>
</div>
I know it is wrong placed due to top:0 however I dont know how to make it stay right on the top border of footer.
I would be grateful for any help.
A similar example of yours, I think its usefull for your purpouse:
div {
border: solid 1px green;
margin-bottom: 20px;
}
footer {
position: relative;
height: 50px;
background-color: red;
text-align: center;
padding-top: 20px;
}
footer:before {
content: "";
position: absolute;
display: block;
top: -50%;
left: 0;
width: 100%;
height: 100%;
background: url("http://www.curtainshopsouthport.co.uk/scissors.png");
-moz-background-size: 90%;
background-size: 90%;
background-repeat: no-repeat;
background-position: left 50%;
}
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam quis placeat architecto dolore recusandae nam amet, voluptate consequatur tenetur, quibusdam cupiditate culpa perferendis praesentium ab quasi voluptatum doloremque illum suscipit ea. Placeat
aperiam tempore maiores minus harum sint debitis beatae sit, eos voluptas est temporibus animi ullam praesentium voluptates molestiae dolore illo officiis blanditiis dolores. Qui labore asperiores quia dolore amet, culpa consectetur est quibusdam iusto
incidunt maxime aliquid sit eius explicabo aut, possimus corporis temporibus. Alias officia libero repellat veritatis, obcaecati repudiandae at voluptas, maxime doloremque facilis, sunt praesentium voluptatibus eaque provident natus, earum asperiores?
Possimus voluptatem, soluta deserunt.</div>
<footer>footer</footer>
As long as you don't have overflow issues, all you should need to do is replace top:0 with bottom:100%
footer{
position: relative;
&:before{
content: "";
position: absolute;
display: block;
bottom: 100%; /* change here */
left: 0;
width: 100%;
height: 100%;
padding-bottom: 50%;
background: url("img/line.svg");
-moz-background-size:90%;
background-size:90%;
background-repeat: no-repeat;
}

Make containers respect grid but fill remaining space [duplicate]

This question already has answers here:
Bootstrap full-width with 2 different backgrounds (and 2 columns)
(2 answers)
Closed 6 years ago.
I am having some trouble trying to create a layout like the image below. The left and right columns should take up 2/3 and 1/3 respectively of the main container max-width (which is centered using margin: auto;), but the remaining width of the page should be filled by the background image or the color of the column.
Is there some way to accomplish this with css?
It's a little tricky.
The problem is to avoid that the background image is cropped out of the body of the page, while a simple color fill is easier.
Try using :after and :before pseudo-elements with position:absolute; and putting there the background rules.
Then you need to force to fit all the page in all resolutions, so try these rules:
#left-column{
float:left;
width: 66.66%;
height:200px;
position:relative;
}
#left-column:before{
position:absolute;
/* for this example I used a free-copyright image from pixabay.com */
background:url(https://pixabay.com/static/uploads/photo/2016/05/01/00/57/barn-1364280_960_720.jpg) no-repeat;
background-size: 100% 100%;
top:0;
right:0;
width:100%;
padding-left:100%;
height:100%;
content:'';
display:block;
}
#right-column{
height:200px;
float:left;
width:33.33%;
position:relative;
}
#right-column:after{
position:absolute;
background:green;
top:0;
left:0;
width:10000px;
height:100%;
content:'';
display:block;
}
To show the content inside the columns give them a position:relative; z-index:1;.
Then you need to add to the body the following rule to avoid that backgrounds creates horizontal scroll-bar
body{
overflow-x:hidden;
}
To see it in a working example go here. .
If you prefer a more-accurate solution I think you must use javascript
You can emulate this with pseudo elements with large width:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
p {
margin-bottom: 16px;
}
.wrapper {
overflow-x: hidden;
min-height: 100vh;
}
.container {
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
max-width: 800px;
height: 700px;
margin: 0 auto;
}
.cols {
min-height: 300px;
display: flex;
}
.left {
background: linear-gradient(to right, #F9B80E, #E3342E);
flex: 0 0 66.6%;
position: relative;
}
.left:before {
content: '';
background: linear-gradient(to right, #FFED21, #F9B80E);
position: absolute;
right: 100%;
width: 1000px;
top: 0;
bottom: 0;
}
.right {
background: #E5E5E4;
position: relative;
padding: 20px;
}
.right:after {
content: '';
background: #E5E5E4;
position: absolute;
left: 100%;
width: 1000px;
top: 0;
bottom: 0;
}
<div class="wrapper">
<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae, quam. Dolore unde repudiandae deleniti, explicabo voluptatum, consequatur soluta architecto cumque! Modi sit doloremque veniam dignissimos porro nulla, exercitationem illum possimus!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae, quam. Dolore unde repudiandae deleniti, explicabo voluptatum, consequatur soluta architecto cumque! Modi sit doloremque veniam dignissimos porro nulla, exercitationem illum possimus!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae, quam. Dolore unde repudiandae deleniti, explicabo voluptatum, consequatur soluta architecto cumque! Modi sit doloremque veniam dignissimos porro nulla, exercitationem illum possimus!</p>
<div class="cols">
<div class="left"></div>
<div class="right">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugiat esse, corporis, quis accusantium, adipisci sequi animi cupiditate distinctio blanditiis consequuntur illo molestias velit dolorem qui sit voluptas. Labore cupiditate, quis.</p>
</div>
</div>
</div>
</div>

Responsive layout in which left column may move to the right

Say we have this responsive design with 3 columns (all 3 are dynamic contents so we don't know their heights)
For desktop:
For tablet (left column moves to the right)
What's the best way we can achieve this? (I don't mind using flexbox or other modern css specs)
You can make the elements make float: left on desktop with with 1/3 width each, then on tablet/mobile give them 50% width and make 1 and 3 float: right.
HTML:
<div class="b1">
1
</div>
<div class="b2">
2
</div>
<div class="b3">
3
</div>
CSS:
div {
float: left;
width: calc(100%/3);
box-sizing: border-box;
}
#media (max-width: 600px) {
div {
width: 50%;
}
.b1,
.b3 {
float: right;
}
}
Working JSFiddle
div{
border: 1px solid #333;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 20px;
float: left;
}
.div1{
background : yellow;
width: 25%;
}
.div2{
background : red;
width: 50%;
min-height: 400px;
}
.div3{
background : purple;
width: 25%;
}
#media (max-width: 768px){
.div1, .div3{
clear: right;
float: right;
width: 30%;
}
.div2{
width: 70%;
}
}
<div class="div1">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo reiciendis sapiente cumque optio incidunt, dolore impedit officiis ut tempore. Pariatur commodi perspiciatis ducimus laudantium atque sed eveniet explicabo animi ipsam!</div>
<div class="div2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo reiciendis sapiente cumque optio incidunt, dolore impedit officiis ut tempore. Pariatur commodi perspiciatis ducimus laudantium atque sed eveniet explicabo animi ipsam!</div>
<div class="div3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo reiciendis sapiente cumque optio incidunt, dolore impedit officiis ut tempore. Pariatur commodi perspiciatis ducimus laudantium atque sed eveniet explicabo animi ipsam!</div>
https://jsfiddle.net/yuywh5gv/
Try this, it might help. You can edit CSS as your wish
HTML code:
<div class="wrapper">
<div class="left"> 1 </div>
<div class="middle">2 </div>
<div class="right"> 3 </div>
</div>
CSS code:
.wrapper div {float:left;margin-right:.5%;text-align:center;}
.wrapper div:last-child {margin-right:0;}
.left {background: yellow; width:33%}
.middle {background: green; width:33%}
.right {background: blue; width:33%}
# Phone only screen and (max-width:320px) # Tablet only screen and (min-width:321px) and (max-width:768px) # Desktop only screen and (min-width:769px)
<div class="b1 col" >1</div>
<div class="b2 con">2</div>
<div class="b3 col">3</div>
add style bellow ::
div {
border: 2px solid black;
padding: 20px;
float: left;
box-sizing: border-box;
}
.con{
width: 66.66%;
}
div.col {
width: 16.5%;
}
.b1 {
height: 50px;
border-color: #ee8;
}
.b2 {
height: 200px;
border-color: #fcc;
}
.b3 {
height: 80px;
border-color: #caf;
}
#media screen and (min-width:321px) and (max-width:768px) {
div.col {
width: 33.33%;
}
.b1,
.b3 {
float: right;
}
}
DEMO

Resources