3 div's in a container [duplicate] - html

This question already has answers here:
heading with horizontal line on either side [duplicate]
(3 answers)
Closed 5 years ago.
First I have to say, I didn't find any answer to this. If it's a duplicate, please forgive me and point me correct.
I'm trying to create a div with three divs inside. The center div should have text, and the side divs should have a vertically centered line, like this:
This is the code I have so far:
HTML:
<div className="container">
<div class="line"><hr/></div>
<div class="text">My Text</div>
<div class="line"><hr/></div>
</div>
CSS:
.container {
.text {
font-size: 16px;
text-transform: uppercase;
color: red;
display: inline-block;
}
.line {
display: inline-block;
}
}
My problem is that I don't see the lines at all, my text is positioned to the left. I tried margin: auto; but that didn't help me. Can someone plese help?
I have one prerequisite, I can't use flexboxes.

You could approach this layout using pseudoelements instead of hr.
Example:
.container {
text-align: center;
position: relative;
}
.container:before {
content: '';
position: absolute;
left: 0;
right: 0;
height: 2px;
background: grey;
top: 50%;
transform: translateY(-50%);
}
.text {
font-size: 16px;
text-transform: uppercase;
color: red;
margin: 0 auto;
display: inline-block;
background: white;
position: relative;
/* add left and right padding if needed */
padding: 0 1em;
}
<div class="container">
<div class="text">My Text</div>
</div>

Related

Why are two divs with display set to inline-block not vertically aligned? [duplicate]

This question already has answers here:
CSS align images and text on same line
(9 answers)
Vertically align text next to an image?
(26 answers)
Closed 6 months ago.
I have 2 divs within a parent div. Each has display set to inline-block;. However they are not vertically aligned. I would expect that either their tops or bottoms are aligned. Why does this occur? and How to get them aligned?
.image {
display: inline-block;
border: grey 1px solid;
}
.name {
display: inline-block;
margin-left: 4px;
border: grey 1px solid;
height: 24px;
line-height: 24px;
}
<div class=icon>
<div class=image>
<img src="https://via.placeholder.com/48" width="24px" height="24px">
</div>
<div class=name>Name field</div>
</div>
Both images and text have whitespace allowances for descenders, being inline content. They happen to not be the same size.
A modern solution is flexbox.
.icon {
display: flex;
align-items: center; /* or 'start' (top), or 'end' (bottom) */
background: pink; /* for demo only */
padding: 8px; /* for demo only */
}
.image {
border: grey 1px solid;
font-size: 0; /* one way to eliminate descender space on images */
}
.name {
margin-left: 4px;
border: grey 1px solid;
height: 24px;
line-height: 24px;
}
<div class=icon>
<div class=image>
<img src="https://via.placeholder.com/48" width="24px" height="24px">
</div>
<div class=name>Name field</div>
</div>
You can try this position relative with position absolute check this
.icon {
position: relative;
}
.image {
position: absolute;
top: 0;
left: 0;
}
.name {
position: absolute;
top: 0;
left: 30px;
background-color: blue;
height: 24px;
line-height: 24px;
}
<div class=icon>
<div class=image>
<img src="https://via.placeholder.com/48" width="24px" height="24px">
</div>
<div class=name>Name field</div>
</div>

Center a div element without ruining inline blocks [duplicate]

This question already has answers here:
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
How can I vertically align elements in a div?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed last year.
I have 3 small divs contained in a larger div all inline. I want to make the middle div vertically centered because it is a dash in between two words. When the user hovers over them, the line expands for an animation so it is important that the divs have relative position so the last word can get "pushed"
<div id = "con">
<div class = "a">01</div>
<div id = test></div> //This is the line to be centered
<div class = "a">Projects</div>
</div>
.a {
display: inline-block;
color: #AAAAAA;
}
html {
background: #222222;
}
#test {
width: 30px;
height: 1px;
display: inline-block;
background-color: #AAAAAA;
border-radius: 1px;
}
#con {
position: relative;
}
display: inline-flex, and align-items: center on the container solves your problem.
To better learn how to use flexbox display, check out flexbox froggy.
.a {
color: #AAAAAA;
}
html {
background: #222222;
}
#test {
width: 30px;
height: 1px;
background-color: #AAAAAA;
border-radius: 1px;
}
#con {
position: relative;
display: inline-flex;
align-items: center;
}
<div id="con">
<div class="a">01</div>
<div id="test"></div>
<div class="a">Projects</div>
</div>
Can use from margin-bottom & transition:
.a {
display: inline-block;
color: #AAAAAA;
}
html {
background: #222222;
}
#test {
transition: 0.5s linear;
margin-bottom: 5px;
width: 30px;
height: 1px;
display: inline-block;
background-color: #AAAAAA;
border-radius: 1px;
}
#con {
position: relative;
display: inline-block;
}
#con:hover #test {
width: 40px;
}
<div id="con">
<div class="a">01</div>
<div id=test></div>
<div class="a">Projects</div>
</div>

How to overlap HTML block level element over another HTML block level element while retaining responsive behaviour across screen sizes

