Sometimes when I come back to html I forget the simple things...
I want to be able to get the spans inside the div to center. IDK if I have it structured right, feel free to suggest anything
https://jsfiddle.net/yxg1zsac/
.define_link {
background: rgba(0,0,0,.3);
border-radius: 10px;
padding: 5px;
width: 200px;
margin: 5px auto;
font-size: 20px;
display: inline-block;
font-weight: bold;
text-align: center;
}
.pagination {
width:100%;
margin:auto
}
<div class="pagination">
<span class="define_link">previous</span>
<span class="current">Page 2 of 88.</span>
<span class="define_link">next</span>
</div>
Try this:
https://jsfiddle.net/tobyl/yxg1zsac/1/
Critical CSS:
.pagination {
text-align: center;
}
i think you want to this check it
https://jsfiddle.net/bhavhirani/gnrqxxka/1/
.define_link {
background: rgba(0,0,0,.3);
border-radius: 10px;
padding: 5px;
width: 200px;
margin: 5px auto;
font-size: 20px;
display: inline-block;
font-weight: bold;
text-align: center;
}
.define_link.prev{
float:left;
}
.current {
display: block; float: left; width: 30%; margin: 10px auto; text-align: center;
}
.define_link.next{
float:right;
}
.pagination {
width:100%;
margin:auto;
}
<div class="pagination">
<span class="define_link prev">previous</span>
<span class="current">Page 2 of 88.</span>
<span class="define_link next">next</span>
</div>
Related
I want to display cards in the same height even when the content(pattern-name) differs.I'm getting the content from DB.
Here is my html code
<div class="wrapper" *ngFor="let row of Pattern,I">
<div class="profile-card">
<div class="profile-card__unit-description">
<fa-icon
size="3x"
[icon]="faBrain"
class="icon"></fa-icon>
</div>
<div class="profile-card__unit-name">{{row.Pattern_Name}}</div> //This pattern name I'm getting it from DB.
<a class="fancy-button bg-gradient1" *ngIf="arr[row.Pattern_Id] == 1" onclick="return false">
<span (click)="onselect(row)">
<i size="2x" class="fa fa-ticket" ></i>Start
</span>
</a>
</div>
</div>
Here is my CSS for wrapper and profile-card
.wrapper {
display: inline-block;
margin: 0 50px;
padding-top: 100px;
padding-bottom: 80px;
}
.wrapper:focus {
outline: 0;
}
.profile-card {
background: white;
width: 300px;
display: inline-block;
margin: auto;
border-radius: 19px;
position: relative;
text-align: center;
box-shadow: -1px 15px 30px -12px black;
height:inherit;
}
.profile-card__unit-name {
font-size: 22px;
color: black;
margin-bottom: 10px;
margin-top:0px;
margin-left:10px;
margin-right:15px;
height:inherit;
}
.profile-card__unit-description {
padding: 20px;
color:#F9C118;
}
Please help me in doing that. Thanks in advance
as of now I did not get the reply from you that you want these 2 items side by side or up and down, so just seeing your code, I am assuming that you need it side by side.
so in your case just use display: flex; and flex-child will take the same height which will be side by side, to make last-child anchor below use flex-wrap: wrap and it will go down as first 2 items will take 50% width each.
I have given both div's background color just for demo purpose so that you can see these are taking equal height.
.wrapper {
display: inline-block;
margin: 0 50px;
padding-top: 100px;
padding-bottom: 80px;
}
* {
box-sizing: border-box;
}
.wrapper:focus {
outline: 0;
}
.profile-card {
background: white;
width: 300px;
display: inline-block;
margin: auto;
border-radius: 19px;
position: relative;
text-align: center;
box-shadow: -1px 15px 30px -12px black;
height:inherit;
display:flex;
flex-wrap: wrap;
}
.profile-card__unit-name {
font-size: 22px;
width: 50%;
color: black;
margin-top:0px;
padding-top: 20px;
background: green;
}
.profile-card__unit-description {
padding: 20px;
width: 50%;
color:#F9C118;
background: red;
}
.fancy-button {
width: 100%;
display: block;
}
<div class="wrapper" *ngFor="let row of Pattern,I">
<div class="profile-card">
<div class="profile-card__unit-description">
<p>dummy data for demo onlydummy data for demo onlydummy data for demo onlydummy data for demo onlydummy</p>
<fa-icon
size="3x"
[icon]="faBrain"
class="icon"></fa-icon>
</div>
<div class="profile-card__unit-name">row Pattern_Name</div>
<a class="fancy-button bg-gradient1">
<span (click)="onselect(row)">
<i size="2x" class="fa fa-ticket" ></i>Start
</span>
</a>
</div>
</div>
if need something else, feel free to share
You can check the outcome here in this link. At the bottom of the page, on the extreme right, there is a circle with an image of a tshirt. The image is not vertically centered properly.
The css of the anchor tag is this:-
.dfa {
padding: 5px 5px;
font-size: 30px;
width: 44px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 50%;
//line-height: 10px;
}
.dfa-tshirt {
background: #2c4762;
color: white;
}
The HTML is this:-
<a href="https://disabilityloverstshirtbuilders.com/" class="dfa dfa-tshirt">
<img src="https://png.icons8.com/color/100/t-shirt.png" style="width:35px; height:35; margin:auto; top:0; right:0; bottom:0; left:0;"/>
</a>
How can I center it? For the time being, I am using inline css for the img, which I will later remove to css file.
I would recommend to just keep it simple, let flex handle it for you. All your margins and padding will exacerbate things when your image changes sizes or other common situations
.dfa-tshirt {
background: #2c4762;
}
a {
display: flex;
justify-content: center;
align-items: center;
border-radius:50%;
width: 44px; height: 44px;
}
a img {
width: 35px; height: 35px;
}
<a href="https://disabilityloverstshirtbuilders.com/" class="dfa-tshirt">
<img src="https://png.icons8.com/color/100/t-shirt.png" />
</a>
EDIT: Non-flex solution --
I can't really plan for every scenario you may have, but to answer your question and support most browsers, I would also recommend just moving the actual styling to the image only:
a img {
width: 30px; height: 30px;
padding: 5px;
border-radius: 50%;
background: #2c4762;
}
<a href="https://disabilityloverstshirtbuilders.com/">
<img src="https://png.icons8.com/color/100/t-shirt.png" />
</a>
Use this:
img { vertical-align: middle; }
.dfa {
padding: 5px 5px;
font-size: 30px;
width: 44px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 50%;
line-height: 10px;
}
.dfa-tshirt {
background: #2c4762;
color: white;
}
img {
vertical-align: middle;
width:35px;
height:35px;
}
<a href="https://disabilityloverstshirtbuilders.com/" class="dfa dfa-tshirt">
<img src="https://png.icons8.com/color/100/t-shirt.png">
</a>
The images parent needs to be displayed inline-block
.dfa {
padding: 5px 5px;
font-size: 30px;
width: 44px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 50%;
display: inline-block;
}
The inline style should just be
<img src="https://png.icons8.com/color/100/t-shirt.png" style="width: 35px; height: 35px;"/>
I have just checked you site url, you can add two lines for the class as bellow.
display: table;
float: right;
.dfa {
padding: 5px 5px;
font-size: 30px;
width: 44px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 50%;
display: table;
float: right;
}
Img tag
<img src="https://png.icons8.com/color/100/t-shirt.png" style="width: 35px; height: 35px;"/>
I am making a Image upload result box, somehow I managed to give it proper layout but elements of the result box doesn't seem right in 'Brackets View'
I struggle when it comes to use floats, clear and display. I get confused, I've tried to learn it 4-5 times till now but somewhere I fail to apply them properly.
Can someone guide me through this code while explaining when and where to use them..
Also, I use this technique to clear floats but sometimes it works and sometimes nothing happens:
.example
{
content: ' ';
display: block;
clear: both;
}
My HTML & CSS:
.files-bar {
width: 100%;
max-width: 700px;
margin: 20px auto;
padding: 15px;
overflow: auto;
border: 1px solid #BBBBBB;
box-shadow: 2px 3px 15px #E7E7E7;
}
.delete {
float: right;
background-color: #02BFC1;
color: #FFFFFF;
font-family: gothic;
width: 100%;
max-width: 75px;
border: 1px solid #02BFC1;
font-size: 10pt;
padding: 10px;
border-radius: 5px;
cursor: pointer;
}
.image-thumb {
float: left;
display: inline;
width: 160px;
height: 120px;
margin-right: 20px;
}
.img-thumb:after {
content: '';
display: block;
clear: both;
}
.image-name {
font-size: 17pt;
margin-top: 2px;
}
.image-size {
font-size: 13pt;
margin: 20px 0;
}
.file-status {
display: block;
font-size: 12pt;
margin-bottom: 10px;
}
.progress-wrap {
float: left;
width: 300px;
height: 20px;
color: #111;
height: 5px;
margin-top: 5px;
}
.progress-meter {
max-width: 300px;
height: 5px;
background: #02BFC1;
}
.up {
margin-left: 30px;
}
.cancel-upload {
float: left;
margin: -25px 0 0 -15px;
}
<div class="files-bar">
<button class="manage-btn delete">Delete</button>
<img class="image-thumb" src="profile_image/2861e205148ccebc01cb9b1d8a4c6b0c.jpg">
<p class="image-name">14217596f69f44507b.jpg</p>
<p class="image-size">22 KB</p>
<p class="file-status">File Uploaded Successfully!</p>
<div class="progress-wrap">
<!-- Progress bar -->
<div class="progress-meter"></div>
</div>
<p class="cancel-upload">✖</p>
</div>
Float is not a good strategy for layout as it requires managing floats with clear:both. clear will clear any floats defined previously, in this case your delete button that is floated right.
Please see this quick reference on float and clear properties.
As mentioned in a comment above, using display:flex will give you greater control over layout. Here is a solution with minimal change to your original code. I set display:flex on the container defined by div files-bar, created a container for progress and one for the delete button. Together with the img, these sibling elements are flex items. Here is a good tutorial on using flex.
And the complete code:
.files-bar
{
width: 100%;
max-width: 700px;
margin: 20px auto;
padding: 15px;
overflow: auto;
border: 1px solid #BBBBBB;
box-shadow: 2px 3px 15px #E7E7E7;
display:flex;
}
.delete
{
background-color: #02BFC1;
color: #FFFFFF;
font-family: gothic;
max-width: 75px;
border: 1px solid #02BFC1;
font-size: 10pt;
padding: 10px;
border-radius: 5px;
cursor: pointer;
display:inline-block;
}
.button-cell {
text-align:right;
flex-grow:1;
}
.image-thumb
{
display: inline;
width: 160px;
height: 120px;
margin-right: 20px;
}
.image-name
{
font-size: 17pt;
margin-top: 2px;
}
.image-size
{
font-size: 13pt;
margin: 20px 0;
}
.file-status
{
display: block;
font-size: 12pt;
margin-bottom: 10px;
}
.progress-wrap
{
float: left;
width: 300px;
height: 20px;
color: #111;
height: 5px;
margin-top: 5px;
}
.progress-meter
{
max-width: 300px;
height: 5px;
background: #02BFC1;
}
.up
{
margin-left: 30px;
}
.progress {
position:relative;
}
.cancel-upload
{
position:absolute;
right:4px;
bottom:2px;
}
<div class="files-bar">
<img class="image-thumb flex-item" src="profile_image/2861e205148ccebc01cb9b1d8a4c6b0c.jpg">
<div class="progress">
<p class="image-name">14217596f69f44507b.jpg</p>
<p class="image-size">22 KB</p>
<p class="file-status">File Uploaded Successfully!</p>
<div class="progress-wrap"> <!-- Progress bar -->
<div class="progress-meter"></div>
</div>
<p class="cancel-upload">✖</p>
</div>
<div class="button-cell">
<button class="manage-btn delete flex-item">Delete</button>
</div>
</div>
UPDATE – New snippet using absolute position within a relative positioned container.
Please review the following solution. Instead of using float, I positioned the elements absolute within the files-bar container. This will work in any browser.
.files-bar
{
width: 100%;
max-width: 700px;
margin: 20px auto;
padding: 15px;
overflow: auto;
border: 1px solid #BBBBBB;
box-shadow: 2px 3px 15px #E7E7E7;
position:relative;
}
.delete
{
background-color: #02BFC1;
color: #FFFFFF;
font-family: gothic;
max-width: 75px;
border: 1px solid #02BFC1;
font-size: 10pt;
padding: 10px;
border-radius: 5px;
cursor: pointer;
position:absolute;
right:12px;
}
.image-thumb
{
display: inline;
width: 160px;
height: 120px;
margin-right: 20px;
float:left;
}
.image-name
{
font-size: 17pt;
margin-top: 2px;
}
.image-size
{
font-size: 13pt;
margin: 20px 0;
}
.file-status
{
display: block;
font-size: 12pt;
margin-bottom: 10px;
}
.progress {
position:absolute;
left:185px;
}
.progress-wrap
{
width: 300px;
height: 20px;
color: #111;
height: 5px;
margin-top: 5px;
}
.progress-meter
{
max-width: 300px;
height: 5px;
background: #02BFC1;
}
.up
{
margin-left: 30px;
}
.cancel-upload
{
position:absolute;
right:4px;
bottom:2px;
}
<div class="files-bar">
<img class="image-thumb" src="profile_image/2861e205148ccebc01cb9b1d8a4c6b0c.jpg">
<div class="progress">
<p class="image-name">14217596f69f44507b.jpg</p>
<p class="image-size">22 KB</p>
<p class="file-status">File Uploaded Successfully!</p>
<div class="progress-wrap"> <!-- Progress bar -->
<div class="progress-meter"></div>
</div>
<p class="cancel-upload">✖</p>
</div>
<button class="manage-btn delete flex-item">Delete</button>
</div>
Layout Problem Solved!
The problem was that I wanted to put image on the left and other contents to the right of the image.
But there was too much use of floats, clear and display it was confusing also code was improper. And even though using them I was not getting the proper output. As the 'paragraph' element was also behind the image due to floats.
So, after some more trials I achieved that layout I wanted without using 'position' and too much of floats and clear.
What I Applied:
First, Floated the image to the left.
Put all of the other content below image inside a div class named 'rest'.
Floated 'rest div' to the left too.
Floated delete button to the right.
At last I've applied Clear Fix for "files-bar div."
It was simple that's it. All other elements adjusted itself. I just needed to put all other contents inside a div element and float it.
Updated HTML:
<div class="files-bar">
<button class="delete">Delete</button>
<img class="image-thumb" src="profile_image/1777859bb71d37aec3.jpg">
<div class="rest">
<p class="image-name">14217596f69f44507b.jpg</p>
<p class="image-size">22 KB</p>
<p class="file-status">File Uploaded Successfully!</p>
<p class="cancel-upload">✖</p>
<div class="progress-wrap">
<div class="progress-meter"></div>
</div>
</div>
</div>
Default HTML's CSS has been removed which is also known as 'Doctor CSS'
Updated CSS:
.files-bar
{
width: 100%;
max-width: 600px;
padding: 15px;
border: 1px solid #BBBBBB;
box-shadow: 2px 3px 15px #E7E7E7;
}
.files-bar:after
{
clear: both;
content: '';
display: block;
}
.image-thumb
{
float: left;
width: 160px;
height: 120px;
margin-right: 20px;
}
.rest {float: left;}
.delete
{
float: right;
width: 100px;
background-color: #02BFC1;
color: #FFFFFF;
font-family: gothic;
max-width: 75px;
border: 1px solid #02BFC1;
font-size: 10pt;
padding: 10px;
border-radius: 5px;
cursor: pointer;
}
.image-name {font-size: 17pt;}
.image-size
{
font-size: 13pt;
margin: 20px 0;
}
.file-status
{
display: inline-block;
font-size: 12pt;
margin-bottom: 15px;
}
.progress-wrap
{
width: 300px;
height: 20px;
color: #111;
height: 5px;
}
.progress-meter
{
max-width: 300px;
height: 5px;
background: #02BFC1;
}
.cancel-upload
{
padding: 5px;
float: right;
cursor: pointer;
}
I'm trying to create a div, and then inside the div put the date on the left, and two icons on the right. Both should be vertically centered, have some margin to the edge, and margin between other elements in the parent div. But right now when I run it, the icons end up in strange positions, often clipping out of the div.
.c-project-bar {
width: 355px;
height: 30px;
display: table;
padding: 0px 10px;
background-color: #ffffff;
}
.c-project-date {
display: table-cell;
vertical-align: middle;
color: #828282;
font-size: 14px
}
.c-project-github-icon {
margin-left: 10px;
background-color: #000000;
height: 25px;
width: 25px;
float: right;
vertical-align: middle;
display: table-cell;
}
<div class="c-project-bar">
<p class="c-project-date">Aug, 2017</p>
<span class="c-project-github-icon"></span>
<span class="c-project-github-icon"></span>
</div>
https://jsfiddle.net/enyzhxyz/
Edit:
Everyone's answers are awesome, it seemed a major issue was the fact that the was inheriting { margin: 0px; }, and it was throwing a wrench in everyone's solutions. I solved this by including a margin: initial, before using any margin style later, so it first removed { margin: 0px; } then added the one I wanted.
When you give float: right you cannot vertically centre. Instead, use the inline-block technique:
.c-project-bar {
width: 355px;
padding: 0px 10px;
background: #ccf;
}
.c-project-date, .c-project-icons {
display: inline-block;
width: 48%;
vertical-align: middle;
}
.c-project-icons {
text-align: right;
}
.c-project-github-icon {
margin-left: 10px;
background-color: #000000;
height: 25px;
width:25px;
display: inline-block;
vertical-align: middle;
}
<div class="c-project-bar">
<p class="c-project-date">Aug, 2017</p>
<div class="c-project-icons">
<span class="c-project-github-icon"></span>
<span class="c-project-github-icon"></span>
</div>
</div>
I would have suggested you the transform and position centering technique, but it would be a too much of overkill for this solution. I have given some background colour to see it is perfectly vertical align middle. Although it uses slightly extra markup, this would be the right way that works on browsers that don't support flexbox too.
Here is a solution using css flexbox.
body {
background-color: #696969;
}
.c-project-bar {
display:flex;
align-items: center;
justify-content: space-between;
width: 355px;
height: 30px;
padding: 0px 10px;
background-color: #ffffff;
}
.c-project-date {
color: #828282;
font-size: 14px
}
.c-project-github-icon {
margin-left: 10px;
background-color: #000000;
height: 25px;
width:25px;
float: right;
}
<div class="c-project-bar">
<p class="c-project-date">Aug, 2017</p>
<div>
<span class="c-project-github-icon"></span>
<span class="c-project-github-icon"></span>
</div>
</div>
Another way to achieve this could be to use transform.
position: relative;
top: 50%;
transform: translateY(-50%);
.c-project-bar {
width: 355px;
height: 30px;
padding: 0px 10px;
background-color: #ccc;
}
.c-project-date {
margin: 0;
position: relative;
top: 50%;
transform: translateY(-50%);
float: left;
color: #828282;
font-size: 14px
}
.c-project-github-icon {
margin-left: 10px;
background-color: #000000;
height: 25px;
width:25px;
float: right;
position: relative;
top: 50%;
transform: translateY(-50%);
}
<div class="c-project-bar">
<p class="c-project-date">Aug, 2017</p>
<span class="c-project-github-icon"></span>
<span class="c-project-github-icon"></span>
</div>
You can do it easily with display: flexbox.
.c-project-bar {
display: flex; // power
align-items: center; // aligning
width: 355px;
height: 30px;
padding: 0px 10px;
background-color: #ffffff;
}
.c-project-date {
margin-right: auto; // let's push other stuff to right side
color: #828282;
font-size: 14px
}
.c-project-github-icon {
margin-left: 10px;
background-color: #000000;
height: 25px;
width:25px;
}
Fixed jsfiddle
How do I make two (or more) floating divs appear like "big buttons" and let them float and be leveled? My problem is that the boxes are "partially leveled"... with one slightly lower than the other. I have tried to use float: left on the adminBox, but then they grow outside the container. Can anyone help me?
I have used this HTML code:
(http://jsfiddle.net/jf936/13/)
<div class="container">
<div class="adminBox">
<h2>Manage users</h2>
<div class="adminBoxLargeContent" data-bind="text: usersCount"></div>
<div class="adminBoxSmallContent">Registered users</div>
</div>
<div class="adminBox">
<h2>Manage templates</h2>
<div class="adminBoxLargeContent" data-bind="text: templateCount"></div>
</div>
and this style:
.container{
background-color: light-blue;
}
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
}
.adminBox h2{
color:white;
font-size:20px;
text-align:center;
}
.adminBoxLargeContent{
font-size: 70px;
text-align:center;
padding: 0;
margin: 0;
line-height: 1;
}
.adminBox .adminBoxSmallContent{
float: none;
text-align:center;
}
This has nothing to do with float, the issue is that you are using display: inline-block; and hence the element are aligned to the baseline, inorder to fix this, you need to use vertical-align: top;
Demo
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
vertical-align: top; /* Add this here */
}
Note: You don't have to use float: none; as nothing is floated here, so you can get rid of those unused properties.
Here you go.
WORKING DEMO
The CSS Code Change:
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
float:left;
}
Hope this helps.
Maybe this code will be helpful for you:
jsfiddle
.container{
background-color: light-blue;
overflow:hidden;
}
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: block;
margin: 5px;
float:left;
}
.adminBox h2{
color:white;
font-size:20px;
text-align:center;
}
.adminBoxLargeContent{
font-size: 70px;
text-align:center;
padding: 0;
margin: 0;
line-height: 1;
}
.adminBox .adminBoxSmallContent{
text-align:center;
}
<div class="container">
<div class="adminBox">
<h2>Manage users</h2>
<div class="adminBoxLargeContent" data-bind="text: usersCount"></div>
<div class="adminBoxSmallContent">Registered users</div>
</div>
<div class="adminBox">
<h2>Manage templates</h2>
<div class="adminBoxLargeContent" data-bind="text: templateCount"></div>
</div>
</div>