I need to put a background image to a text. I suspect it could be because we nested too many classes in "div" but still can't figure it out.
CSS:
.box {
display: flex;
top: 80px;
position: relative;
padding-top: 30px;
border-top: thin solid black;
border-bottom: thin solid black;
border-right: thin solid black;
border-left: thin solid black;
}
.box1 {
padding-left: 300px;
padding-right: 30px;
width: 630px;
flex-direction: column;
align-self: flex-start;
}
.smalltitle2 {
border-bottom: medium solid black;
background-image: url("https://s3.amazonaws.com/codecademy-content/courses/freelance-1/unit-4/img-news-bite.png");
background-repeat: no-repeat;
}
HTML:
<div class="box">
<div class="box1">
<div class="smalltitle2">Mother of Three Buys Tuna Steak at Phish Concert. Leaves, "Feeling Funny."</div>
</div>
</div>
Add a width and height to your smalltitle2 container and you can tweak around how you want to make it look whether it should be part of the image, or do you want the entire image inside the container (make use of background-size).
.box {
display: flex;
top: 80px;
position: relative;
padding-top: 30px;
border-top: thin solid black;
border-bottom: thin solid black;
border-right: thin solid black;
border-left: thin solid black;
}
.box1 {
padding-left: 300px;
padding-right: 30px;
width: 630px;
flex-direction: column;
align-self: flex-start;
}
.smalltitle2 {
border-bottom: medium solid black;
background:url(https://s3.amazonaws.com/codecademy-content/courses/freelance-1/unit-4/img-news-bite.png);
background-repeat: no-repeat;
background-size: contain;
width:100%;
height:100px;
}
<div class="box">
<div class="box1">
<div class="smalltitle2">Mother of Three Buys Tuna Steak at Phish Concert. Leaves, "Feeling Funny."</div>
</div>
</div>
You can either try background-size: contain; or background-size: cover; etc.
There is no problem with the CSS, it's just missing a rule to define the size of your background image.
See demo here : https://jsfiddle.net/v8eLsef4/1/
Related
A big beginner here, but I am trying to align my divs in rows so that the border design doesn't get overly thick where they touch.
For some reason I can't use the pre to write the html so I will write it in plain text.
.site {
display: flex;
flex-direction: row;
height: 100%;
width: 100%;
align-items: stretch;
}
.box1 {
background: #000000;
background: #000000;
background: #000000;
margin: 0px;
padding: 0px;
width: 55px;
height: 100%;
border: 3px solid black;
background-color: white;
}
.box2 {
background: #000000;
background: #000000;
background: #000000;
margin: -3px;
padding: 0px;
width: 730px;
height: 100%;
border: 3px solid black;
background-color: white;
}
<div class="site">
<div class="box1">Box 1</div>
<div class="box2">Box 2</div>
</div>
I haven't gotten to that point yet, but I also want the entire .site to have a 3 px black border around it. I basically want a .site with a 3 px black border, and 3 px dividers between the different components.
I have prepared a small code for you. You can choose any one out of the two snippets.
Case 1: 3px border for your .site class, as well as neat and clean div to differentiate between the .site class and the two divs within.
.site, .box1, .box2{
display: flex;
padding:7px;
border:3px solid black;
}
<div class="site">
<div class="box1">Box 1</div>
<div class="box2">Box 2</div>
</div>
Case 2: Slightly border change, but as per your need, 3px border for your .site class will remain same in this case as well.
.site{
display:flex;
border:3px solid black;
padding: 5px;
}
.box1, .box2{
border: 3px solid black;
}
<div class="site">
<div class="box1">Box 1</div>
<div class="box2">Box 2</div>
</div>
Hope this helps.
Try below CSS for box2:
.box2{
background: #000000;
background: #000000;
background: #000000;
padding: 0px;
width: 730px;
height: 100%;
border: 3px solid black;
border-left: 0;
background-color: white;
}
For the entire site to have a border, you can give your <body> a border.
For your elements, have you tried giving the relevant sides a border of just 1.5px?
I have a table made with divs, using flexbox to obtain a nice table formatting of my divs.
Now I got a structure like this:
<div class="tableWrapper">
<div class="tableHeader">
<div class="tableHeaderRow">
<div class="tableHeaderCells"></div>
<div class="tableHeaderCells"></div>
</div>
</div>
<div class="tableBody">
<div class="tableBodyRow">
<div class="tableBodyCells"></div>
<div class="tableBodyCells"></div>
</div>
<div class="tableBodyRow">
<div class="tableBodyCells"></div>
<div class="tableBodyCells"></div>
</div>
<div class="tableBodyRow">
<div class="tableBodyCells"></div>
<div class="tableBodyCells"></div>
</div>
</div>
so now what I would like to achieve is to have the "tableHeader" always stay in the same position, so when the "tableBody" content is big (it could have 50rows) and doesn't fit in the browser screen, when the user scrolls down, the header follows so it's always visible.
I tried with position:fixed but then it messes up the "tableBody" content.
Here the current css:
.tableWrapper {
width: 100%;
height: 100%;
margin-top: 15px;
position: relative;
}
.tableHeader {
width: 100%;
position: relative;
}
.tableHeaderRow {
display: flex;
height: 35px;
border-bottom: 1px solid #000;
align-items: center;
}
.tableHeaderCells {
display: flex;
border-top: 1px solid #000;
border-bottom: none;
border-left: 1px solid #000;
border-right: 1px solid #000;
align-items: center;
justify-content: center;
font-weight: bold;
height: 100%;
width: 100%;
}
.tableBodyCells {
display: flex;
border-top: none;
border-bottom: none;
border-right: 1px solid #000;
border-left: 1px solid #000;
height: 100%;
width: 100%;
align-items: center;
justify-content: center;
}
.tableBody {
width: 100%;
height: 100%;
position: relative;
}
.tableBodyRow {
display: flex;
height: 50px;
width: 100%;
align-items: center;
border-bottom: 1px solid #000;
border-top: 1px solid #000;
margin-bottom: 2px;
}
here a fiddle: jsfiddle
so the final result I would like to obtain is, with a body with over 50rows, I want the user to be able to scroll down while leaving the header always on screen, and a plus would be that the "scroll size" (don't know how to call it) is equal to the rows height, meaning that when the user scrolls once, it will go down a fixed amount and exactly put a body row under the header, to avoid that when the user scrolls you get the header, and under it a cut in half body row, hope you understood what I mean!
Please check this you can use position: sticky; instead of position: sticky; please check fidle, hope it will help you
https://jsfiddle.net/06L52wm1/36/
.tableWrapper{position:relative;}
.tableHeader{position:absolute;width:100%:`}
I don't know what your issue was with position:fixed but it doesn't seem like it changes the body content.
.tableHeader {
width: 100%;
position: fixed;
background-color: #FFFFFF;
z-index:999;
}
.tableBody {
width: 100%;
height: 100%;
position: relative;
padding-top: 50px;
}
JSfiddle
There is still an issue with the width of the header though but I think you can set it by removing the the body margin from the tableHeader's width with calc()
.
I would like to know, if it is possible to give to a border-bottom something like a padding-left and padding-right. I have two divs, which have some borders. I would like to make the border-bottom of the top div to have some padding on left and right. I have no idea if this is possible. I know the structure is strange (I could easy use the border around the whole box wrapper and than work on the span with a border-bottom to achieve this). The problem is, I'm using a plugin which has a structure like this and I have to customize it like this, because there is exactly this strucure and styling. Hope it's clear enough. Here a picture how it should look and an example snippet:
.box {
display: flex;
flex-direction: column;
width: 200px;
}
.box__top {
border: 1px solid black;
border-bottom: 1px solid red;
height: 20px;
padding: 10px;
text-align: center;
}
.box__bottom {
border: 1px solid black;
border-top: none;
height: 150px;
padding: 10px;
text-align: center;
}
<div class="box">
<div class="box__top">
<span>I'm the top section</span>
</div>
<div class="box__bottom">
<span>I'm the top section</span>
</div>
</div>
Use a pseudo-element instead:
.box {
display: flex;
flex-direction: column;
width: 200px;
}
.box__top {
border: 1px solid black;
border-bottom: none;
position: relative;
height: 20px;
padding: 10px;
text-align: center;
}
.box__top::after {
content: " ";
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 0;
width: 90%;
height: 1px;
background-color: red;
}
.box__bottom {
border: 1px solid black;
border-top: none;
height: 150px;
padding: 10px;
text-align: center;
}
<div class="box">
<div class="box__top">
<span>I'm the top section</span>
</div>
<div class="box__bottom">
<span>I'm the top section</span>
</div>
</div>
I want to display an image that has a caption beneath it. If the user resizes the browser, the image will resize while maintaining its aspect ratio. The width of the image must not exceed its normal width. You can scale down but not scale up beyond its actual size. The image width must also not exceed 500px and the height must not exceed 800px. As you resize the image, the caption's width must align with the image's left and right sides. Here is what I got:
Working jsFiddle
Code:
.furlHtmlCont {
max-width: 600px;
max-height: 800px;
display: inline-block;
flex-direction: column;
align-items: flex-start;
box-shadow: 0 0 8px #c0c0c0;
border-left: 1px solid #c0c0c0;
border-right: 1px solid #c0c0c0;
border-bottom: 1px solid #c0c0c0;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
.furlHtmlFooter {
display: table-caption;
caption-side: bottom;
padding: 5px 10px 5px 10px;
}
.furlHtmlImg {
max-width: 100%;
max-height: 300px;
cursor: pointer;
}
<div class="furlHtmlCont">
<div style="display: flex; flex-direction: column">
<img class="furlHtmlImg" src="http://dhr7l999iqsnw.cloudfront.net/wp-content/uploads/Two_Male_Giraffes_Fighting_600.jpg">
<div class="furlHtmlFooter">
<div class="furlHtmlTitle">Caption goes here</div>
<div class="furlHtmlDesc">Long description goes here. It should wrap at the image's right edge even as the user resizes the image.
</div>
</div>
</div>
</div>
The problem I am having is that the image is exceeding its normal width and getting stretched.
UPDATE:
Although I accepted the answer below, it in fact does NOT work. The height must be limited to 800px.
I think this should work.
CSS:
.furlHtmlCont {
width: 100%;
height: 100%;
max-width: 500px;
max-height: 800px;
display: inline-block;
flex-direction: column;
align-items: flex-start;
box-shadow: 0 0 8px #c0c0c0;
border-left: 1px solid #c0c0c0;
border-right: 1px solid #c0c0c0;
border-bottom: 1px solid #c0c0c0;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
.furlHtmlFooter {
display: table-caption;
caption-side: bottom;
padding: 5px 10px 5px 10px;
}
.furlHtmlImg {
width:100%;
height:auto;
cursor: pointer;
}
JSFiddle: here
None of the solutions listed were able to constrain the height to some maximum value. Here's the solution (I also decided to limit the height to a maximum of 400px instead of 800px):
Html:
<div class="furlHtmlCont">
<div style="display: table;">
<img class="furlHtmlImg">
<div class="furlHtmlFooter">
<div class="furlHtmlTitle">Caption goes here</div>
<div class="furlHtmlDesc">This is where the long description goes and its with should not exceed the width of the image. No clipping either.</div>
</div>
</div>
</div>
css:
.furlHtmlCont {
max-width: 600px;
display: inline-block;
box-shadow: 0 0 8px #c0c0c0;
border-left: 1px solid #c0c0c0;
border-right: 1px solid #c0c0c0;
border-bottom: 1px solid #c0c0c0;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
.furlHtmlFooter {
display: table-caption;
caption-side: bottom;
padding: 5px 10px 5px 10px;
}
.furlHtmlImg {
max-width: 100%;
max-height: 400px;
cursor: pointer;
}
https://jsfiddle.net/Deepview/vy6h0rdj/5/
Here we go!
html,
body {
height: 100%;
}
.container {
width: 100%;
max-width: 500px;
max-height: 800px;
height: 100%;
}
.image-container {
width: 100%;
height: 100%;
}
img {
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
<div class="container">
<div class="image-container">
<img src="http://dhr7l999iqsnw.cloudfront.net/wp-content/uploads/Two_Male_Giraffes_Fighting_600.jpg">
<div>
<div>Caption goes here</div>
<div>Long description goes here. It should wrap at the image's right edge even as the user resizes the image.
</div>
</div>
</div>
</div>
.furlHtmlCont {
max-width: 600px;
max-height: 100%;
display: inline-block;
flex-direction: column;
align-items: flex-start;
box-shadow: 0 0 8px #c0c0c0;
border-left: 1px solid #c0c0c0;
border-right: 1px solid #c0c0c0;
border-bottom: 1px solid #c0c0c0;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
text-align:justify;
}
.furlHtmlFooter {
display: table-caption;
caption-side: bottom;
padding: 5px 10px 5px 10px;
}
.furlHtmlImg {
max-width: 100%;
max-height: 100%;
cursor: pointer;
object-fit: scale-down;
}
change the css as above.
And let me know if it is what you wanted..
You should have an image of the exact width and height placed there. Every time for the image you can't specify the width and height because that would stretch and distort the image, so put the image in right size to function correctly.
i am a beginner who wants to learn please help.here archenemies is the id i gave to div.
div {
height:100px;
width:100px;
display: inline-block;
margin-left: 5px;
border-radius:100%;
border: 2px solid black;
}
#archenemies{
border:4px solid #cc0000;
background-image:"http://static.comicvine.com/uploads/original/11119/111193741/4458205-1304230669-friez.png";
background-size:90%;
}
Method 1 - Using Background Image.
The things to keep in mind while creating a circular div-
1. border-radius:50% or more
2. Backgound-imgage- size to cover
3. background position to center
Below is the working code.
div {
height: 100px;
width: 100px;
display: inline-block;
margin-left: 5px;
border-radius: 50%;
border: 2px solid black;
border: 4px solid #cc0000;
background-image: url(http://static.comicvine.com/uploads/original/11119/111193741/4458205-1304230669-friez.png);
background-size: cover;
background-position: center center;
}
<div> </div>
Method 2 - Using IMG SRC
div {
width: 100px;
height: 100px
}
img {
border-radius: 50%;
width: 100%;
height: 100%;
border: 4px solid red
}
<div><img src="http://static.comicvine.com/uploads/original/11119/111193741/4458205-1304230669-friez.png" /></div>
Sory if I ignored your height and width settings!
.circle {
width: 200px;
height: 200px;
border: 1px solid black;
border-radius: 100px;
background-image: url('http://static.comicvine.com/uploads/original/11119/111193741/4458205-1304230669-friez.png') ;
background-size: 100px;
background-position:50%;
background-repeat:no-repeat;
<div class="circle"></div>