Here I want to align this inside circle at the left border. As shown in the image by orange lines.
Here is my HTML code for this
<section style="height: 300px;border: 2px solid green;">
<ul id="Name_Section">
<li style=" border: 2px solid blue;">I AM PRAVEEN KUMAR </li>
<li id="logo"></li>
</ul>
</section>
Below is the CSS for this.
Ignore the extra code if there it is.
#Name_Section{
display: flex;
justify-content: space-around;
padding: 30px;
}
#Name_Section li{
list-style: none;
padding: 10px;
font-weight: bold;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
#logo{
outline: 1px solid rgb(255, 255, 255);
outline-offset: 15px;
background-color: rgb(38, 38, 54);
height: 120px;
width: 120px;
border-radius: 70px;
}
You only need two container for you to reproduce the effect you desire, basically the outer container should have a white border, the inside container containing the text should have a smaller dimension than the outer container. In my example there's a 2em height and width difference to achieve the effect. Both then sould have display: flex;, align-items and justify-content set to center, to align the items inside of them to the center. See the snippet below for your reference.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
section {
height: 300px;
border: 2px solid green;
background: #4A495B;
}
#Name_Section {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.outside {
display: flex;
justify-content: center;
align-items: center;
border: 1px solid grey;
border-radius: 50%;
height: 12em;
width: 12em;
}
.inside{
background: #272636;
color: #fff;
border-radius: 50%;
height: 10em;
width: 10em;
font-weight: bold;
font-family: Verdana, Geneva, Tahoma, sans-serif;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
<section>
<ul id="Name_Section">
<li class="outside">
<p class="inside">I AM PRAVEEN KUMAR </p>
</li>
</ul>
</section>
place the element inside a parent div that own the size, the padding and the border
the parent have a relative position
the logo have an absolute position
you can now move the child where you want in the parent with properties top, bottom, left or right
#logo{
background-color: rgb(38, 38, 54);
border-radius: 70px;
height: calc(100% - 14px);
width: calc(100% - 14px);
position: absolute;
right:0;
top:7px; //the midle of the parent padding
}
.element-border {
position:relative;
border: solid grey 1px;
border-radius: 70px;
padding: 14px;
height: 120px;
width: 120px;
}
<div class="element-border">
<div id="logo"></div>
</div>
Related
I am trying to display numbers in circle which is number over total numbers for example 90/100.
Like this:
I tried like this but need small help because Circle is breaking up.
.kanban-circle{
border-radius: 50%;
width: 36px;
height: 36px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
}
<span class="kanban-circle">
<u>90</u>
<br></br>
100
</span>
Here it is, if you like more space between the number and the horizontal line, change the css for .line like { margin: 5px 0; }
.kanban-circle {
border-radius: 50%;
width: 36px;
height: 36px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
display: flex;
flex-direction: column;
}
.line {
padding: 0;
margin: 0;
width: 100%
}
span {
font-size: 15px;
}
<div class="kanban-circle">
<span>90</span>
<hr class="line" />
<span>100
</span></div>
The problem is with the <br> tag. I don't really know why, but through this tag, the lower number is not seen as part of the circle and the border is not drawn around it.
I experimented a little bit and came to following solution with following code:
.kanban-circle{
border-radius: 50%;
background-color: coral;
width: 70px;
height: 70px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
}
<div class="kanban-circle">
<div>
<u>90</u>
110
</div>
</div>
I replaced span with div, but the result should be the same.
here the solution with also the comments, if you want to read it.
I make it responsive to the width, just change the width of parent element, and automatically change all the things inside!
the first 2 lines of CSS are css variables
--width: 3rem;
--color: #666;
Change their value, and all the elements will be changed automatically, and be show always good.
if you want to also be more responsive, you can use some new CSS units in --width: like vw, vh, %, etc... this is relative to something (parent elements, or viewport width, etc...)
so for responsive layout try to not use (avoid) absolute units like cm, px, in, pt. details: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units
in html I used <hr> instead of <br>
#container {
--width: 3rem;
--color: #666;
/* same height, same width */
width: var(--width);
height: var(--width);
/* responsive padding that is relative to the container width*/
padding: calc(var(--width) / 5);
/* always perfect circle */
border-radius: var(--width);
/* centering */
display: grid;
place-items: center;
/* coloring with the same color */
border: 2px solid var(--color);
color: var(--color);
/* font responsive to parent container */
font-size: calc(var(--width) / 3)
}
#container hr {
/* responsive width */
width: 100%;
/* removing a little bug if we use GRID */
margin: 0;
}
<div id="container">
<span>97</span>
<hr>
<span>100</span>
</div>
You could do it as below. Feel free to adjust it to your need.
.kanban-circle {
border-radius: 50%;
width: 86px;
height: 86px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
font: 32px Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.kanban-circle hr {
width: 100%;
margin:0;
border: 1px solid #666;
}
<span class="kanban-circle">
<span>90</span>
<hr/>
<span>100</span>
</span>
I have a flex-box with direction set to row containing two divs. The div on the left has a single image while that on the right serves as a container for two sub divs set to column, each containing an image.
I am trying to position the captions midway directly onto the images, but where there is a change in screen size, the captions are left behind floating in the space of the viewport.
I have tried to position the captions absolutely on their corresponding images whiles setting their positions with respect to their containers. However, the dimensions I set rather correspond to the whole viewport and not their containers.
Help!
<div id="container">
<div id="large">
<img class="img-large" src="large.jpg">
<div id="caption-span-large">
<h3 class="caption">The Dark Playground</h3>
</div>
</div>
<div id="small-frame">
<div class="small"><img class="img-small" src="small1.png">
<div class="caption-span-small1">
<h3 class="caption">The Red Night Jedi Camp</h3>
</div>
</div>
<div class="small"><img class="img-small" src="small2.png">
<div class="caption-span-small2">
<h3 class="caption">The Red Night Jedi Camp</h3>
</div>
</div>
</div>
</div>
#container{
display: flex;
width: 50%;
}
#large{
border-radius: 5px;
height: 400px;
width: 50%;
border: lawngreen solid 2px;
position: relative;
display: inline-block;
}
#small-frame{
display: flex;
flex-direction: column;
width: 50%;
border: lawngreen solid 2px;
}
.small{
border-radius: 5px;
height: 200px;
border: green solid 2px;
}
#caption-span-large{
background-color: rgba(224, 83, 101, 0.63);
border-radius: 10px;
position: absolute;
top: 50%;
left: 25%;
}
.caption-span-small1{
background-color: rgba(224, 83, 101, 0.63);
border-radius: 10px;
position: absolute;
top: 50%;
left: 50%;
}
.caption-span-small2{
background-color: rgba(224, 83, 101, 0.63);
border-radius: 10px;
position: absolute;
}
.caption{
color: honeydew;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 15px;
background-color: rgba(224, 83, 101, 0.63);
border-radius: 10px;
position: absolute;
top: 200px;
left: 120px;
}
.img-large{
height: 400px;
max-width: 100%;
}
.img-small{
height: 200px;
max-width: 100%;
}
The position property set to absolute works relative to the closest parent element that has position: relative. If there is no such element, then positioning is relative to the top-left corner of the page. Since in your code position: relative is specified only for the #large block, the layout falls apart.
Therefore, for .small blocks, you also need to set position: relative.
If I understood the task correctly, then the code will be as follows (run the snippet, expand the snippet and resize the block by grabbing it by the lower right corner):
#container {
display: flex;
height: 400px;
width: 50%;
/* Only for demo */
overflow: hidden;
resize: both;
}
#large {
position: relative;
width: 50%;
border: lawngreen solid 2px;
border-radius: 5px;
}
#small-frame {
display: flex;
flex-direction: column;
width: 50%;
border: lawngreen solid 2px;
}
.small {
position: relative;
height: 50%;
border: green solid 2px;
border-radius: 5px;
}
#caption-span-large,
.caption-span-small {
position: absolute;
top: 50%;
left: 50%;
border-radius: 10px;
transform: translate(-50%, -50%);
background-color: rgba(224, 83, 101, 0.63);
}
.caption {
display: inline-block;
border-radius: 10px;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 15px;
text-align: center;
color: honeydew;
background-color: rgba(224, 83, 101, 0.63);
}
.img-large {
height: 400px;
max-width: 100%;
}
.img-small {
height: 200px;
max-width: 100%;
}
<div id="container">
<div id="large">
<img class="img-large" src="large.jpg">
<div id="caption-span-large">
<h3 class="caption">The Dark Playground</h3>
</div>
</div>
<div id="small-frame">
<div class="small">
<img class="img-small" src="small1.png">
<div class="caption-span-small">
<h3 class="caption">The Red Night Jedi Camp</h3>
</div>
</div>
<div class="small">
<img class="img-small" src="small2.png">
<div class="caption-span-small">
<h3 class="caption">The Red Night Jedi Camp</h3>
</div>
</div>
</div>
</div>
It creates exactly what I need but I cannot center to whole element on the page. centering will only center the text within the background colored area. What am I doing wrong?
I tried many different code combination but cannot make this work.
GROW YOUR BUSINESS WITH US
<h1 style="display: inline-block; text-align: center; background-color: #273b86; color: #ffffff; padding: 5px; border-radius: 5px; width: 640px;">GROW YOUR BUSINESS WITH US</h1>
I would like whole element above to be centered on the page.
You also could just change the display attr to block and add margin:auto to it!
I placed it into a div with 1000px width for you to view, but you just need the h1
<div style="width:1000px;">
<h1 style="display: block; text-align: center; background-color: #273b86; color: #ffffff; padding: 5px; border-radius: 5px; width: 640px; margin:auto;">GROW YOUR BUSINESS WITH US</h1>
</div>
You can add div around H1 and add width and margin:auto like
<div style="width:650px; margin: auto;"><h1 style="display: inline-block; text-align: center; background-color: #273b86; color: #ffffff; padding: 5px; border-radius: 5px; width: 640px; ">GROW YOUR BUSINESS WITH US</h1><div>
Or like Huangism do
<h1 style="text-align: center; background-color: #273b86; color: #ffffff; padding: 5px; border-radius: 5px; width: 640px; margin: auto;">GROW YOUR BUSINESS WITH US</h1>
here is an example
.container{
width: 100%;
height: 100%;
border: 1px red solid;
display: inline-block;
height: 90vw;
}
.container > div{
width: 150px; /* very impotent */
margin:auto;/* center position */
border:1px #CCC solid;
text-align:center;
}
<div class="container">
<div> center div </div>
</div>
I have a div called insidenextcontent2.
This is just a div that colors a section.
In this div I have another div called bottle1, which is a geometrical shape(supposed to be the top of a bottle).
Also, I have a paragraph which I want to position besides this geometrical shape. However, the paragraph is placed below the whole div(insidecontent).
How can I fix this? I want the text to be inside the outer div, besides the inner div.
.insidenextcontent2 {
margin-top: 10%;
width: 100%;
height: 15%;
background: #EEFA0F;
}
.bottle1 {
margin-left: 30%;
border-top: 97px solid black;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
height: 0;
width: 150px;
}
#webpara {
color: black;
margin-left: 50%;
font-family: 'Fjalla One', sans-serif;
}
<div class="insidenextcontent2">
<div class="bottle1"></div>
<p id="webpara">Web & app development</p>
</div>
place your paragraph in a div alongside the bottle div.
add display: flex to your containing div.
https://jsfiddle.net/m08paL1d/2/
<div class="insidenextcontent2">
<div class="bottle1"> </div>
<div>
<p id="webpara">Web app development</p>
</div>
</div>
CSS:
.insidenextcontent2 {
margin-top: 10%;
width: 100%;
height: 15%;
background: #EEFA0F;
display: flex;
}
.bottle1 {
margin-left: 30%;
border-top: 97px solid black;
border-left: 35px solid transparent;
border-right: 35px solid transparent;
height: 0;
width: 150px;
}
#webpara {
color: black;
margin-left: 50%;
font-family: 'Fjalla One', sans-serif;
}
I am having truble with the css for an image inside figure. This is the html:
#content figure {
display: inline-block;
border: 1px solid #333333;
height: 200px;
margin: 10px;
}
#content img {
height: 180px;
background-size: auto 100%;
background-repeat: no-repeat;
background-position: center center;
border: 1px solid red;
margin: 0px;
margin-bottom: -5px;
}
#content figcaption {
border: 1px solid blue;
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
text-shadow: none;
color: black;
text-align: center;
height: 20px;
}
<div id="content">
<figure>
<img style="background-image: url('http://placehold.it/300x300');"></img>
<figcaption>image caption that is to long to fit</figcaption>
</figure>
<!--... /*Here it can be multiple figure after each other*/-->
</div>
What I want is that the figure should have a fixed height at 200px. The figcaption should have an automatic height depending on how many rows of text there is. The image should then take up the rest of the height and scale the width to keep the proportions. The width of the figure should therefore be the same width as the image inside it. The code I have now is not doing everything and I do not understand how I should modify it to do what I want.
In your #content figcaption style add word-wrap: break-word;, set height: auto; and give it the same width as your image, so something like this:
#content figcaption {
border: 1px solid blue;
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
text-shadow: none;
color: black;
text-align: center;
height: auto;
word-wrap: break-word;
width:300px;
}
#content figure {
display: inline-block;
border: 1px solid #333333;
height: 200px;
margin: 10px;
}
#content img {
height: 180px;
background-size: auto 100%;
background-repeat: no-repeat;
background-position: center center;
border: 1px solid red;
margin: 0px;
margin-bottom: -5px;
}
#content figcaption {
border: 1px solid blue;
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
text-shadow: none;
color: black;
text-align: center;
height: auto;
word-wrap: break-word;
width:300px;
}
<div id="content">
<figure>
<img style="background-image: url('https://i.stack.imgur.com/8z6RE.jpg?s=48&g=1');"/>
<figcaption>image caption that is to long to fit</figcaption>
</figure>
<!--... /*Here it can be multiple figure after each other*/-->
</div>
I don't see a way to dynamically adjust the height of your image to accommodate the figcaption(since your figcaption have varied height as per content).
An alternative is to use the image to use the whole figure height and add figcaption on top of the figure using position.
Here is the FIDDLE