Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a few boxes inside a container. The container is set to overflow: hidden to make sure everything stays in its place. Taking away overflow: hidden is not an option because doing so allows content to overflow where it would otherwise resize to fit the container.
I'm trying to give the boxes a box-shadow, but when doing so, the shadows on the edge of the boxes at the edge of the container are not showing up (see image below), because the parent container stops there and has no overflow.
As indicated by the green arrows, the two boxes at left show their shadows as expected. As indicated by the red arrows, the two boxes at right have their shadows cropped at the right edge where each meets the container.
Is there any way to hack around this?
A simple reproduction:
Note: This code snippet was added by a community editor, not the author, as an attempt to reproduce the symptoms. It does not reflect the actual code used by the author to produce the attached image.
.container {
overflow: hidden;
display: grid;
grid-template-columns: repeat(2, 1fr);
column-gap: 1rem;
row-gap: 1rem;
}
.shadow {
display: inline-block;
height: 2rem;
background-color: tomato;
box-shadow: 0 0 0.25rem black;
}
<div class="container">
<div class="shadow"></div>
<div class="shadow"></div>
<div class="shadow"></div>
<div class="shadow"></div>
</div>
Can you add margins to the inner div's?
#inner-div {
margin: 10px
}
check this JSFiddle
try this one:
div {
top: 100px;
position: absolute;
left: 100px; height: 50px;
width: 200px;
-webkit-box-shadow:
5px 5px 5px #000,
inset 0 0 5px #000;
border-radius: 5px;
background: white;
}
UPDATED DEMO
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
So i need to make a website for school. My layout is almost done, but i'm stuck with one thing.
I have made a box around my main text (header and footer excluded), the box has a right and left margin of 150px. The background color is then changed so that it looks nice between the contrast of the background image and the box where the text is.
This is my problem: The bottom border is not connected to the footer, so if there is less text then other pages, you see more of the background image and this is ugly to look at.
below the CSS code for the main
main {
padding: 20px 20px 80px 20px;
margin: 0px 150px;
background-color: rgba(209, 219, 255, 0.829);
border-left: 5px solid #333;
border-right: 5px solid #333;
box-shadow: 0px 2px 0px 2px;
position: relative;
z-index: -1;
top: 80px;
}
I have tried to changed height to 100% so that it will take the full screen everytime. But this doesn't work.
I am trying to build a website which I also use angular. I need to perfectly centre a div element which contains some icons (around 80) and those icons must be left aligned. Contents are filtered via text input and this filtration results in different numbers of icons every time. I've tried a grid system similar to a bootstrap's grid, flexbox, whatever. Either a small extra area is left blank on the right side when I align my contents to left, or all the elements are centred and the bottom elements are centred and the div does not look organized. Moreover, I need to keep at least 10 px of margins between each icon. Can anyone help me?
.notfound {
text-align: center;
}
.iconelement:hover {
background-color: #ffffff;
box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.16);
color: #000000;
}
.iconelement:active {
background-color: #2974d4;
box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.16);
color: #ffffff;
}
.grid-container {
background-color: #fdfdfd;
padding-bottom: 20px;
display: flex;
justify-content: center;
text-align: left;
flex-wrap: wrap;
}
.iconelement {
width: 60px;
height: 60px;
border-radius: 4px;
background-color: #fdfdfd;
text-align: center;
margin: 10px;
float: none;
color: #000000;
}
.icons {
position: relative;
top: 50%;
transform: translateY(-50%);
font-size: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="ui-g ">
<div class="ui-g-12" *ngIf="(icons|filter:searchText).length===0">
<div class=" ui-g-12 notfound">
<h3>No results for "{{searchText}}"</h3>
</div>
</div>
</div>
<div class="ui-xl-3 ui-lg-3 ui-md-2 ui-sm-1" (click)="unselectIcon()"></div>
<div class=" ui-xl-6 ui-lg-6 ui-md-8 ui-sm-10 ">
<div class="ui-g-12 grid-container">
<div class="ui-g-1 iconelement" *ngFor="let icon of icons| filter : searchText; let i = index " (click)="getIcon(icon.id)">
<i class="icons {{icon.name}}"></i>
</div>
</div>
</div>
<div class="ui-xl-3 ui-lg-3 ui-md-2 ui-sm-1" (click)="unselectIcon()"></div>
</div>
ps: text align: center does not solve this problem.
If your goal is to create a responsive auto-centering container where items (icons) maintain the same width while the gaps between items adapt, your best way to do that currently is probably flexbox (and grids in the future). An example here.
The issue with flexbox based layouts, though, is how to have the last row aligned to the left. You could try some of the solutions proposed in this thread, however they work only in certain situations. Oftentimes you would need to use javascript to achieve this. I created a function for that and could post it somewhere should you be interested.
Generally, when you're dealing with this kind of a problem, you should consider, which elements need to adapt. Whether the gap between elements, the elements themselves or the container where elements reside.
Flexible gap - fixed elements - fixed/flexible container
Manageable by the approach I described above - flexbox to stretch the gap, fixed width on the elements and possibly javascript to align last row.
Fixed gap - flexible elements - fixed/flexible container
Fixed padding and flex attribute on the element.
Fixed gap - fixed elements - fixed container
Use float: left on the elements and put all into a container of defined dimensions. The container's width must be in multiples of elements width + padding to be centered, affected by how many elements should be on each line.
Fixed gap - fixed elements - flexible container
This is fairly well doable with flex attribute again. Often though there is a need to set a minimal width and we're back at case #1.
So achieving a fully responsive centered element with left-aligned items is currently a challenge. If you need perfection at all costs, I'd suggest using several media queries instead to make sure it always looks the way you want (As discussed here for example).
I have found my solution but it was not in the way I've wanted. I've got rid of all the ui-g grid layout except the grid itself. (the main reason that I've been using it is to run my page on all browsers, ie11 cause many problems with new technologies) I also used flex (flex-wrap as recommended) to keep the elements in the div.
That way the icons covered 100% of the screen in width.
To contain the items I have a maximum width but this meant that the responsiveness of the container is not there anymore. that is why I don't like this solution. To patch this, I used #media screen to adjust the number of elements displayed depending on the screen size.
To make it perfect it needed many trials and errors but a fix is a fix.
Fixing all the elements is done by "margin: auto;"
here is the code after fix:
<div class="ui-g">
<div class="notfound" *ngIf="(icons|filter:searchText).length===0">
<h3>No results for "{{searchText}}"</h3>
</div>
<div class="ui-g-12 grid-container">
<div class="ui-g-1 iconelement" *ngFor="let icon of icons| filter : searchText; let i = index "(click)="getIcon(icon.id)">
<i class="icons pi pi-{{icon.name}}" ></i>
</div>
</div>
In the div at the top I still use class=ui-g" to push down the sticky element which displays the icon details.
Each icon has the width and height of 60 px and has 10 px margin, so I needed to calculate the sum of the width and apply it according to the screen and how many icons I need to see side by side.
CSS:
.notfound {
text-align: center;
margin: auto;
width: 100%;
}
.iconelement:hover {
background-color: #ffffff;
box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.16);
color: #000000;
}
.iconelement:active {
background-color: #2974d4;
box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.16);
color: #ffffff;
}
.grid-container {
background-color: #fdfdfd;
padding-bottom: 20px;
display:flex;
flex-wrap: wrap;
max-width: 660px;
margin: auto;
}
.iconelement {
width: 60px;
height: 60px;
border-radius: 4px;
background-color: #fdfdfd;
text-align: center;
margin: 10px;
float: none;
color: #000000;
}
.icons {
position: relative;
top: 50%;
transform: translateY(-50%);
font-size: 2em;
}
#media screen and (max-width: 430px) {
.grid-container{
max-width: 260px;
}
}
the last bit is for the width configuration.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a sidebar on the right and I want to create two centered together columns for Tumblr posts on the left. What can I do?
#wrapper /*for two columns*/ {
display: inline-block;
margin: 15px 15px 15px 30px;
}
#wrapper .posts {
width: 400px;
margin: 0 15px 15px 0px;
padding: 10px;
}
#sidebar /*including some other stuff, obviously*/ {
display: table;
width: 250px;
height: 100%;
position: fixed;
top: 0px;
right: 0px;
}
To make HTML elements center aligned:
For Block element such as div, p, ..etc., these should have width or max-width set to some value and there should be margin-left: auto & margin-right:auto
For inline element such as span, em, ..etc., we can center align by giving text-align:center to its parent element.
Your horizontal margins on #wrapper should be set to auto. That’s the key. The parent (possibly the body) may need to also have set text-align: center.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a problem with my school project. I want to make two columns on my page using css, but nothing is working...
Website : http://kitlab.pef.czu.cz/~wbdinfo141528/
CSS : http://kitlab.pef.czu.cz/~wbdinfo141528/css/style.css
I hope that there is some dumb mistake, but I can't figure out, where the problem is.
I want to place the right column next to the left one :
Your margin was taking up the entire row, that's why the second div was pushed down. You don't need margin, just set the width and display it as an inline-block. The inline-block means it'll still be a block, but will wrap like text - so if there's enough space for the second div to be in the same row as the first, it can be.
Replace CSS with this, comments for what was changed.
div.leva {
background: blueviolet;
/* float: left; */
/* margin: 5px 500px auto auto; */
width: 49%;
display: inline-block;
}
div.prava {
background: yellow;
/* float: left; */
/* margin: 5px auto auto 500px; */
display: inline-block;
width: 49%;
}
Alternatively, you can use a relative container div and set that to 100%, and have two absolute divs inside the container with 50% width.
HTML
<div class="container">
<div class="leftdiv"></div>
<div class="rightdiv"></div>
</div>
CSS
.container {
position: relative;
width: 100%;
}
.leftdiv, .rightdiv {
position: absolute;
width: 50%;
top: 0;
}
.leftdiv {
left: 0;
}
.rightdiv {
right: 0;
}
You must add margin:0 in div leva et prava http://jsfiddle.net/rvp5js2w/
At first glance your floats are incorrect.
The purple is floated right while the yellow is floated left.
Set a width (where width is less then total width of stranka/2) for each of these div's and then float them correctly and it should line up.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have been having trouble for many days, and have asked several related questions in regards to these issues. My main question here is how to stop my divs from overflowing. I just managed to fix a problem with them being wrapped onto a different line.
Here is a fiddle.
And here is a snippet:
#main-content {
padding: 0% 15% 0% 15%;
overflow: hidden;
height: 620px;
clear: both;
width: 70%;
border-style: solid;
border-color: #31679a;
border-width: 0px 0px 2px 0px;
}
#side-bar {
float: left;
max-width: 28%;
height: 99%;
padding: 1% 1% 0% 1%;
font-size: 14px;
}
#container {
float: left;
max-width: 68%;
height: 100%;
padding: 1% 1% 0% 1%;
}
Main content contains both sidebar and container, which sit side by side (with the sidebar to the left)
You can see in the main content area, that the container overlaps the sidebar at certain widths, instead of stopping at it's edge. This also happens with the images in the header, but that doesn't show in the fiddle.
I would greatly appreciate any help.
As a quick fix, adding the following code to your CSS would stop the links from wrapping onto a new line:
#sidebar a {
white-space: nowrap;
}
However your real problem is that your sidebar div isn't wide enough to contain its content.
You should also be using divs instead of tables for layout purposes: read why here.