How to connect line to two borders html/css - html

Good morning guys. I just want to know how to do this in html and css. :)
I've done this so far in my website.
I've been working for this for days but I can't find an exact way to do it that way.
This is my html code:
<div class="container">
<div class="col-md-2 col-md-offset-1"><img class="img-circle img-left" style="border: 5px solid #0766dc;" src="1.png"></div>
<div class="col-md-2" id="gradient1"></div>
<div class="col-md-2"><img class="img-circle img-center" style="border: 5px solid #00afdc;" src="2.png"></div>
<div class="col-md-2" id="gradient2"></div>
<div class="col-md-2"><img class="img-circle img-right" style="border: 5px solid #28ddb3;" src="3.png"></div>
</div>
and this is my css:
#gradient1 {
display: block;
background: linear-gradient(to right, #0766dc, #00afdc);
height: 5px;
margin-top: 100px;
}
#gradient2 {
display: block;
background: linear-gradient(to right, #00afdc, #28ddb3);
height: 5px;
margin-top: 100px;
}
.img-center {
margin: auto;
}
.img-right {
margin-right: auto;
}
.img-left {
margin-left: auto;
}
.img-circle {
display: block;
padding: 10px;
border-radius: 50%;
width: 200px;
height: 200px;
}

This is a simple code that works. You will have to resize the elements to your desired size, recolor, etc.
<div style='height:60px; position:relative; width:60px; border:1px solid black; border-radius:60px; vertical-align:middle; text-align:center; float:left; '><p style='position:absolute; margin:0px; padding:0px; top:50%; left:50%; transform: translate(-50%, -50%);'>Hi</p></div>
<div style='height:30px; width:50px; border-bottom:1px solid black; float:left'></div></div>
<div style='height:60px; position:relative; width:60px; border:1px solid black; border-radius:60px; vertical-align:middle; text-align:center; float:left; '><p style='position:absolute; margin:0px; padding:0px; top:50%; left:50%; transform: translate(-50%, -50%);'>Hi # 2</p></div>
<div style='height:30px; width:50px; border-bottom:1px solid black; float:left'></div></div>
<div style='height:60px; position:relative; width:60px; border:1px solid black; border-radius:60px; vertical-align:middle; text-align:center; float:left; '><p style='position:absolute; margin:0px; padding:0px; top:50%; left:50%; transform: translate(-50%, -50%);'>Hi # 3</p></div>
When resizing, make sure that you make the border radius the same as your height and width size. Note that the line div height is half the circle div height.

Your code when I run it does not look like the picture provided. The lines are almost halfway inside the circle to their left.
You can try something like this:
<div class="circle"></div><div class="line"></div><div class="circle"></div>
.circle {
height: 100px;
width: 100px;
border: 4px solid black;
border-radius: 50%;
display: inline-block;
box-sizing: content-box;
}
.line {
display: inline-block;
border-top: 4px solid black;
width: 100px;
height: 50px;
box-sizing: content-box;
}
Make sure you have no spaces between html inline or inline-block elements.
Add circles and change the sizes, colors, etc. at will. You'll probably want to wrap it all in a div with a minimum width so that the elements don't wrap when the screen gets small.

You were so close! :) But for custom things like this bootstrap is very unflexible, so sometimes you have to overwrite some properties.
So, problem is that bootstrap sets a padding on it's elements, that is the reason of the space between your circles:
To solve this issue just make a new class:
<div class="col-md-2 outer">
And apply the style like this:
.outer {
padding:0;
}
Another problem I see in your code is that you set the image width and height manually. But the divs with the class col-md-2 adjust their size depending on the screen size. So resizing can result in overlapping.
So you have to think about, if you set also the width / height of .outer to static values. To prevent this you can at least set the min-height and min-width of the div that have the circle inside.
Check out the solution on jsfiddle:
https://jsfiddle.net/w58L7ojL/ (zoom out to see it working)

Related

div with some sections using fix width

