I need to center align div content responsively.
.wpwi_main {
border: 1px solid aliceblue;
border-radius: 5px;
font-size: 9px;
}
.wpwi_top {
text-align: center;
}
.wpwi_outer {
text-align: center;
margin: auto;
padding-bottom: 20px;
width: 100%;
}
.wpwi_inner {
display: table;
width: 40%;
margin: auto;
}
.wpwi_row {
display: table-row;
width: 50%;
}
.wpwi_row > div {
display: table-cell;
width: 20%;
}
<div class="wpwi_main">
<div class="wpwi_top">Top</div>
<div class="wpwi_outer">
<div>Outer</div>
</div>
<div class="wpwi_inner">
<div class="wpwi_row">
<div>Time</div>
<div>8:02 PM</div>
</div>
<div class="wpwi_row">
<div>Date</div>
<div>13 Aug 2022</div>
</div>
<div class="wpwi_row">
<div>Pressure</div>
<div>999 hPa</div>
</div>
<div class="wpwi_row">
<div>Visibility</div>
<div>10000 Meter</div>
</div>
<div class="wpwi_row">
<div>Cloudiness</div>
<div>98%</div>
</div>
<div class="wpwi_row">
<div>Sunrise</div>
<div>5:37 AM</div>
</div>
<div class="wpwi_row">
<div>Sunset</div>
<div>6:39 PM</div>
</div>
</div>
</div>
How can I center align content of wpwi_inner div so that content will remain center aligned if font size increase or decrease ?
You probably want to look at flexbox. You can tell flexbox children to be centered on either axis with very little effort and browser support is very strong these days.
.flex{
display: flex;
justify-content: center;
}
.wpwi_main {
border: 1px solid aliceblue;
border-radius: 5px;
font-size: 20px;
}
.wpwi_top {
text-align: center;
}
.wpwi_outer {
text-align: center;
margin: auto;
padding-bottom: 20px;
width: 100%;
}
.wpwi_inner {
display: table;
width: 40%;
margin: auto;
}
.wpwi_row {
display: table-row;
width: 50%;
}
.wpwi_row > div {
display: table-cell;
width: 20%;
}
<div class="flex-container">
<div class="wpwi_main">
<div class="wpwi_top">Top</div>
<div class="wpwi_outer">
<div>Outer</div>
</div>
<div class="flex">
<div class="wpwi_inner">
<div class="wpwi_row">
<div>Time</div>
<div>8:02 PM</div>
</div>
<div class="wpwi_row">
<div>Date</div>
<div>13 Aug 2022</div>
</div>
<div class="wpwi_row">
<div>Pressure</div>
<div>999 hPa</div>
</div>
<div class="wpwi_row">
<div>Visibility</div>
<div>10000 Meter</div>
</div>
<div class="wpwi_row">
<div>Cloudiness</div>
<div>98%</div>
</div>
<div class="wpwi_row">
<div>Sunrise</div>
<div>5:37 AM</div>
</div>
<div class="wpwi_row">
<div>Sunset</div>
<div>6:39 PM</div>
</div>
</div>
</div>
</div>
</div>
In the snippet, I enclosed your wpwi_inner within a div that has display: flex. Using the justify-content property we can make children of the flexbox stay centered on the main axis regardless of the size of the content inside.
Related
I have created simple circles using border radius 50% but the color of border is fading means color is spread out. How to Solve this ?, I have tried to create border using ::after but that doesn't work.
Here is my code:
.category-row {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.category-item {
margin-bottom: 10px;
padding: 15px;
}
.image-box {
width: 140px;
height: 140px;
border-radius: 50%;
display: table;
position: relative;
margin: 0 auto 24px;
background: #FBF4F3;
border: 1px solid #AF3D78;
}
.category-title {
text-align: center;
}
<div class="category-row">
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
Here is my problem:
I want a smooth border color.
Please open your jsfiddle link on a mobile device and zoom it. It is not fading out. The appearance may be different depending on the resolution and screen size.
Otherwise, you can try increasing the border-width to 2px:
.category-row {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.category-item {
margin-bottom: 10px;
padding: 15px;
}
.image-box {
width: 140px;
height: 140px;
border-radius: 50%;
display: table;
position: relative;
margin: 0 auto 24px;
background: #FBF4F3;
border: 2px solid #AF3D78;
}
.category-title {
text-align: center;
}
<div class="category-row">
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
<div class="category-item">
<div class="image-box"></div>
<div class="category-title">Fragrance</div>
</div>
</div>
My Code is like below.
.wpwi_main {
border: 1px solid aliceblue;
border-radius: 5px;
font-size: 9px;
}
.wpwi_top {
text-align: center;
}
.wpwi_outer {
text-align: center;
margin: auto;
padding-bottom: 20px;
width: 100%;
}
.wpwi_inner {
display: table;
width: 40%;
margin: auto;
}
.wpwi_row {
display: table-row;
width: 50%;
}
.wpwi_row > div {
display: table-cell;
width: 20%;
}
<div class="wpwi_main">
<div class="wpwi_top">Top</div>
<div class="wpwi_outer">
<div>Outer</div>
</div>
<div class="wpwi_inner">
<div class="wpwi_row">
<div>Time</div>
<div>8:02 PM</div>
</div>
<div class="wpwi_row">
<div>Date</div>
<div>13 Aug 2022</div>
</div>
<div class="wpwi_row">
<div>Pressure</div>
<div>999 hPa</div>
</div>
<div class="wpwi_row">
<div>Visibility</div>
<div>10000 Meter</div>
</div>
<div class="wpwi_row">
<div>Cloudiness</div>
<div>98%</div>
</div>
<div class="wpwi_row">
<div>Sunrise</div>
<div>5:37 AM</div>
</div>
<div class="wpwi_row">
<div>Sunset</div>
<div>6:39 PM</div>
</div>
</div>
</div>
I would like to keep two columns as close as possible without line break and center aligned when font size increase or decrease. I would like to keep like this image when font size is 28px https://i.stack.imgur.com/lYOzI.png and I would like to keep like this image when font size is 9px https://i.stack.imgur.com/89Jc3.png
You can try to unset width: 40% on .wpwi_inner and increase the width of .wpwi_row > div from 20% to 60%.
.wpwi_main {
border: 1px solid aliceblue;
border-radius: 5px;
font-size: 9px;
}
.wpwi_top {
text-align: center;
}
.wpwi_outer {
text-align: center;
margin: auto;
padding-bottom: 20px;
width: 100%;
}
.wpwi_inner {
display: table;
/* width: 40%; */ /* Removed this */
margin: auto;
}
.wpwi_row {
display: table-row;
width: 50%;
}
.wpwi_row > div {
display: table-cell;
width: 60%; /*Increase this width to 60%*/
}
<div class="wpwi_main">
<div class="wpwi_top">Top</div>
<div class="wpwi_outer">
<div>Outer</div>
</div>
<div class="wpwi_inner">
<div class="wpwi_row">
<div>Time</div>
<div>8:02 PM</div>
</div>
<div class="wpwi_row">
<div>Date</div>
<div>13 Aug 2022</div>
</div>
<div class="wpwi_row">
<div>Pressure</div>
<div>999 hPa</div>
</div>
<div class="wpwi_row">
<div>Visibility</div>
<div>10000 Meter</div>
</div>
<div class="wpwi_row">
<div>Cloudiness</div>
<div>98%</div>
</div>
<div class="wpwi_row">
<div>Sunrise</div>
<div>5:37 AM</div>
</div>
<div class="wpwi_row">
<div>Sunset</div>
<div>6:39 PM</div>
</div>
</div>
</div>
.circle{
padding:20px !important;
}
h2{
margin:unset;
}
.circle-text {
display: block;
margin: auto;
height: 120px;
width: 120px;
text-align: center;
vertical-align: middle;
border-radius: 50%;
background: #FF9800 ;
color: #fff;
font: 18px "josefin sans", arial;
line-height: 120px;
}
.a {
display: inline-block;
position: relative;
}
.a:before,
.a:after {
content: "";
position: absolute;
height: 60px;
border-bottom: 5px solid black;
top:0;
width: 293px;
}
.a:before {
right: 100%;
margin-right: 0px;
}
.a:after {
left: 100%;
margin-left:0px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/js/uikit-icons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/js/uikit.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/css/uikit.min.css" rel="stylesheet"/>
<div class="uk-section-align uk-margin-xlarge-top">
<div class="uk-container">
<div class="uk-text-center" uk-grid>
<div class="uk-width-1-3 circle">
<div class="circle-text ">
<i class="medium material-icons">Step 1</i>
</div>
<p class="center-align uk-margin-top">Choose Your Trip</p>
</div>
<div class="uk-width-1-3 ">
<div class="circle-text a">
<i class="medium material-icons">Step 2</i>
</div>
<p class="center-align uk-margin-top ">Request for reservation</p>
</div>
<div class="uk-width-1-3">
<div class="circle-text ">
<i class="medium material-icons">Step 3</i>
</div>
<p class="center-align uk-margin-top">Successfully</p>
</div>
</div>
</div>
</div>
I want to make responsive progress bar using pure css and uikit 3. This code i was written it works when it show in desktop mode . when i switching desktop mode to mobile mode , middle black line strike both circle. i just want to when it show in mobile mode also it only touch the circle.
please give some suggestion.
Try this
.circle{
padding:20px !important;
}
h2{
margin:unset;
}
.circle-text {
display: block;
margin: auto;
height: 120px;
width: 120px;
text-align: center;
vertical-align: middle;
border-radius: 50%;
background: #FF9800 ;
color: #fff;
font: 18px "josefin sans", arial;
line-height: 120px;
}
.a {
display: inline-block;
position: relative;
}
/*
.a:before,
.a:after {
content: "";
position: absolute;
height: 60px;
border-bottom: 5px solid black;
top:0;
width: 293px;
}
.a:before {
right: 100%;
margin-right: 0px;
}
.a:after {
left: 100%;
margin-left:0px;
}
*/
.uk-process-step {
position: relative;
}
.uk-process-step:before {
top: 60px;
bottom: 0;
position: absolute;
content: " ";
width: 100%;
height: 5px;
background-color: black;
}
.uk-process-step .uk-width-1-3 {
position: relative;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/js/uikit-icons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/js/uikit.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/css/uikit.min.css" rel="stylesheet"/>
<div class="uk-section-align uk-margin-xlarge-top">
<div class="uk-container">
<div class="uk-text-center uk-process-step" uk-grid>
<div class="uk-width-1-3 circle">
<div class="circle-text ">
<i class="medium material-icons">Step 1</i>
</div>
<p class="center-align uk-margin-top">Choose Your Trip</p>
</div>
<div class="uk-width-1-3 ">
<div class="circle-text a">
<i class="medium material-icons">Step 2</i>
</div>
<p class="center-align uk-margin-top ">Request for reservation</p>
</div>
<div class="uk-width-1-3">
<div class="circle-text ">
<i class="medium material-icons">Step 3</i>
</div>
<p class="center-align uk-margin-top">Successfully</p>
</div>
</div>
</div>
</div>
Use z-index for the pseudo elements (the black line).
Set it to -1 so that it will go beyond the circle.
Try this
.circle{
padding:20px !important;
}
h2{
margin:unset;
}
.circle-text {
display: block;
margin: auto;
height: 120px;
width: 120px;
text-align: center;
vertical-align: middle;
border-radius: 50%;
background: #FF9800 ;
color: #fff;
font: 18px "josefin sans", arial;
line-height: 120px;
}
.a {
display: inline-block;
position: relative;
}
.a:before,
.a:after {
content: "";
position: absolute;
height: 60px;
border-bottom: 5px solid black;
top:0;
width: 293px;
}
.a:before {
right: 100%;
margin-right: 0px;
z-index: -1;
}
.a:after {
left: 100%;
margin-left:0px;
z-index:-1
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/js/uikit-icons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/js/uikit.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-rc.25/css/uikit.min.css" rel="stylesheet"/>
<div class="uk-section-align uk-margin-xlarge-top">
<div class="uk-container">
<div class="uk-text-center" uk-grid>
<div class="uk-width-1-3 circle">
<div class="circle-text ">
<i class="medium material-icons">Step 1</i>
</div>
<p class="center-align uk-margin-top">Choose Your Trip</p>
</div>
<div class="uk-width-1-3 ">
<div class="circle-text a">
<i class="medium material-icons">Step 2</i>
</div>
<p class="center-align uk-margin-top ">Request for reservation</p>
</div>
<div class="uk-width-1-3">
<div class="circle-text ">
<i class="medium material-icons">Step 3</i>
</div>
<p class="center-align uk-margin-top">Successfully</p>
</div>
</div>
</div>
</div>
HTML:
<div>
<div id="Science" class="subjectsParent">
<div class="subject" draggable="true">
Science
</div>
<div class="subject" draggable="true">
Science
</div>
<div class="subject" draggable="true">
Science
</div>
</div>
<div id="Sports" class="subjectsParent">
<div class="subject" draggable="true">
Sports
</div>
<div class="subject" draggable="true">
Sports
</div>
<div class="subject" draggable="true">
Sports
</div>
</div>
<div id="Physics" class="subjectsParent">
<div class="subject" draggable="true">
Physics
</div>
<div class="subject" draggable="true">
Physics
</div>
<div class="subject" draggable="true">
Physics
</div>
</div>
</div>
CSS:
.subject {
display: block;
position: absolute;
background-color: green;
margin: 5px;
padding: 5px;
color: white;
}
.subjectsParent {
display: inline-block;
position: relative;
}
All the divs are collapsing altogether.
See here https://jsfiddle.net/a1quymqe/3/
What I want is only the same subjects should collapse together in there "subjectsParent" class.
Result I want:
(2 more same div behind these divs)
The solution is to give the last child position relative. This works no matter how many divs you use.
.subject {
display: block;
position: absolute;
background-color: green;
margin: 5px;
padding: 5px;
color: white;
}
.subject:last-child {
position: relative;
}
.subjectsParent {
display: inline-block;
}
https://jsfiddle.net/avvwa75h/1/
.subject {
display: block;
position: relative;
background-color: green;
margin: 5px;
padding: 5px;
color: white;
}
.subjectsParent {
display: inline-block;
position: relative;
}
//first two can be absolute
.subjectsParent .subject:first-child,.subjectsParent .subject:nth-child(2){
position: absolute;
}
working JSfiddle here
I want to keep the text block always on the first line, and if it needs multiple lines, then those lines should always get created beneath the first line of text.
The objective is that you only see dates on the left part of the page.
what is happening:
enter image description here
what should be happening:
enter image description here
/* Magic */
* {
margin: 0;
padding: 0;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
ul {
margin-left:20px;
}
/* MAIN STRUCTURE */
.page {
margin: 20px 20px 20px 20px;
font-size: 1.1rem;
}
#header {
width: 100%;
z-index: 1;
display: inline-block;
}
.section {
margin-top: 15px;
display: inline-block;
width: 100%;
}
/* Header */
#title {
float: left;
font-size: 1.3rem;
}
#meta {
float: right;
}
/* section */
.timeline_entry {
display: inline-block;
width: 100%;
margin-bottom: 1rem;
}
.entry {
display: inline-block;
width: 100%;
}
#identity {
}
#current {
}
#actions {
}
#stats {
}
#listing {
}
/* entry */
.element {
display: inline-block;
margin-right: 0.8rem;
}
.word {
display: inline-block;
}
#editing{
display: inline-block;
text-align: left;
float: right;
}
#proposal_status {
}
#proposal_text {
}
/* header */
#user_actions{
}
<div class="section" id="listing">
<div class="timeline_entry">
<div class="entry">
<div class="element">
<div class="word">2015-09-23</div>
<div class="word">#</div>
</div>
<div class="element">This is a long text which is going to the second line because its so big you know? more text, moarr</div>
</div>
<div class="entry">
<div class="element">
<div class="word">2015-09-23</div>
<div class="word">#</div>
</div>
<div class="element">Achieved</div>
<div class="element">Talk (5)</div>
<div class="element">
<div class="word">Category</div>
<div class="word">Category</div>
</div>
</div>
</div>
<div class="timeline_entry">
<div class="entry">
<div class="element">
<div class="word">2015-09-23</div>
<div class="word">#</div>
</div>
<div class="element">This text stays where it should</div>
</div>
<div class="entry">
<div class="element">
<div class="word">2015-09-23</div>
<div class="word">#</div>
</div>
<div class="element">Achieved</div>
<div class="element">Talk (5)</div>
<div class="element">
<div class="word">Category</div>
<div class="word">Category</div>
</div>
</div>
</div>
</div>
you could try playing around with HTMLs much underloved "Deffinition List" <dl>
Alternatively, here's a table-like layout:
.list-group {
display:table;
width:100%;
max-width:500px;
}
.item {
display:table-row;
}
.date {
display:table-cell;
width:30%;
padding:10px;
vertical-align:top;
text-align:right;
}
.dates {
display:table-cell;
width:70%;
padding:10px;
vertical-align:top;
}
<div class="list-group">
<div class="item">
<div class="date">2015 09 14</div>
<div class="dates">2013123 2013123 2013123 2013123 2013123 2013123 2013123</div>
</div>
<div class="item">
<div class="date">2015 09 14</div>
<div class="dates">2013123 2013123 2013123 2013123 2013123 2013123 2013123</div>
</div>
<div class="item">
<div class="date">2015 09 14</div>
<div class="dates">2013123 2013123 2013123 2013123 2013123 2013123 2013123</div>
</div>
<div class="item">
<div class="date">2015 09 14</div>
<div class="dates">2013123 2013123 2013123 2013123 2013123 2013123 2013123</div>
</div>
</div>
I was hoping to comment but I don't have enough rep points to do so, but would the below work?
JSFiddle: https://jsfiddle.net/4r295p0q/2/
This won't work if your class assignments aren't flexible because I changed the classes of the two DIV's with the text from .element (red border) to .post (blue border). From there, I gave the new .post class an pre-determined width percentage and float: right.