I am having a problem when I have a scrolling div when I scroll the background and border styles are not applied to the inner divs.
I have tried to simplify the problem here;
https://jsfiddle.net/w498trmf/22/
.GridScrollOuter {
overflow-x: hidden;
white-space: nowrap;
}
.GridScrollHeader {
overflow-x: auto;
}
.GridHeader {
background-color: #c8ffbb !Important;
color: red;
border-top: 1px solid #337ab7;
border-bottom: 1px solid #337ab7;
}
.Column {
width: 50%;
display: inline-block;
}
<div class="GridScrollOuter">
<div class="GridScrollHeader">
<div class="GridHeader">
<div class="Column">
<button>Button1</button>
</div>
<div class="Column">
<button>Button2</button>
</div>
<div class="Column">
<button>Button3</button>
</div>
</div>
</div>
</div>
It's because you have
.Column {
width: 50%;
display: inline-block;
}
Three divs with 50% width, so it's like 150% width. And .GridHeader is only 100% width.
Try this:
Make your .GridHeader 150% width
.GridHeader {
background-color: #c8ffbb !Important;
color: red;
border-top: 1px solid #337ab7;
border-bottom: 1px solid #337ab7;
width: 150%;
}
and your .Column 33% width:
.Column {
width: 33%;
display: inline-block;
}
Or if you will always have different number of divs, then forget about width and just add these classes to .GridHeader:
.GridHeader {
display: flex;
justify-content: space-between;
}
Here's the code snippet for non-constant number of inner divs.
.GridScrollOuter {
overflow-x: hidden;
white-space: nowrap;
}
.GridScrollHeader {
/*background-color: #c8ffbb !Important;
border-top: 1px solid #337ab7;
border-bottom: 1px solid #337ab7;*/
overflow-x: auto;
}
.GridHeader {
background-color: #c8ffbb !Important;
color: red;
border-top: 1px solid #337ab7;
border-bottom: 1px solid #337ab7;
width: 150%;
display: flex;
justify-content: space-between;
}
<div class="GridScrollOuter">
<div class="GridScrollHeader">
<div class="GridHeader">
<div class="Column">
<button>Button1</button>
</div>
<div class="Column">
<button>Button2</button>
</div>
<div class="Column">
<button>Button3</button>
</div>
</div>
</div>
</div>
Related
I'm trying to do a responsive layout, I'm not good with css so I need help.
Here is the code:
.container {
outline: 1px solid black;
max-width: 490px;
margin: 0 auto;
}
.columns {
outline: 1px solid black;
display: inline-flex;
flex-wrap: wrap;
}
.map {
background-color: cyan;
width: 150px;
min-width: 150px;
height: 150px;
min-height: 150px;
margin-right: 20px;
}
.content {
outline: 1px solid black;
background-color: lightgray;
max-width: 320px;
}
.cards {
outline: 1px solid black;
display: inline-flex;
flex-wrap: wrap;
}
.card {
background-color: pink;
outline: 1px solid black;
width: 150px;
height: 70px;
display: inline-block;
}
.card.left {
margin-right: 20px;
}
.texts {
outline: 1px solid black;
display: inline-flex;
flex-wrap: wrap;
}
.text {
background-color: gold;
outline: 1px solid black;
width: 150px;
height: 200px;
display: inline-block;
}
.text.left {
margin-right: 20px;
}
<div class="container">
<div class="columns">
<div class="map"></div>
<div class="content">
<div class="cards">
<div class="card left">card #1</div>
<div class="card">card #2</div>
<div class="card left">card #3</div>
<div class="card">card #4</div>
</div>
<div class="texts">
<div class="text left">text #1</div>
<div class="text">text #2</div>
</div>
</div>
</div>
</div>
Basically there are two rows.
The first one contains an element with fixed width and height, and on the right four cards.
The second rows contains only two elements.
Each element of this layout has width 150px.
The code shown above works partially.
The first row is ok, the second one no because the gold elements should stay aligned with the cards so when cards are on the right of el1, contents should below the cards.
It is like if there were to be a hidden element (on the left side of contents) that has the same size as el1.
Also I would like everything to always be centered because now it is only if the window width is > 490px.
This is what I'd like to have:
How can I do that?
I have following progress bar
I want the 'created', 'assigned' div's below circle and centred at the same time 'hr' line should touch the circle. Should work for varying screen sizes
How to make perfect circle here?
HTML
<div class="container">
<div class="progress">
<div id='content' class='filledCircle'></div>
<div>Created</div>
<hr class="line">
<div id='content' class='filledCircle'></div>
<div>Assigned</div>
</div>
</div>
CSS
.container{
position: relative;
border: 3px solid mistyrose;
margin-left: 50%;
}
.progress{
display: flex;
}
hr.line{
border: none;
background: grey;
width: 100%;
height: 2px;
}
.filledCircle{
height: 25px;
width: 25px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
Thanks in advance :)
For making a better circle you can use Padding
.container{
position: relative;
border: 3px solid mistyrose;
margin-left: 50%;
}
.progress{
display: flex;
align-items:center
}
hr.line{
border: none;
background: grey;
width: 100%;
height: 2px;
}
.filledCircle{
padding:15px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
<div class="container">
<div class="progress">
<div id='content' class='filledCircle'></div>
<div>Created</div>
<hr class="line">
<div id='content' class='filledCircle'></div>
<div>Assigned</div>
</div>
</div>
Just use align-items: center in your CSS file
and use padding instead of width and height
.progress {
display: flex;
align-items: center;
}
.filledCircle {
padding: 15px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
.container{
position: relative;
border: 3px solid mistyrose;
margin-left: 50%;
}
.progress{
display: flex;
}
hr.line{
border: none;
background: grey;
width: 100%;
height: 2px;
}
.filledCircle{
height: 25px;
width: calc(25px * 2);
background-color: #bbb;
border-radius: 50%;
display: inline-block;
}
<div class="container">
<div class="progress">
<div id='content' class='filledCircle'></div>
<div>Created</div>
<hr class="line">
<div id='content' class='filledCircle'></div>
<div>Assigned</div>
</div>
</div>
Answer:
I used CSS grids and put the circle, line and text in them and centred them accordingly.
display: grid;
grid-template-columns: [colstart]1fr [two]1fr [three]2fr [four]1fr [five]1fr [colend];
grid-template-rows: [rowstart]80% [rowcenter] auto[rowend];
.container {
display: flex;
justify-content: start;
border-right:1px solid black;
}
.side-nav {
border-right: 1px solid #111;
height: 200px;
padding-right: 20px;
}
.main-content {
margin-right: 20px;
margin-left: 20px;
}
.divider {
border-bottom: 1px solid gray;
}
.divider:before{
position: relative;
content: "";
width: 100%;
top: 1px;
right: 22px;
padding-right: 20px;
padding-left: 20px;
border-bottom: 1px solid gray;
}
<div class="container">
<div class="side-nav">
one
</div>
<div class="main-content">
two
<div class="divider"></div>
<p>some content gdvsgsgfghdgfhgdsfgdsgfdsfgdsfgdsgfgdsfgdsgfdsgfdsgfgdsgfffdfghjfghj</p>
<div class="divider"></div>
</div>
</div>
I'm creating a page layout. Inside the container, there are two containers- side-nav and main-content. In the main-content, there is a p tag with some demo text. the p tag is surrounded by two border containers. I m not able to extend the border lines upto the main container width. I have given a snippet of it, Can someone please help me to resolve this issue.
If I understand you correctly, add flex: 1 to .main-content so it will take the whole width that left.
.container {
display: flex;
justify-content: start;
border-right: 1px solid black;
}
.side-nav {
border-right: 1px solid #111;
height: 200px;
padding-right: 20px;
}
.main-content {
margin-right: 20px;
margin-left: 20px;
flex: 1;
}
.divider {
border-bottom: 1px solid gray;
}
.divider:before {
position: relative;
content: "";
width: 100%;
top: 1px;
right: 22px;
padding-right: 20px;
padding-left: 20px;
border-bottom: 1px solid gray;
}
<div class="container">
<div class="side-nav">
one
</div>
<div class="main-content">
two
<div class="divider"></div>
<p>some content gdvsgsgfghdgfhgdsfgdsgfdsfgdsfgdsgfgdsfgdsgfdsgfdsgfgdsgfffdfghjfghj</p>
<div class="divider"></div>
</div>
</div>
But seems you have more problems here. For example, if there is no enough space, the right border is displayed on top of the text. Also, small extra top and bottom borders in the left of the .main-content. What're you trying to do? How it should look?
You have given right:22px in your :before. That's causing the issue here.
.container {
display: flex;
justify-content: start;
border-right: 1px solid black;
}
.side-nav {
border-right: 1px solid #111;
height: 200px;
padding-right: 20px;
}
.divider {
border-bottom: 1px solid gray;
}
.divider:before {
position: relative;
content: "";
width: 100%;
top: 1px;
padding-right: 20px;
padding-left: 20px;
border-bottom: 1px solid gray;
}
p {
word-break: break-word;
padding:10px
}
<div class="container">
<div class="side-nav">
one
</div>
<div class="main-content">
<p style="padding:0 10px;margin:0">two</p>
<div class="divider"></div>
<p>some content gdvsgsgfghdgfhgdsfgdsgfdsfgdsfgdsgfgdsfgdsgfdsgfdsgfgdsgfffdfghjfghj</p>
<div class="divider"></div>
</div>
</div>
I honestly have no idea what you're trying to do here, but the modified example below looks a bit better, no?
.container {
display: flex;
justify-content: start;
border-right: 1px solid black;
}
.side-nav {
border-right: 1px solid #111;
height: 200px;
padding-right: 20px;
}
.main-content {
padding: 0 20px;
word-break: break-word;
}
.divider {
border-top: 1px solid tomato;
border-bottom: 1px solid gray;
display: block;
margin: 0 -20px;
position: relative;
}
<div class="container">
<div class="side-nav">
one
</div>
<div class="main-content">
two
<hr class="divider" />
<p>some content gdvsgsgfghdgfhgdsfgdsgfdsfgdsfgdsgfgdsfgdsgfdsgfdsgfgdsgfffdfghjfghj</p>
<hr class="divider" />
</div>
</div>
I don't see the reason for having the :before element within the divider if it then has the same color as the border anyways, you could just make the border 2px...or more generally, even if you need different colors, you can just work with top/bottom borders and you don't need the :before at all, you could also choose to got with an <hr /> element for that purpose, would be more semantic anyways =)
If a user is signed up to my site, in their login area I have 3 divs as follows:
<div id="psts-cancel-link" class="psts-cancel-link"></div>
<div class="psts-receipt-link"></div>
<div id="psts-signup-another"></div>
These divs all have a width of 32% and sit inline with each other.
#psts-cancel-link {
background: white;
border-left: 3px solid #ccc;
padding: 1em;
width: 32%;
min-height: 270px;
float: left;
}
.psts-receipt-link {
background: white;
border-left: 3px solid #ccc;
min-height: 270px;
float: left;
width: 32%;
margin: 0 10px;
padding: 20px;
}
#psts-signup-another {
background: white;
padding: 1em;
border-left: 3px solid #ccc;
margin-bottom: 30px;
width: 32%;
min-height: 270px;
float: left;
}
When a user is not signed up, only one of the divs displays:
<div id="psts-signup-another"></div>
Is it possible to change the styling of this so that it's width is 100% when div1 and div2 aren't displayed?
So far I have tried this, but with no success:
#psts-cancel-link ~ .psts-receipt-link ~ #psts_existing_info #psts-signup-another {
width:100%;
}
Table Layout Implementation
Use a table layout. Specify display: table on the parent and display: table-cell on the child elements.
#psts-cancel-link {
background: tomato;
border-left: 3px solid #ccc;
padding: 1em;
min-height: 270px;
display: table-cell;
word-wrap: break-word;
}
.psts-receipt-link {
background: lightblue;
border-left: 3px solid #ccc;
min-height: 270px;
margin: 0 10px;
padding: 20px;
display: table-cell;
word-wrap: break-word;
}
#psts-signup-another {
background: tomato;
padding: 1em;
border-left: 3px solid #ccc;
margin-bottom: 30px;
min-height: 270px;
display: table-cell;
word-wrap: break-word;
}
.container {
display: table;
width: 100%;
table-layout: fixed;
}
Logged in
<div class="container">
<div id="psts-cancel-link"></div>
<div class="psts-receipt-link"></div>
<div id="psts-signup-another"></div>
</div>
Logged out
<div class="container">
<div id="psts-signup-another"></div>
</div>
Flexbox Layout Implementation
You can also use flexbox which expands and shrinks the child items according to the parent container.
#psts-cancel-link {
background: tomato;
border-left: 3px solid #ccc;
padding: 1em;
min-height: 270px;
flex: 1;
}
.psts-receipt-link {
background: lightblue;
border-left: 3px solid #ccc;
min-height: 270px;
margin: 0 10px;
padding: 20px;
flex: 1;
}
#psts-signup-another {
background: tomato;
padding: 1em;
border-left: 3px solid #ccc;
margin-bottom: 30px;
min-height: 270px;
flex: 1;
}
.container {
display: flex;
}
Logged in
<div class="container">
<div id="psts-cancel-link"></div>
<div class="psts-receipt-link"></div>
<div id="psts-signup-another"></div>
</div>
Logged out
<div class="container">
<div id="psts-signup-another"></div>
</div>
You could simply use :first-child if it's indeed the only child in the second case.
#psts-signup-another:first-child {}
You can use the adjacent selector. Have a look at the following snippet:
#psts-signup-another {padding: 5px; background: #f99;}
div + div + #psts-signup-another {padding: 5px; background: #99f;}
<h2>Div when three divs are present</h2>
<div class="theDivs">
<div id="psts-cancel-link" class="psts-cancel-link"></div>
<div class="psts-receipt-link"></div>
<div id="psts-signup-another"></div>
</div>
<h2>Div when three divs are not present</h2>
<div class="theDivs">
<div id="psts-signup-another"></div>
</div>
i think you should use another container div with a new class when user logout.
Logged:
<div class="container">
<div id="psts-cancel-link" class="psts-cancel-link"></div>
<div class="psts-receipt-link"></div>
<div id="psts-signup-another"></div>
</div>
Logout:
<div class="container logout">
<div id="psts-cancel-link" class="psts-cancel-link"></div>
<div class="psts-receipt-link"></div>
<div id="psts-signup-another"></div>
</div>
CSS:
.container.logout > div {
display:none;
}
.container.logout > .psts-signup-another {
display:block;
}
Consider the following code:
HTML:
<div id="wrapper">
<div class='a'></div>
<div class='a'></div>
<div class='a'></div>
<div class='a'></div>
<div class='a'></div>
</div>
CSS:
#wrapper {
width: 300px;
border: 1px solid black;
overflow: auto;
}
.a {
width: 70px;
height: 70px;
border: 1px solid red;
float: left;
}
How could I force the horizontal scroll bar to appear rather than displaying the red div's in the second line ?
Try this:
#wrapper {
width: 300px;
border: 1px solid black;
overflow: auto;
white-space: nowrap;
}
.a {
width: 70px;
height: 70px;
border: 1px solid red;
display: inline-block;
}
It will give you spacing between the inner divs - put them all in one line to remove those.