Span does not recognize a parent element - Overlapping - html

First of all, thank you for taking your time answering my maybe stupid question. I have a problem with my span not wanting to stay where mummy told him to stay.
HTML
<section class="row" id="white_background">
<div class='col-lg-6 col-md-6 col-sm-6 col-xs-12'>
<article class="news_post">
<span class='news_head'>
<h4>BLA BLA BLA BLA BLA BLA BLA</h4>
<p><?php echo $NewsItem->getValueEncoded( "summary" ) ?></p>
<p><?php echo $NewsItem->getValueEncoded( "uploadDate" ) ?></p>
</span>
</article>
</div>
</section>
Sass
#white_background {
background: $light;
height:100%;
padding: 20px;
text-align: center;
#inlcude clearfix;
h2 {
text-align: center;
color: $purple;
}
}
.news_post {
#include article_back (
'../img/picture_2.png');
padding: 20px;
margin-top: 30px;
margin-bottom: 50px;
}
.news_head {
max-width: 330px;
background-color: $purple;
padding: 6px 12px;
display: block;
color: $white;
margin: auto 50px auto 0px;
transform: translateY(120px);
text-align: left;
font-size: 12px;
h4 {
font-family: $heading;
font-size:13px;
}
}
Now it does this:
http://imgur.com/a/HQ46N
So it seems like the span does not see the div as a boundary.. any ideas?^^
EDIT: Sorry for making a slight mess here.
What I want to achieve is make the article-span overflow the article in a controlled way. Meaning: If I manually resize the window, the span should not go outside of the parent article.
The problem is that the sections I used, do not render the movement of the span properly and that is why the sections overlaps, like shown here: http://imgur.com/a/fZyux (Note: the left item in the purple box overflows the light grey edges of the article. It should stay inside this grey box.
The dealbreaker now is, when i resize the window to smaller window sizes, the span starts to move down, but i expected it to move to the edge of it's parten article or div.
The span does not get recognize that it sits in a div and does not get restricted by its boundaries. Why is that the case? It's super hard to explain but I tried.
Take a look at the full mockup to get an idea. http://imgur.com/a/5ZQn9
I hope this makes it more clear what i want to achieve^^

Use display flex;.
article {
width: 100px;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid red;
}
article span {
width: 30px;
height: 30px;
border: 1px solid green;
}
<article>
<span></span>
</article>

The sections overlap because using:
transform: translateY(120px);
makes the element behave like it was:
position: relative;
top: 120px;
The element has moved on the screen, but the rest of the layout renders as if it was still in the original place. To push the borders you can add margin-bottom to your span.
.container {
background-color: yellow;
height: auto;
}
.element-transformed {
display: block;
width: 50%;
height: 100px;
background-color: red;
transform: translateY(70px);
}
.element-positioned {
display: block;
width: 50%;
height: 100px;
background-color: red;
position: relative;
top: 70px;
}
.make-some-space {
height: 100px;
}
.element-transformed-with-margin {
display: block;
width: 50%;
height: 100px;
background-color: red;
transform: translateY(70px);
margin-bottom: 70px;
}
<div class="container">
<span class="element-transformed">
<p>transform: translateY(70px);</p>
</span>
</div>
<div class="container">
<span class="element-positioned">
<p>position: relative; top: 70px;</p>
</span>
</div>
<div class="make-some-space"></div>
<div class="container">
<span class="element-transformed-with-margin">
<p>transform: translateY(70px); margin-bottom: 70px;</p>
</span>
</div>
<div class="container">
<span class="element-positioned">
<p>position: relative; top: 70px;</p>
</span>
</div>

Related

Text position in table-style DIV when there's a picture?