I want to achieve a layout like below using fix width. The width should be 600px and then I want to have some sections in the main div. And I want that the main div is aligned at the center of the page.
Im a CSS beginner and Im not achieving this result, I have a fiddle with the issues: fiddle
Its not aligned at the center of the page and also only the div .post-title is appearing properly.
Do you know what is necessary to achieve the image layout?
<div class="wrapper">
<div class="post-title">
title
</div>
<div class="post-info">
<div class="post-date">
date
</div>
<div class="post-admin">
admin
</div>
</div>
<div class="post-category">
category
</div>
<div class="post-tags">
tags
</div>
</div>
I updated your fiddle.
Here is the CSS in case it didn't work. Using flexbox.
.wrapper{
width: 600px;
display:block;
margin: auto;
border:1px solid gray;
text-align:center;
}
.post-title{
border-bottom: 1px solid gray;
padding:20px;
text-align:left;
}
.post-info{
width:100%;
display: flex;
height: 100px;
}
.post-date{
border-right:1px solid gray;
padding: 20px;
flex: 1;
box-sizing:border-box;
text-align: left;
}
.post-admin{
padding:20px;
box-sizing:border-box;
text-align: left;
flex: 1;
}
.post-category{
border-top:1px solid gray;
text-align: left;
padding:10px;
}
.post-tags{
border-top:1px solid gray;
text-align: left;
padding:10px;
}
You don't need to float everything, in fact it makes it very difficult to handle elements under your box because the floats get ripped from the document flow. Also the parent container no longer recognizes the size of the elements. You could instead use flexbox for the two elements next to each other, but for better compatibility you can also just make them inline-block.
I would wrap everything in another block (possibly just the body body if that works for you) with width: 100%; (or at least something larger than 600px) and then use margin: 0 auto; (0 top and bottom, auto left and right). I used inline-block for the date and admin blocks. Also not that you must remove the whitespace between them (I used an html comment) so they don't break.
body {
width: 100%;
}
.wrapper{
width: 600px;
display:block;
border:1px solid gray;
text-align:center;
margin: 0 auto;
}
.post-title{
border-bottom: 1px solid gray;
padding:20px;
text-align:center;
}
.post-info{
width:100%;
}
.post-date{
border-right:1px solid gray;
padding: 20px;
width:50%;
box-sizing:border-box;
display: inline-block;
}
.post-admin{
padding:20px;
width:50%;
box-sizing:border-box;
display: inline-block;
}
.post-category{
padding:10px;
box-sizing:border-box;
border-top: 1px solid grey;
}
.post-tags{
padding:10px;
box-sizing:border-box;
border-top: 1px solid grey;
}
<body>
<div class="wrapper">
<div class="post-title">
title
</div>
<div class="post-info">
<div class="post-date">
date
</div><!--
--><div class="post-admin">
admin
</div>
</div>
<div class="post-category">
category
</div>
<div class="post-tags">
tags
</div>
</div>
</body>

create corner arc with css

How would you create such corner arc using css?
This is starter template: https://codepen.io/anon/pen/rwraXG
I was hoping that I would be able to use black outer div and red inner div, and use border radius to leave just the top left corner showing through. I messed something midway.
.bar {
width: 100px;
height: 20px;
background-color: red;
}
.outer {
height: 100%;
width: 8px;
background-color: black;
}
.inner {
height: 100%;
width: 100%;
background-color: red;
border: 2px solid black;
border-radius: 15px 0px 0px 0px:
}
<div class="bar">
<div class="outer">
<div class="inner"></div>
</div>
</div>
Modified your codepen: https://codepen.io/anon/pen/dRjoow
Essentially, it was a syntax error. You had a colon (:) at the end of your border-radius property like this:
.inner{
...
border-radius: 15px 0px 0px 0px:
}
instead of a semi colon (;) like this:
.inner{
...
border-radius: 15px 0px 0px 0px;
}
so it wasn't rendering.
fiddle: https://jsfiddle.net/m8wf66u6/
HTML:
<div class="outer">
<div class="inner">
</div>
</div>
CSS:
.outer {
height: 200px;
width: 400px;
background-color: black;
}
.inner {
height: 100%;
width: 100%;
background-color: red;
border-top-left-radius: 20px;
}
The only problem is the : at the end of the last line.
border-radius: 15px 0px 0px 0px;
Note that you can also use :
border-top-left-radius: 15px;
I suggest you to do it with 2 DIVs as below:
HTML :
<div class="outer">
<div class="inner"></div>
</div>
CSS :
.outer,.inner{
width:200px;
height:80px;
}
.outer {
background-color:black;
}
.inner {
background-color:red;
border-radius:20px 0 0 0; /* numbers are : top left bottom right*/
}
https://codepen.io/FaridNaderi/pen/pwZJyP
Hope it helps
It is possible to do this with the inner and outer boxes as you have. You would change your css to the below. You don't need to declare the color red on '.bar' because your '.inner' div will be the red portion of this.
.bar{
width:200px;
height:100px;
}
.outer{
height:100%;
width:100%;
background-color:black;
}
.inner{
height:100%;
width:100%;
background-color:red;
border-radius: 20px 0 0 0;
}
As long as your parent div ('.bar') has a set width and height '.inner' and '.outer' can have width and heights of 100%.
*Please note though that the higher you make '.bar' the better the top left tab will look.