I am trying to replicate the behaviour of a piece of HTML and CSS content that appears on the website i have provided a link to below. The website in question is www.air-it.co.uk.
I have included below a mockup image, which indicates the layout that i want to achieve.
I do not know how else other than to link to the working version on the website below to visualise this for users reading this question, because i do not know how to solve the problem i am trying to address with this question using HTML and CSS.
The example of this can be seen roughly 1/3 of the way down the following page.
www.air-it.co.uk
Essentially, it appears to be be positioning one div on the left over another div on the right within a container. It appears to be leveraging a 'card content' element which is placed over another div containing a background image.
I could possibly do this at one screen size using absolute positioning, i think. But i need it to behave responsively in a similar way (or the same way) as the example above?
I am aware that the above example uses Foundation. But my question would be is there an inbuilt way to do this using Bootstrap?
I would imagine the alternative here is to customise CSS for different media queries in order to do this, which unfortunately i don't know how to do.
Please do not simply close this question again if you would like to take umbrage with my syntax or question structure. Kindly post your feedback or criticism in a comment which will allow me to revise this question as opposed to simply closing the question with no additional clues or feedback as to why you have chosen to do so.
Thank you.
maybe this can help, try to open in full view
body {
font-family: Roboto;
margin: 0;
}
.overlap-section {
min-height: 450px;
background-color: #fff;
display: inline-block;
float: left;
width: 45%;
border: 1px solid #ff5722;
padding: 50px;
position: absolute;
z-index: 99;
top: 50%;
transform: translateY(-50%);
left: 5%;
}
.main-box {
background-color: lightgray;
height: 100%;
width: 75%;
float: right;
position: relative;
}
.main-section {
height: 100vh;
position: relative;
}
.text-wrapper {
display: inline-block;
position: absolute;
top: 50%;
right: 26%;
transform: translate(50%, -50%);
}
.text-wrapper h2 {
display: inline-flex;
margin: 0;
text-transform: uppercase;
line-height: 42px;
color: #fff;
font-weight: bold;
}
.overlap-section h3 {
text-transform: uppercase;
font-weight: bold;
font-size: 30px;
padding-bottom: 25px;
}
.overlap-section label {
font-size: 25px;
display: block;
}
.overlap-section span {
font-size: 16px;
padding: 18px 0;
display: block;
}
.button-wrapper {
margin: 0 auto;
display: table;
padding-top: 52px;
}
.button-wrapper .custom-btn {
color: #fff;
background-color: #ff5722;
padding: 14px 35px;
border: 0;
font-size: 19px;
}
<div class="main-section">
<div class="overlap-section">
<h3>Header text is here</h3>
<label>More header text here</label>
<span>List item</span>
<div class="button-wrapper">
<button class="btn-default custom-btn" type="button">Call to action here</button>
</div>
</div>
<div class="main-box">
<div class="text-wrapper">
<h2>This Grey Element</h2><br>
<h2>Will contain an image</h2>
</div>
</div>
</div>

Adding paragraph <p> Text to inline-block set of divs puts the div onto the next line [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 3 years ago.
When I place any content inside the first div of three below, (which are displayed as inline-block), the first div moves out of position to the next line.
.container-testimonials {
text-align: center;
background: teal;
margin: 20px auto;
font-size: 0;
}
.clients {
padding-top: 60px;
}
.clients h3 {
font-size: 2rem;
font-weight: normal;
}
.box8,
.box9,
.box10 {
display: inline-block;
height: 250px;
width: 31.3%;
background-size: cover;
margin: 1%;
background: #F25E5E;
border-radius: 10px;
}
.box8 p {
color: #000;
font-size: 1rem;
}
<div class="container-testimonials">
<div class="clients">
<h3>WHAT CLIENTS SAY</h3>
</div>
<div class="box8">
<p>Text</p>
</div>
<div class="box9"></div>
<div class="box10"></div>
</div>
I am fairly sure this has to do with the extra white space the <p> tag adds to the width of each div block, which is set to 31.3%, with the other 1% going to padding and the 2/3% going to the other two divs.
Adding vertical-align: top; to your boxes alignes them on top correctly.
Add vertical-align:top; on .box8,.box9,.box10
.box8,
.box9,
.box10 {
display: inline-block;
height: 250px;
width: 31.3%;
background-size: cover;
margin: 1%;
background: #F25E5E;
vertical-align:top;
border-radius: 10px;
}
https://jsfiddle.net/lalji1051/0a94m5tn/1/

How vertical align inner span with smaller text? [duplicate]

This question already has answers here:
Vertically center <span> text which is beside a much larger <span>, both inside a <div>
(2 answers)
Closed 5 years ago.
Example: https://codepen.io/ahdung/pen/dJVZov
body {
font-size: 2em;
}
.outer {
background-color: darkgray;
}
.inner {
background-color: red;
font-size: 0.7em;
vertical-align: middle;
/*not useful*/
}
<span class="outer">
<span class="inner">AAA</span>BBB
</span>
simplest solution. although you may want to tinker for exact placement since block with inline isn't always perfect.
.inner {
display: inline-block;
vertical-align: middle;
}
you could go more complex to get a better center doing something with:
.outer {
display: inline-block;
position: relative;
padding-left: 2.5em;
}
.inner {
display: block;
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
}
depending on what's around it and what kind of text or variable text, you can do different things.