I have this table-style DIV code for a used vehicle sales platform:
.mainwrapper {
border: 2px solid;
display: table;
}
.itemwrapper {
display: table-row;
width: 706px;
}
.mainwrapper {
margin-bottom: 20px;
}
.item {
width: 700px;
border: 1px solid;
padding: 1em;
background-color: blue;
color: white;
}
.item:nth-child(2) {
float: left;
margin: -2px;
}
.item1 {
display: table-cell;
text-align: left;
margin-left: -30px;
}
.item1 p {
margin-top: -30px;
}
.item-price {
width: 300px;
background-color: blue;
padding: 1em;
color: white;
text-align: center;
}
.picture, .item {
display: table-cell;
border: 1px solid;
}
.picture {
width: 90px;
margin: 1px;
border: 2px solid;
}
.picture img {
height: 185px;
}
<div class="mainwrapper">
<div class="itemwrapper">
<div class="item">1992 ELDDIS PAMPEROS XLi</div>
<div class="item-price">£1,000</div>
</div>
<div class="itemwrapper">
<div class="picture"><img src="https://complianz.io/wp-content/uploads/2019/03/placeholder-300x202.jpg.webp"></div>
<div class="item1"><p>2 berth, good condition</p></div>
</div>
</div>
<div class="mainwrapper">
<div class="itemwrapper">
<div class="item">2008 SWIFT CHALLENGER 540</div>
<div class="item-price">£13,000</div>
</div>
<div class="itemwrapper">
<div class="picture"><img src="https://complianz.io/wp-content/uploads/2019/03/placeholder-300x202.jpg.webp"></div>
<div class="item1"><p>4 berth end bedroom</p></div>
</div>
</div>
What I am trying to do is ensure the class item1 is opposite the image, with the text like this if you didn't have the £ per month div and list as table:
Basically, what I am trying to fix is the text that's in class item1 opposite the image (not with all the description or colored DIV there); see the image below.
I tried margin-left and margin-top, but it won't quite put the image opposite.
This is the result of my code:
I can't quite get it to work as I'd expected, text opposite image and size of DIV in the CSS; if anyone can help, I'd much welcome this.
It works OK - no major coding errors, but isn't quite esthetically working out, and that's the basic problem.
I'm trying this as basic HTML first before attempting anything with Javascript, just to ensure it works as a standalone design.
Edit: I tried vertical-align for text, that worked, but it's fixing the gap between image div and text that's the issue. There's a large amount of space I don't know how to fix.
As the answer for the text is solved. You can change the column width by changing the css property of item. you can do it as follows. The width was 700px in your code you can reduce to get a smaller width. I changed it to 400px.
.item {
width: 400px;
border: 1px solid;
padding: 1em;
background-color: blue;
color: white;
}

DIV element isn't placed correctly next to an image

So I'm questioning myself why the div with the class champ_info isn't placed next to the image because the image is an inline-block element. So the Text in my div element lies under the image instead of next to the image. My code is below.
.champ_info {
background: #0b2e33;
color: white;
}
.champ_container {
background: #10474e;
}
.champ_img {
border: 3px solid #1ba9bd;
border-radius: 50%;
margin: 5px;
height: 5rem;
width: auto;
}
<div class="champ_container">
<img class="champ_img" src="https://ddragon.leagueoflegends.com/cdn/9.5.1/img/champion/Pyke.png">
<div class="champ_info">
Some Text
</div>
</div>
Thank you in advance.
I personally find making inherently block level elements inline counter intuitive. Flex box is the perfect solution to your problem.
.champ_container {
width: 40%;
margin: 0 auto;
display: flex;
/* justify-content: center; */
align-items: center;
background: #10474e;
}
.champ_info {
background: #0b2e33;
color: white;
width: 100%;
height: 100%;
}
.champ_img {
border: 3px solid #1ba9bd;
border-radius: 50%;
margin: 5px;
height: 5rem;
width: auto;
}
<div class="champ_container">
<img class="champ_img" src="https://ddragon.leagueoflegends.com/cdn/9.5.1/img/champion/Pyke.png">
<div class="champ_info">
Some Text
</div>
</div>
<div> is a block element, which means it takes up the whole line. Put display: inline; inside the css for the <div> and it places it next to the image like you wanted.
Add vertical-align: top; if you want the text to align to the top. Since the image and the text align to the bottom of the parent, you need to manually set them to align to the top.
.champ_info {
background: #0b2e33;
color: white;
display: inline;
vertical-align: top;
}
.champ_container {
background: #10474e;
}
.champ_img {
border: 3px solid #1ba9bd;
border-radius: 50%;
margin: 5px;
height: 5rem;
width: auto;
}
<div class="champ_container">
<img class="champ_img" src="https://ddragon.leagueoflegends.com/cdn/9.5.1/img/champion/Pyke.png">
<div class="champ_info">
Some Text
</div>
</div>