Box position not centering

Im trying to center a box 200 by 200. I have tried using left:50% top:50% etc., but this is somehow not really working.
I created a fiddle to recreate my problem: https://jsfiddle.net/8k9o9Lvv/2/
I also tried to center the text from the top as well, with text-align:center and this is also not working.
Any ideas why this is not working?
HTML
<div id ="container">
<div class="slider-text">
<h2>Test</h2>
</div>
</div>
CSS
#container{
width:100%;
}
.slider-text {
text-align:center;
position:relative;
height:200px;
width: 200px;
border-left:1px solid red;
border-right:1px solid red;
border-top:1px solid red;
border-bottom:1px solid red;
top:50%;
left:50%;
right:50%;
}
Just margin:0px auto; is enough
#container {
width: 100%;
}
.slider-text {
text-align: center;
margin:0px auto;
height: 200px;
width: 200px;
border-left: 1px solid red;
border-right: 1px solid red;
border-top: 1px solid red;
border-bottom: 1px solid red;
}
<div id="container">
<div class="slider-text">
<h2>Test
</h2>
</div>
</div>
Give the below code a try, centering the #container div horizontally, and the .slider-text div horizontally and vertically within #container.
#container{
width:100%;
}
.slider-text {
text-align:center;
position:relative;
height:200px;
width: 200px;
border:1px solid red; /* Creates a border around entire element */
margin: auto; /* Centers horizontally */
}
/* This is to center the text vertically within its parent, */
/* remove it if you don't want to do that */
.slider-text h2 {
text-align:center;
position: absolute; /* position: relative; works too */
width: 100%;
top: 30%;
left: 0%;
}
<div id ="container">
<div class="slider-text">
<h2>Test</h2>
</div>
</div>
Let me know if it helps.
* {
margin: 0;
padding: 0;
}
#container{
position:relative;
width:100%;
height: 100vh;
}
.slider-text {
position: absolute;
text-align:center;
height:200px;
width: 200px;
border-left:1px solid red;
border-right:1px solid red;
border-top:1px solid red;
border-bottom:1px solid red;
top:50%;
left:50%;
transform: translateX(-50%) translateY(-50%);
right:50%;
display: flex;
align-items: center;
justify-content: center;
}
<div id ="container">
<div class="slider-text">
<h2>Test</h2>
</div>
</div>
You need to set the height of the container. In this case I used 100vh which is equal to 1 viewport height. transform: translateX(-50%) translateY(-50%); with top: 50%; left: 50% will make your .slider-text on center.
To center your text. You can use flexbox. Using display: flex will enable you to use align-items and justify-content. With value of center, it will allow your text to flow on center of its parent.
Your HTML
<div id ="container">
<div class="slider-text">
<h2>Test</h2>
</div>
</div>
Modified CSS
#container{
width:100%;
}
.slider-text {
position:relative;
height:200px;
width: 200px;
border:1px solid red;
margin: 0 auto;
}
.slider-text h2 {
width: 100%;
text-align: center;
}
#container{
width:100%;
position: relative;
}
.slider-text {
text-align:center;
height:200px;
width: 200px;
border-left:1px solid red;
border-right:1px solid red;
border-top:1px solid red;
border-bottom:1px solid red;
position: relative;
}
/*since slider-text has a fixed height and width, a simple math would do*/
.slider-text h2 {
margin-top: 90px;
}
<div id ="container">
<div class="slider-text"><h2>Test
</h2></div>
</div>
Just a simple calculation would do
You should set height:100% to all elements down to your container. That means:
html, body, #container
{
height:100%;
}
Then to center horizontaly and verically a known-size div inside your #container, you just need to set for that div:
left:50%;
top:50%;
and
margin-left:(MINUS whatever is the half of your div width)
margin-top:(MINUS whatever is the half of your div height)
UPDATED FIDDLE (sorry forgot to "update" it)
edit: i assumed you want to center it to the whole screen.
Assuming you want to center it both X and Y, you're right so far, however there are a few changes. Use this for your .slider-text class:
.slider-text {
text-align:center;
position:absolute; /* Relative was wrong */
height:200px;
width: 200px;
border-left:1px solid red;
border-right:1px solid red;
border-top:1px solid red;
border-bottom:1px solid red;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
Relative positioning was incorrect in this instance. absolute is correct. Relative would make it move X amount of pixels from its natural position, whereas absolute will position it in a specific place, relative to the closest parent with position: relative on it.
The transform basically does the same as negative margins, but you don't need to change the margin if the size of the box changes :)
Let me know if you have any questions.
Here is the css code:
.slider-text {
text-align:center;
position:absolute;
height:200px;
width: 200px;
border-left:1px solid red;
border-right:1px solid red;
border-top:1px solid red;
border-bottom:1px solid red;
top:50%;
left:50%;
margin-left:-100px;
margin-top:-100px;
}
margin-left:-(div width)/2;
margin-top:-(div height)/2;

How to make a box with borders cutting at some points

I'm working on a practice project and I'm facing a problem. There is a border box with the border cut off near the text and the button. I shall appreciate it if you people can tell me how to make a box like that. I tried several methods but they were not good at different viewports.
Take a look. Workinglink
HTML:
<div>
<h1>Title</h1>
</div>
CSS:
div{
height:100px;
width:100px;
border:2px solid black;
}
h1{
width:30px;
margin-top:-10px;
margin-left:5px;
background:white;
}
Here is one way you can do it.
Using "margin" in CSS you can do it.
<div class="back-box">
<div class="second-box">
<div class="text-box">
<h2>
My Text here
</h2>
</div>
</div>
</div>
CSS
.back-box{ background-color: black; width: 500px; height: 200px; padding: 50px }
.second-box { border: 1px solid white; width: 500px; height: 200px }
.text-box{ background-color: black; margin-top:-30px; width:200px; margin-left:auto; margin-right:auto; text-align: center }
h2 { color: white; }

min-width and max-width issues. How to get inner content to grow with width

I have a three column site that will display all three columns or just one. If it displays just one column, my example below is the column it will be displaying. This intro wrapper is the center column that needs to grow in the event that the columns to the left and right of this wrapper are not present. Specifically, the first div in the intro wrapper. The second div has a static image in it and should not change.
I've used min/max-width but the content never reaches the maximum but rather stays at the minimum.
.intro is the wrapper. The min-width for this wrapper should be 801px and can grow up to a max of 1200px. The first inner div (.intro-left) should be a minimum of 531px and can grow up to a maximum of 979px.
Can someone have a look and tell me where I'm going wrong?
Here is my code.
.intro{
float:left;
min-height:200px;
width:801px;
padding:10px 0;
}
.intro .intro-right{
display:inline;
float:left;
height:200px;
width:250px;
background:#ccc;
}
.intro .intro-right img{
height:190px;
width:240px;
margin:5px 0 0 5px;
border:1px solid #777;
}
.intro .intro-left{
display:inline;
float:left;
width:531px;
min-height:200px;
margin-right:20px;
}
<div class="intro">
<div class="intro-left">
<h2>Test</h2>
<p>test</p>
</div>
<div class="intro-right">
<img alt="" src="1.jpg">
</div>
</div>
display:table solves your issue,. here is the CSS, ive made some changes while testing that you may want to remove.. such as making the left div resizeable so that you can see it work in action.
div.intro {border:2px dotted red;
min-height: 200px;
max-width:1200px;
min-width:801px;
padding: 10px 0;
margin:0 auto;
display:table;
}
.intro-right, .intro-left{display:inline-block;vertical-align:top;}
.intro-right {
height: 200px;
width: 250px;
background: #ccc;
outline: 2px solid green;
}
.intro-right img {
height: 190px;
width: 240px;
margin: 5px 0 0 5px;
border: 1px solid #777;
}
.intro-left {
width: 531px;
height: 200px;
margin-right: 20px;
outline: 2px solid blue;
resize:both;
overflow:auto;
}