The Problem
I am trying to place images within a responsive circle (div), which is itself the child of another responsive circle.
I feel I have the divs nailed, but as soon as I include an image the proportions get distorted and I can't figure out the correct CSS code.
The two divs are for a future border effect I am planning.
What I currently have...
CodePen
HTML
<section class="col-4">
<div class="wrapper">
<div class="outta-circle">
<div class="circle">
<!-- <img src="#"> -->
</div>
</div>
</div>
<div class="wrapper">
<div class="outta-circle">
<div class="circle">
<!-- <img src="#"> -->
</div>
</div>
</div>
</section>
CSS
.col-4 {
width: 1068px;
}
.wrapper {
width: 48.68%;
max-height: 520px;
background-color: white;
}
.outta-circle {
width: 100%;
height: auto;
margin: 80px auto;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background-color: red;
}
.circle {
width: 96.15%;
height: auto;
padding-bottom: 96.15%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background-color: blue;
overflow: hidden;
}
The solution to my issue is to use the CSS Background property for the class .circle (see comments, cheers for the help there!!).
I have a number of news stories each with their own image placed in a PHP array - I plan to use a database but for the time being an array will suffice - therefore the img src will change depending on which news story is loaded.
I was going to use:
<img src="<?php echo $article["img"]; ?>" alt="<?php echo $article["title"]; ?>">
Now I have to use the CSS Background property, how would I parse the PHP into the HTML/CSS??
I'm new to this, apologies if I haven't been clear...
First of all you can make your images a basic circle I said by following this tutorial
.circular {
width: 300px;
height: 300px;
border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
background: url(http://link-to-your/image.jpg) no-repeat;
}
But for your use, make a foreach loop in your PHP like this to be able to apply CSS directly to it (given the images in the array are stored like <img src="www.mysrc.com/kittens.jpg" />. If they are just the URL you have to change the echo line in the foreach loop a little)
<?php
$cont=0;
echo '<ul>';
foreach($array as $arrval){
echo '<li class="circular">'.$arrval.'</li>';
$cont++;
}
echo "</ul>";
?>
And then you can apply the CSS with
li.circular{
width: 300px;
height: 300px;
border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
}
Edit based on my chat with you. Set up the PHP this way first (has to be outside of <script> tags)
<?php
$array1 = array('img' => "http://izview.com/wordpress/wp-content/uploads/2008/07/the-chandelier.jpg",
'title' => 'article',
'content' => 'This is the content coming from PHP',
'date' => "6/27/2013");
?>
And call it by converting it to json and putting it in <script> tags to be applied to the element.
Javascript fix (no PHP) jsFiddle
var articleArray = [{img: "http://izview.com/wordpress/wp-content/uploads/2008/07/the-chandelier.jpg", title: "Article Name", content: "This is the content coming from PHP", date: "6/27/2013"},
{}
];
So if you're trying to achieve a sort of 3d effect on a rounded image you can definitely get it with just the image tag only so the code will be very clean and it will be easy to place the image through PHP.
Simply assign a 100% border-radius and a proper box-shadow to the image, something along these lines:
img {
border-radius: 100%;
box-shadow: 9px 0 red;
}
Take a look at this http://codepen.io/nobitagit/pen/trEuJ
As the code is this simple it will be very easy to make it responsive-friendly as to your needs.
#Zeaklous I have tried your method, but I believe in this instance I have to use CSS Background-Image: url();
Therefore I need a method of dynamically changing the Background-Image: url(); and after a little searching it seems following this technique using background-image:url('<?php echo $url ?>'); would work?!?
It's a stab in the dark though, my 1st time with code of this nature.
Related
I'm currently trying to set the background of my div according to if the user has a chosen background or not, and I can successfully do that to an extend.
However, what I cannot do is set the background of the div via CSS because I cannot concatenate strings in CSS, which means I can for example do:
background: url("/uploads/Example.png") !important;
But I cannot do.
background: url("/uploads/#Model.Banner")
or
background: url("/uploads/" + #Model.Banner)
My current code looks like this.
<head>
#if ("/uploads/" + #Model.Banner != "/uploads/")
{
<style>
:root {
--url: url("/uploads/#Model.Banner");
}
.profile-header {
height: 200px;
background: var(--url) !important;
background-size: 100%;
-webkit-border-radius: 10px !important;
-moz-border-radius: 10px !important;
border-radius: 10px !important;
}
</style>
}
</head>
<div id="main">
<label class="navigation-bar"><a>Home</a> - <a>Users</a> - <b>Profile</b></label>
<hr />
<div class="container profile-header"></div>
.profile-header exists in another .css file with a default banner, meaning that the CSS in the code is what would be used for changing it dynamically if a banner exists.
What I kindly ask is for guidance in how I can have set the background of the div to the path + the banner name, the current code does not work as it sets no background to the div when it enters the IF statement.
Thank you!
I assume you will know if the user has a value for Banner in the Controller action if you are adding it to the model for the corresponding View. For example:
public IActionResult Index()
{
YourModel model = new YourModel();
...
// you could supply a default image or just leave as "url(/uploads/)"
model.BannerUrl = string.IsNullOrEmpty(model.Banner) ? "url(/uploads/Default.png)" : $"url(/uploads/{model.Banner})";
return View(model);
}
Then in the View:
<head>
#if (!#Model.Banner.Contains("Default.png"))
{
<style>
:root {
--url: #Model.BannerUrl;
}
.profile-header {
height: 200px;
background: var(--url) !important;
background-size: 100%;
-webkit-border-radius: 10px !important;
-moz-border-radius: 10px !important;
border-radius: 10px !important;
}
</style>
}
</head>
<div id="main">
<label class="navigation-bar"><a>Home</a> - <a>Users</a> - <b>Profile</b></label>
<hr />
<div class="profile-header"></div>
Or you could add it all inline (just used a couple of styles so you get idea):
<div style="background:#Model.BannerUrl !important; height: 200px; background-size: 100%"></div>
EDIT:
Forgot to say could work in the view as below, but wanted to give alternative option.
#{
var url = $"/uploads/" + #Model.Banner;
}
<div style="background: url(#url) !important"></div>
I'm trying to add an image before other images. It should be before every image except the first one. So thought of adding it like:
.class3:not(:first-child):before {
background-image: url('image.jpg');
width: 2rem;
height: 2rem;
}
The html gets added dynamically through Backbone and uses Handlebars. It looks something like this:
<div class="class1">
<div class="class2">
{{#each item}}
<div class="class3" style="background-image: url('{{image1}}')">
<p>{{text}}</p>
<img class="dialog-popup-rewards" src={{image2}} />
</div>
{{/each}}
</div>
</div>
But nothing gets added. I tested the before statement with less complexity. Adding a before to all of the divs:
.class3:before {
background-color: black;
width: 2rem;
height: 2rem;
}
And it never gets added. What am I missing? I rewrote the code for the sake of clarity, so I might have slipped in some syntax errors.
Would it be better to try this with a Handlebars helper?
Thank you in advance.
You need to include a content property in your :before css block. It can be just an empty string. Try this for your simplified example:
.class3:before {
content: '';
background-color: black;
width: 2rem;
height: 2rem;
}
Building my first website, and learning HTML, CSS, PHP, MySQL as needed. I'd like a set of inline divs which are aligned to the left. However, if there's not enough room to fill the screen, I'd like for the entire block of inline divs to be centered. After much searching and research, I determined it was impossible with only CSS, due to the fact that the internal size of all the inline left aligned divs would have to be calculated before the auto margin of the centered containing div could be calculated. I ended up kludging it together with the use of a whole bunch of invisible inline "ghost" divs which make the last line of the inline divs appear as if it's left-aligned.
Now it looks like this, which is great. http://i.stack.imgur.com/Zmru7.png
I gave the fake divs a border, and now they're visible. http://i.stack.imgur.com/Zmru7.png
Firstly, is there an elegant solution to this aside from media tags which change the CSS depending on screen size? Secondly, is it possible to force it to center when there's only one line?
i.stack.imgur.com/ DjWaj.png
CSS: (stripped, if something seems missing let me know)
div.pmegaframe {
width: 100%;
margin: 0px auto; padding: 0px;
text-align: center; }
div.pfake {
display: inline-block;
vertical-align: top;
overflow: hidden;
margin: 22px; margin-top:0px; margin-bottom:0px;
width: 164px; height: 1;
border: none; }
div.pframe {
display: inline-block;
vertical-align: top;
overflow: hidden;
margin: 15px;
width: 164px;
border: 6px solid var(--header); }
/*div.pframe:hover {
border: 16px solid #B85843; }*/
div.pminiframe {
width: 160px;
margin: 0px; padding: 0px;
border: 2px solid var(--white);
background: var(--dark); }
div.pimageframe {
overflow: hidden;
width: 160px; height: 160px;
color: var(--accent);
background: var(--white); }
div.pwordsframe {
position: relative;
width: 160px; height: 280px; }
index.php (stripped)
<div class="pmegaframe">
<?php
$pquery = mysqli_query($db, "SELECT f_name, l_name, blurb FROM users");
$pnum = mysqli_num_rows($pquery); $id = 0; //Pull userdata
while ($id < $pnum) { //Collect userdata
mysqli_data_seek($pquery, $id); $prow = mysqli_fetch_row($pquery);
$image = "160px_profile_".$id; $name = $prow[0]." ".$prow[1];
$text = $prow[2];
$state = 0; $rating = 1;
$squery = mysqli_query($db, "SELECT ID, courseID FROM subjects WHERE userID=".$id); //Pull the user's subjects
$snum = mysqli_num_rows($squery);
include "pframe.php"; //Makes the userframe
$id += 1;
}
echo str_repeat("<div class=\"pfake\"></div>", 8);
//fills in the grid with invisible boxes
?>
</div>
pframe.php (also stripped):
<div class="pframe"> <!--The base grey outer frame-->
<a href="profile.php?user=<?php print $id?>" class="nocolor"> <!-- links it-->
<div class="pminiframe"> <!-- puts down the interior white frame-->
<div class="pimageframe"> <!--The upper half of the box-->
<img src="/profiles/<?php echo $image; ?>.png" alt="Profile image not found!"></div>
<div class="pwordsframe"> <!--The lower half of the box-->
<!-- *snip* This was the messy content of the lower half of the profile boxes. -->
</div>
</div>
</a>
</div>
Im trying to use padding to push an image 18px from the top of a div. Neither margin or padding are working, and after comparing the two padding seems to be what I want anyway.
The problem is with the footer-middle-left-left-image div tag. The margin on the text one works fine though.
Here's the html:
<div id = "footer-middle-left-left">
<div id = "footer-middle-left-left-picture">
<img src = "" alt = "some_text">
</div>
<div id = "footer-middle-left-left-text">
If you would like to join our newsletter, please enter your </br>
email address below.
</div>
<div id = "footer-middle-left-left-email">
</div>
</div>
The CSS I have is:
#footer-middle-left-left {
float: left;
width: 483px;
height: 175px;
}
#footer-middle-left-left-image {
float: left;
width: 483px;
height: 59px;
padding-top: 18px;
}
#footer-middle-left-left-text {
width: 483px;
height: 58px;
float: left;
margin-left: 25px;
color: white;
}
#footer-middle-left-left-email {
height: 58px;
float: left;
width: 483px;
}
Any help would be appreciated! Also any advice, anything at all would be nice too. I'm pretty new so advice not relevant to my problem is also appreciated, like is this a good id-naming convention, etc..
In html you have footer-middle-left-left-picture but in css #footer-middle-left-left-image
Is it this bug or you just make mistake on paste code?
http://jsfiddle.net/CmwHu/
#footer-middle-left-left-image this id doesnt exist in your html.
So i have changed footer-middle-left-left-picture to #footer-middle-left-left-image.
It is working now
DEMO
Hi all !
I want to create a small round static percent indicator in CSS but I can't find the solution.
The squared indicator at left is ok, but so ugly, I want it round !
I have tried with rounded corner (cf indicators at the right of the screenshot), and I wonder if there is possibility to add a rounded mask to hide the corners (cf. css3 mask : http://webkit.org/blog/181/css-masks/), but it seems like it's only for img...
The solution can works only on webkit browsers, because it's for a mobile webapp.
Here is my code to create the (ugly) indicator in the image above :
<div class="meter-wrap">
<div class="meter-value" style="background-color: #489d41; width: 70%;">
<div class="meter-text"> 70 % </div>
</div>
</div>
And the css :
.meter-wrap{
position: relative;
}
.meter-value {
background-color: #489d41;
}
.meter-wrap, .meter-value, .meter-text {
width: 30px; height: 30px;
/* Attempt to round the corner : (indicators at the right of the screenshot)
-webkit-border-radius : 15px;*/
}
.meter-wrap, .meter-value {
background: #bdbdbd top left no-repeat;
}
.meter-text {
position: absolute;
top:0; left:0;
padding-top: 2px;
color: #000;
text-align: center;
width: 100%;
font-size: 40%;
text-shadow: #fffeff 1px 1px 0;
}
Add a wrapper around your .meter-value class, set its overflow to hidden and then set the width of that layer to get the desired effect. The rounded corners on the .meter-value class should remain intact and give you a nice fluid progress indicator.
You will have to move the .meter-text div outside of the wrapper to ensure it's visible throughout the transition, so your html would like something like:
<div class="meter-wrap">
<div class="meter-text"> 70 % </div>
<div class="meter-value-wrapper" style="width:70%;">
<div class="meter-value" style="background-color: #489d41;">
</div>
</div>
And the class for .meter-value-wrapper might look like:
.meter-value-wrapper {
overflow: hidden;
width: 30px;
height: 30px;
}