Trying to add floating image and and description in a filled box

I am trying to get this to happen.
what I want
So far, I don't know how to overlap one img-div with another text-div and keep white space on the top of the text-div. You will see. What I have right now is:
<div id="some">
<img src="photos/some.png">
<div id="box">
<p>Proudly seeking</p>
<h2>some Cofefe</h2>
<button id="shopNow" class="button">Shop</button>
</div>
</div>
With some CSS that doesn't make it very appealing: what it looks like
#some{
margin-top: 20px;
background-color: red;
}
#some img{
width: 30%;
float: left;
}
#box{
padding-top: 220px;
margin-right: 40px;
font-family: "Eusthalia";
text-align: right;
}
#box p{
margin-right: 32%
}
h2 {
font-size: 2.6em;
}
button {
border: none;
font-family: "Eusthalia";
font-size: 15px;
background-color: #300c06;
color: #eadfc0;
padding: 2px 10px;
}
I am wondering if my whole approach with divs is wrong. I was researching and I found that right:0; doesn't work and stuff like that. How do I get a border to overlap behind the image? How do I give it a width and a height but make it push to the right?
Do I have to make the main div width 100% and then give the img a width 30% and the colored filled in text box 70%? But how would I have the box behind the img?
Drearo, I think you're doing fine with div tags. You just may need a bit more of them to help things along.
I would suggest the divs be position: absolute with the image in one of those. The box of text needs it too. Aside from that, a little CSS would get you the positioning you want. See here:
<div id="some">
<div class="my_img">
<img src="photos/some.jpg" />
</div>
<div id="box">
<p>Proudly seeking</p>
<h2>some Cofefe</h2>
<button id="shopNow" class="button">Shop</button>
</div>
</div>
css:
#some{
margin-top: 20px;
height: 100vh;
width: 100vw;
border: 1px solid #000;
position: relative;
}
.my_img {
position: absolute;
top: 5em;
left: 5em;
z-index: 200;
}
.my_img img {
width: 200px;
}
#box{
position: absolute;
top: 10em;
left: 10em;
transition: translate( -50%, -50%);
font-family: "Eusthalia";
text-align: right;
background: red;
min-width: 60%;
padding-right: 2em;
}
#box p{
margin-right: 32%
}
h2 {
font-size: 2.6em;
}
button {
border: none;
font-family: "Eusthalia";
font-size: 15px;
background-color: #300c06;
color: #eadfc0;
padding: 2px 10px;
}
https://jsfiddle.net/5k94j73p/

How to center text in a div, which contains an Icon

I got the following question, with a pic to illustrate:
I got a container, containing an icon and text. The Icon is always on the left, there can be more icons which are all fixed on the left. Now I want the text to be in the centre of the container. If the text gets too long, it should NOT overlap the icons, but it should expand to the right instead.
If the text is too long to fit in the container next to the icon, finally I just ellipse it.
But how do I do this? Is there a css solution?
Thanks in advance!
You can have the text taking the entire width of the container parent, but having left and right padding in a way that it will have enough space for the icon.
Then you can have the icon overlaying on top of the textbox.
The text box can align text in the center and clip text if overflow.
I made a simple pen to illustrate the idea. I hope this help
Codepen example
Here's the code.
HTML
<div class="container">
<i class="fa fa-map"></i>
<div class="textbox"><span class='centerized-text'>This is a centered text and it is very long</span></div>
</div>
CSS
.container {
background-color: #FAFBFD;
width: 15rem;
height: auto;
padding: 0.5rem;
border-radius: 4px;
}
i {
color: teal;
position: absolute;
}
.textbox {
padding: 0 1.3rem;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
body {
padding: 2rem;
background-color: #dedede;
}
(The style for body is just for your visual pleasure)
Here a code
#container {
display: flex;
flex-direction: row;
padding: 20px;
border: 2px solid skyblue;
}
#icon {
width: 24px;
height: 24px;
border-radius: 12px;
background-color: skyblue;
}
#text {
flex: 1;
text-align: center
}
<div id="container">
<span id="icon"></span>
<span id="text">Lorem Ipsum</span>
</div>
To have text centered in the block
#container {
position: relative;
padding: 20px;
border: 2px solid skyblue;
text-align: center;
}
#icon {
width: 24px;
height: 24px;
border-radius: 12px;
background-color: skyblue;
position: absolute;
left: 20px;
top: 0;
bottom: 0;
margin: auto;
}
<div id="container">
<span id="icon"></span>
<span id="text">Lorem Ipsum</span>
</div>
In a container use, two span tag and First span will contain your image tab and another has text in it.
You can use align-text-center to center your text.

I want to align a logo at the center of the screen and display few lines right after the image.But the text is coinciding with the image

This is my HTML code:
<img class="centeredimage" src="BLACK.jpg"><br><br>
<p align="center" class="new"><b><span class="main_text">This is regarding....</span></b><br><br>
<span class = "a2017">Welcome to 2017</span><br><br>
<span class="coming_soon">Coming Soon</span></p><br><br>
This is my CSS code:
.centeredimage {
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
width: 200px;
height: 200px;
}
.new{
color:#FFFFFF;
}
.main_text{
font-size:20px;
letter-spacing: 8px;
}
.a2017{
font-size:15px ;
letter-spacing:2px ;
}
.coming_soon{
letter-spacing: 1px;
}
The image is aligned at center of the screen but the text instead of getting displayed after the image is displayed coinciding with the image.How do I make it come after the image so that both are aligned at middle of the screen at center?
Try this
.centeredimage {
display : block;
width: 200px;
margin: auto;
...
I use this code to center things in the middle of the screen, for example, a loader. It can have multiple parts, it doesn't matter. You just put all the parts into one div. I used to use the "margin" trick, and still do here and there, but these days I'm using the table/tablecell thing to get the job done. It works everywhere, phones etc. (note I don't deal with 10-year-old browsers). Below is some code straight from an instructional sample:
<style>
.app_style {
width: 100%;
height: 100%;
display: table;
}
.loader_style {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.loader_icon_style {
border: 2px solid lightgray;
border-radius: 5px 5px 5px 5px;
}
.loader_bar_padding {
padding-top: 10px;
}
.loader_blurb {
width: inherit;
text-align: center;
font-size: 14px;
font-weight: bold;
color: yellow;
font-style: italic;
}
</style>
</head>
<body>
<sample-app class="app_style">
<div class="loader_style">
<img class="loader_icon_style" src="assets/images/r2-d2.jpg" />
<div class="loader_blurb loader_bar_padding">
May the force be with you...
</div>
<img class="loader_bar_padding" src="assets/images/loader-bar.gif" />
</div>
</sample-app>
</body>
If you want center the image and the text, not align only the image otherwise the text follow an other logic on the DOM, mostly if you use the absolute position for the image and not for the text.
You can use a wrapper div aligned to the center and put all content in it.
body {
background-color:#ff00ff;
}
.wrapper {
position: absolute;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -100px;
width: 200px;
height: 300px;
}
.your_image {
width: 200px;
height: 200px;
}
.new {
color: #FFFFFF;
}
.main_text {
font-size: 20px;
letter-spacing: 8px;
}
.a2017 {
font-size: 15px;
letter-spacing: 2px;
}
.coming_soon {
letter-spacing: 1px;
}
<div class="wrapper">
<img class="your_image" src="https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1122px-Wikipedia-logo-v2.svg.png"><br><br>
<p align="center" class="new"><b><span class="main_text">This is regarding....</span></b><br><br>
<span class="a2017">Welcome to 2017</span><br><br>
<span class="coming_soon">Coming Soon</span></p><br><br>
</div>
I prefer to use Flexbox. It simplifies a lot of the coding you need to do.
In your situation, just wrap your HTMl code in a div and make this your CSS:
div{
display: flex;
flex-direction: column;
justify-content: center;
}
.centeredimage {
display: block;
margin: 0 auto;
width: 200px;
height: 200px;
}